Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Support / Re: GLB
« Last post by AGP on December 19, 2023, 11:20:24 pm »
12
Projects / OpenRoad - Arcade racing
« Last post by EgonOlsen on December 09, 2023, 12:20:24 pm »
Long time no new project here...so I thought that I might as well contribute something.

It's not really a "project", but something that I'm working on from time to time. It started out as an experiment to see, how feasible it is to generate a road based on the random number generator alone. Over the months, it turned into something that you can actually "play" albeit it's far from being a game of some sort.

The road and the AI vehicles are all generated, nothing has been placed by hand. It has basic sounds, arcade like vehicle controls, traffic and a very crude collision "model".

Here's a video: https://youtu.be/o3MthgPRDsE?si=GEl1AJA2DRFxJCaJ

And this is how it looks:



13
Support / Re: Obtain normals to adjust vertex controller normals
« Last post by EgonOlsen on November 28, 2023, 07:35:36 am »
If that's the case, I guess that there must have been a reason for it... ;)

...I just can't remember it...
14
Support / Re: Obtain normals to adjust vertex controller normals
« Last post by AeroShark333 on November 27, 2023, 07:58:18 pm »
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.
Thank you, works perfectly! :D

Also, this might be a minor bug: I think the 'shininess' value is not seem to be passed to the fragment shader (while the other uniform variables from the default vertex shader seem accessible though in the fragment shader). I don't need this as I can put custom shader code anyway... But I thought it would be nice to know.
15
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.
16
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...
17
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?
18
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!
19
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.
20
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);
    }
}
Pages: 1 [2] 3 4 ... 10