Giter VIP home page Giter VIP logo

Comments (2)

 avatar commented on June 14, 2024

I just updated the VertexAnimationObject3D to work the EXTRA SLOW effect:

private float[] mInterPolatedVerts   =null;
private float[] mInterPolatedNormals =null;

public VertexAnimationObject3D() {
    super();
}

public VertexAnimationObject3D(SerializedObject3D ser) {
    super(ser);
    float[][] v = ser.getFrameVertices();
    float[][] n = ser.getFrameNormals();

    mNumFrames = v.length;

    for(int i=0; i<mNumFrames; ++i) {
        VertexAnimationFrame frame = new VertexAnimationFrame();
        frame.getGeometry().setVertices(v[i]);
        frame.getGeometry().setNormals(n[i]);
        frame.getGeometry().createVertexAndNormalBuffersOnly();
        mFrames.add(frame);
    }
}

public void preRender() {
    if (!mIsPlaying || !mUpdateVertices) return;

    mCurrentTime = System.currentTimeMillis();
    VertexAnimationFrame currentFrame = (VertexAnimationFrame) mFrames.get(mCurrentFrameIndex);
    VertexAnimationFrame nextFrame = (VertexAnimationFrame) mFrames.get((mCurrentFrameIndex + 1) % mNumFrames);

    if (mCurrentFrameName != null && !mCurrentFrameName.equals(currentFrame.getName())) {
        if (!mLoop)
            stop();
        else
            mCurrentFrameIndex = mLoopStartIndex;
        return;
    }

    /*
    mMaterial.setInterpolation(mInterpolation);
    mMaterial.setNextFrameVertices(nextFrame.getGeometry().getVertexBufferHandle());
    mMaterial.setNextFrameNormals(nextFrame.getGeometry().getNormalBufferHandle());
     */

    int numVerts            = currentFrame.getGeometry().getVerticesF().length;

    float[] currentVerts    = currentFrame.getGeometry().getVerticesF();
    float[] nextVerts       = nextFrame.getGeometry().getVerticesF();

    float[] currentNormals  = currentFrame.getGeometry().getNormalsF();
    float[] nextNormals     = nextFrame.getGeometry().getNormalsF();

    if (mInterPolatedVerts==null) {
        mInterPolatedVerts   = new float[numVerts];
        mInterPolatedNormals = new float[numVerts];
    }

    for (int i = 0; i < numVerts; i += 3) {
        mInterPolatedVerts[i]       = currentVerts[i] + mInterpolation * (nextVerts[i] - currentVerts[i]);
        mInterPolatedVerts[i + 1]   = currentVerts[i + 1] + mInterpolation * (nextVerts[i + 1] - currentVerts[i + 1]);
        mInterPolatedVerts[i + 2]   = currentVerts[i + 2] + mInterpolation  * (nextVerts[i + 2] - currentVerts[i + 2]);

        mInterPolatedNormals[i]         = currentNormals[i] + mInterpolation * (nextNormals[i] - currentNormals[i]);
        mInterPolatedNormals[i + 1]     = currentNormals[i + 1] + mInterpolation * (nextNormals[i + 1] - currentNormals[i + 1]);
        mInterPolatedNormals[i + 2]     = currentNormals[i + 2] + mInterpolation * (nextNormals[i + 2] - currentNormals[i + 2]);
    }

    //setVertices
    mGeometry.setVertices(mInterPolatedVerts);
    mGeometry.setNormals(mInterPolatedNormals);
    mGeometry.createVertexAndNormalBuffersOnly();

    mGeometry.setVertexBufferHandle(mGeometry.getVertexBufferHandle());
    mGeometry.setNormalBufferHandle(mGeometry.getNormalBufferHandle());

    mMaterial.setInterpolation(mInterpolation);
    mMaterial.setNextFrameVertices(mGeometry.getVertexBufferHandle());
    mMaterial.setNextFrameNormals(mGeometry.getNormalBufferHandle());

    //
    mInterpolation += (float) mFps * (mCurrentTime - mStartTime) / 1000;

    if (mInterpolation >= 1) {
        mInterpolation = 0;
        mCurrentFrameIndex++;

        if (mCurrentFrameIndex >= mNumFrames)
            mCurrentFrameIndex = 0;
        /*
        mGeometry.setVertexBufferHandle(nextFrame.getGeometry().getVertexBufferHandle());
        mGeometry.setNormalBufferHandle(nextFrame.getGeometry().getNormalBufferHandle());
        */
    }

    mStartTime = mCurrentTime;
}


public void reload() {
    super.reload();
    for (int i = 0; i < mNumFrames; i++) {
        mFrames.get(i).getGeometry().reload();
    }
}

and in the mGeometry.java

public float[] getNormalsF() {
    return this.mNormalsF;
}

and

public float[] getVerticesF() {
    return this.mVerticesF;
}

returns the vertices, and normals array

lacroix

from rajawali.

MasDennis avatar MasDennis commented on June 14, 2024

Cheers man, very much appreciated.
Why not fork Rajawali, make the changes and then submit a pull request?
Will save me some work and we'll use the true power of Github :-)

from rajawali.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.