Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Support / Re: Obtain normals to adjust vertex controller normals
« Last post by EgonOlsen on November 27, 2023, 10:57:32 am »
I see. If you call refreshMeshData() on the controller, the newly calculated normals should be updated in the controller and you can obtain them from there.
22
Support / Re: Obtain normals to adjust vertex controller normals
« Last post by AeroShark333 on November 24, 2023, 02:56:35 pm »
Hmmm, I'll try to explain better:

Currently, I have an animation where I deform the mesh (through its vertices).
I can't calculate the normals in the vertexcontroller because they depend on neighboring vertices.
However, if I use Object3D.calcNormals() after applying the vertexcontroller, then I suppose I will have the normals for the deformed mesh.
Is it possible to obtain these normals for future use, so in that case I could feed them into the vertexcontroller instead of having to call calcNormals() again.
Essentially, I am trying to create a cache of normals to avoid having to call calcNormals() during runtime.

I hope this makes sense...
23
Support / Re: Obtain normals to adjust vertex controller normals
« Last post by EgonOlsen on November 24, 2023, 07:51:31 am »
I'm not sure what you mean exactly...the vertex controller can access the normals already, so you can modify them there. The issue with that is, as the docs state, that this calculation isn't trivial, because vertex normals depend on adjacent polygons as well.

 What do mean by

Quote
Is it possible to obtain the calculated normals so they could be fed into the vertexcontroller immediately?

Which calculated normals?
24
Support / Obtain normals to adjust vertex controller normals
« Last post by AeroShark333 on November 21, 2023, 05:52:46 pm »
Hello,

Currently I have an Object3D with a vertexcontroller attached to it. (Modify = false mode)
The vertexcontroller only changes the vertices positions of the mesh and doesn't touch the normals.
In the draw method I currently do the following three operations:
1. Apply vertexcontroller
2. Object3D#touch
3. Object3D#calcNormals

Is it possible to obtain the calculated normals so they could be fed into the vertexcontroller immediately? I wish to save calculation costs by not having to calculate the normals every frame.
In a sense I imagine I could pre-compute the normals with Object3D#calcNormals and then save the normals to be reused in the vertexcontroller. I looked at polygonmanager but no luck there...

Thanks in advance!
25
Support / Re: GLB
« Last post by EgonOlsen on November 14, 2023, 10:21:47 am »
I'm not sure...I assume that the format is the same as the one that OpenGL uses? In that case, have you tried to use Matrix.transformToGL() instead? Despite the name, it actually transforms jPCT into GL and back again. Comparing what these two methods do, it looks like as if yours does somehow a "flipped" version of what jPCT's is doing. Like as if it's working on an inverse instead , but I'm not sure...it might be worth a try to give jPCT's method a shot, though.
26
Support / GLB
« Last post by AGP on November 14, 2023, 09:39:01 am »
Egon, I've been stuck for six months on the very last step of importing a GLB model. When I try to animate the (otherwise perfect) model, it gets all messed up. I'm assuming the skeletal calculations are accurate, so could you please verify that this Keyframe class is accurately converting between the Glb coordinate system and jpct's?

Code: [Select]
class Keyframe {
    private double time;
    private Matrix transform;

    public Keyframe(double time, Matrix transform) {
        this.time = time;

        // Normalize the rotation component of the transform
        Quaternion rotation = new Quaternion(transform); // Extracts the rotational component
        rotation.normalize();
        Matrix rotationMatrix = rotation.toMatrix();

        // Adjust the transform to the jPCT coordinate system
        this.transform = adjustToJpctCoordinateSystem(rotationMatrix);

        // Extract and reset translation
        SimpleVector translation = extractTranslation(transform);
        resetTranslation(transform);

        // Extract, check, and apply uniform scale
        SimpleVector scale = extractScale(transform);
        if (!isUniformScale(scale)) {
            scale = new SimpleVector(1f, 1f, 1f); // (1, 1, 1) Use uniform scale if it's not uniform
        }
        Utilities.setScale(this.transform, scale);

        // Combine rotation and scale, reapply translation
        this.transform = combineTransforms(translation, this.transform, scale);
    }
    // Method to adjust a transformation matrix to jPCT's coordinate system
    private Matrix adjustToJpctCoordinateSystem(Matrix transform) {
        Matrix adjustedMatrix = new Matrix(transform);

        // Flip the Y-axis
        adjustedMatrix.set(1, 0, -adjustedMatrix.get(1, 0));
        adjustedMatrix.set(1, 1, -adjustedMatrix.get(1, 1));
        adjustedMatrix.set(1, 2, -adjustedMatrix.get(1, 2));
        // If there's translation on Y-axis, flip it as well
        adjustedMatrix.set(1, 3, -adjustedMatrix.get(1, 3));

        // Flip the Z-axis
        adjustedMatrix.set(2, 0, -adjustedMatrix.get(2, 0));
        adjustedMatrix.set(2, 1, -adjustedMatrix.get(2, 1));
        adjustedMatrix.set(2, 2, -adjustedMatrix.get(2, 2));
        // If there's translation on Z-axis, flip it as well
        adjustedMatrix.set(2, 3, -adjustedMatrix.get(2, 3));

        return adjustedMatrix;
    }
    public double getTime() {
       return time;
    }
    // Extract the translation component from a transformation matrix
    private SimpleVector extractTranslation(Matrix transform) {
        return new SimpleVector(transform.get(3, 0), transform.get(3, 1), transform.get(3, 2));
    }
    public Matrix getTransform() {
       return transform;
    }
    // Reset the translation component of a transformation matrix to zero
    private void resetTranslation(Matrix transform) {
        transform.set(3, 0, 0);
        transform.set(3, 1, 0);
        transform.set(3, 2, 0);
    }
    // Helper method to extract scale from a transformation matrix
    private SimpleVector extractScale(Matrix transform) {
       // Assuming the scale is represented by the length of the axis vectors in the matrix
       SimpleVector scaleX = new SimpleVector(transform.get(0, 0), transform.get(1, 0), transform.get(2, 0));
       SimpleVector scaleY = new SimpleVector(transform.get(0, 1), transform.get(1, 1), transform.get(2, 1));
       SimpleVector scaleZ = new SimpleVector(transform.get(0, 2), transform.get(1, 2), transform.get(2, 2));

       return new SimpleVector(scaleX.length(), scaleY.length(), scaleZ.length());
    }
    // Combine the translation, rotation, and scale into a single transformation matrix
    private Matrix combineTransforms(SimpleVector translation, Matrix rotation, SimpleVector scale) {
        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setIdentity();
        Utilities.setScale(scaleMatrix, scale);

        Matrix combined = new Matrix();
        combined.setIdentity();
        combined.matMul(rotation);
        combined.matMul(scaleMatrix);
        combined.translate(translation);

        return combined;
    }

    // Helper method to check if the scale is uniform
    private boolean isUniformScale(SimpleVector scale) {
       // Check if all components are the same within a small epsilon to account for floating-point precision
       final float epsilon = 0.0001f;
       return Math.abs(scale.x - scale.y) < epsilon && Math.abs(scale.y - scale.z) < epsilon;
    }

    // Method to apply scale to a transformation matrix
    private void applyScaleToTransform(Matrix transform, SimpleVector scale) {
       // Reset the scale component of the matrix to 1
       for (int i = 0; i < 3; i++) {
          float length = new SimpleVector(transform.get(0, i), transform.get(1, i), transform.get(2, i)).length();
          if (length != 0) { // Avoid division by zero
              transform.set(0, i, transform.get(0, i) / length);
              transform.set(1, i, transform.get(1, i) / length);
              transform.set(2, i, transform.get(2, i) / length);
          }
       }

       // Create a scale matrix
       Matrix scaleMatrix = new Matrix();
       scaleMatrix.setIdentity(); // Start with an identity matrix
       scaleMatrix.set(0, 0, scale.x);
       scaleMatrix.set(1, 1, scale.y);
       scaleMatrix.set(2, 2, scale.z);

       // Apply scale by multiplying the existing transform with the scale matrix
       transform.matMul(scaleMatrix);
    }
}
27
Support / Re: Sorting
« Last post by EgonOlsen on September 11, 2023, 07:42:41 am »
Sorry for the late reply...not sure on what metric to sort such a thing, though. As you've mentioned, it doesn't seem to be a list. And a tree would most likely reflect the parent-child relationship.
28
Support / Re: blitting - rotated ? subtractive ?
« Last post by AeroShark333 on August 28, 2023, 09:43:39 pm »
I think both are achievable using some workarounds.
The 90° rotated texture could be done using 3 ways:
1st: load the texture's bitmap 90° rotated
2nd: use Overlay to rotate the texture layer
3rd: use a blitting shader to draw your texture 90° rotated

For the subtractive color, I believe you'd need to use a blitting shader too

I'm not sure if a RenderTexture is needed for a blitting shader to work
29
Support / blitting - rotated ? subtractive ?
« Last post by MichaelJPCT on August 27, 2023, 09:04:18 am »
i wish blitting can be 90 degree rotated and can be subtractive in color.
rotated blitting can be used to mimic the rotation of screen without setting it from Android , and without using different textures.
subtractive color is easier to achieve dark text on light color background, without using different textures. ( i currently use textures with white text on black background and no alpha, additive makes the text look good on dark background)
are these possible?
30
Support / Re: framebuffer.getpixels and screen recorder
« Last post by MichaelJPCT on August 27, 2023, 08:41:26 am »
i think it uses the video encode/decode processor to do the encoding in vram then transfer the data stream to system ram/network/storage, just like recording video from physical camera.
Pages: 1 2 [3] 4 5 ... 10