Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AGP

Pages: [1] 2 3 ... 116
1
Support / Re: GLB
« on: December 19, 2023, 11:20:24 pm »

2
Support / GLB
« 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);
    }
}

3
Support / Sorting
« on: August 25, 2023, 09:21:05 pm »
This is more of a programming question than a jpct question. But since it's for sorting the bones I'm importing off of GLB in jpct, this is as good a place as any to ask it. So I'm writing a 2d skeleton viewer. Each bone knows its parent, and that's about all the information I have on them. Since I know it's a bipedal skeleton generated with Mixamo, I know the skeleton's shape. All I need is to sort the bones and draw them out. I'm doing this to verify that the parent/child relationship is accurate. What's the best way to run through the 2d List<Bone> and produce a sorted array? Now that I asked the question I realize that it's not a linear list, it's a tree. Any ideas?

4
Support / Re: raspberry pi, orange pi, etc
« on: April 28, 2023, 02:14:28 am »
Not to keep hitting the same notes, but Raspberry PI does use Vulkan... (https://www.raspberrypi.com/news/vulkan-update-version-1-1-conformance-for-raspberry-pi-4/)

If jpct would use the Vulkan renderer I would write a glb importer both for Java and for my C# port. It gives me more pleasure to program for jpct than it does for an engine like Godot (as much as I like Godot). Makes me feel like I'm actually needed. lol

Do you know what? I wrote one anyway. My glb importer only uses the org.json jar. It can read all the built-in textures and set them to the model. Limitations: it will set the normal maps as diffuse and it's not reading any kind of animations. But I'm pretty happy with it. ChatGPT did help a lot, but darn does it take a lot of coaxing to get consistent help from it.

5
Support / Re: raspberry pi, orange pi, etc
« on: January 25, 2023, 11:20:20 pm »
Oh, and here's something I didn't know: lwjgl now has Vulkan bindings: https://www.lwjgl.org/.

6
Support / Re: raspberry pi, orange pi, etc
« on: January 25, 2023, 11:11:51 pm »
You might be right about the bloating of the drivers, but I don't think that that's all it is. There's a whole lot of 3d tricks that no one could have predicted when OpenGL was conceived. I have neither looked at Vulkan nor read this book (https://github.com/lwjglgamedev/vulkanbook). But the fact that the book exists must mean there are Java wrappers. And even if it were just that the drivers got bloated, well, the drivers got bloated!

7
Support / Re: raspberry pi, orange pi, etc
« on: January 19, 2023, 06:42:26 pm »
Not to keep hitting the same notes, but Raspberry PI does use Vulkan... (https://www.raspberrypi.com/news/vulkan-update-version-1-1-conformance-for-raspberry-pi-4/)

If jpct would use the Vulkan renderer I would write a glb importer both for Java and for my C# port. It gives me more pleasure to program for jpct than it does for an engine like Godot (as much as I like Godot). Makes me feel like I'm actually needed. lol

8
Support / Re: Cpct?
« on: August 18, 2021, 10:56:30 pm »
What do you think that it says that the objects that don't get rendered are always calling CompiledInstance.compileToVBO()?

9
Support / Re: Cpct?
« on: August 13, 2021, 10:39:00 pm »
The character (which is skinned and stored in a JSON-serialized format that mimics the original Java one) and the Skybox get rendered.

10
Support / Re: Cpct?
« on: August 12, 2021, 12:08:11 am »
I'm getting, I think, to a crucial place. I believe that it's one of the following three variables. If you have any insight about what might be wrong that around line 544 in CompiledInstance the rendering block never clears the if (!useDL || (listID == 0 && !buffersCreated)) test (and, thus, never renders most objects) I would appreciate it. The following is the state of most every object in this forest scene.

Code: [Select]
if (useDL || (listID != 0 && buffersCreated))
         System.Console.WriteLine("Not rendering "+obj.getName() +" because useDL: "+useDL +", listID: "+listID +", buffersCreated: "+buffersCreated);
Quote
Not rendering grassB628_jPCT438 because useDL: True, listID: 0, buffersCreated: True

11
Support / Re: Cpct?
« on: August 10, 2021, 07:48:37 pm »
I put a WriteLine on the following block inside CompiledInstance.render() and for every model, including the ones that didn't render, I get "...about to render."

Code: [Select]
                     if (!wireFrame) {
                            if (vertexAlpha) {
                                   // Actually, this doesn't matter but anyway...
                                   cols[3] = 1;
                            }
                            System.Console.WriteLine("CompiledInstance.render(): "+obj.getName() +" about to render.");

12
Support / Re: Cpct?
« on: August 09, 2021, 07:59:10 pm »
Update: the line thing (running my game by calling mono before the .exe) sometimes crashes the application and still fails to give you numbers. Here's where I am: I can compile(true) my main character. The Skybox, too, but it becomes semi-transparent. Nearly everything else disappears when compiled. Maybe the Skybox transparency is a hint, but I don't think so because the disappearing objects also don't show up as wireframes. It's as if jpct is either translating them far out of view or otherwise clipping them.

13
Support / Re: Cpct?
« on: August 07, 2021, 08:02:36 pm »
See, that's why people should talk to each other. I could have been stuck on this forever if you hadn't mentioned line numbers. By making the debug call "debug:embedded" I got the line numbers in. The problem had been that my Lights class was not initializing the distanceOverride array. Compiled objects are still not rendering, though, so off to find that issue (now aided by the line numbers).

14
Support / Re: Cpct?
« on: August 06, 2021, 08:00:07 am »
Actually, I knew that. I also now know that the -debug option is not supported on Windows (or at least not Windows x64) for whatever reason. And every solution to line-number printing I find fails (one of them always prints line 0, another doesn't even compile on Mono). Fun.

15
Support / Re: Cpct?
« on: August 04, 2021, 08:34:47 pm »
It's compiled code, man, it's not a bytecode. No line numbers in C# stack traces.

Pages: [1] 2 3 ... 116