Main Menu
Menu

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.

Show posts Menu

Messages - AGP

#1
Support / Re: Software Render Color Depth
February 16, 2025, 09:52:21 PM
Thanks a lot. It is unnecessarily complicated, though, isn't it?
#2
Support / Re: Software Render Color Depth
February 12, 2025, 07:21:56 AM
I tried texture.setAlpha(). Even tried replacing the texture in the texture manager. It doesn't change the object's opacity in any way.
#3
Support / Re: Software Render Color Depth
February 09, 2025, 08:47:48 PM
So is there no way to do a proper fadeout?
#4
Support / Re: Software Render Color Depth
February 08, 2025, 10:06:59 PM
I thought that it was a color thing that nothing I do makes an object fade in or out with the software render. This is a basic test I wrote (several different attempts in there, none of which work):


import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;

public class Transparency extends Frame implements WindowListener {
    private World theWorld;
    private FrameBuffer buffer;
    private Camera cam;
    private Object3D obj;
    private boolean keepGoing, turnRight, turnLeft;
    private com.threed.jpct.util.KeyMapper keyMapper;
    private Texture boxMap;
    private int transparency = 0;
    private FadeoutEffect effect;

    public Transparency() {
       this.setTitle("BR's");
       theWorld = new World();
       buffer = new FrameBuffer(1440, 900, FrameBuffer.SAMPLINGMODE_NORMAL);
       obj = com.threed.jpct.util.ExtendedPrimitives.createBox(new SimpleVector(2f, 2f, 2f));//Primitives.getCube(1f);
       TextureManager.getInstance().addTexture("boxMap", (boxMap=new Texture("BoxMap.png", true)));
       boxMap.setEffect((effect=new FadeoutEffect()));
       obj.setTexture("boxMap");
       obj.build();
       obj.setTransparencyMode(Object3D.TRANSPARENCY_MODE_DEFAULT);
       obj.setTransparency(transparency);
       Object3D backgroundPlane = Primitives.getPlane(1, 4f);
       backgroundPlane.build();
       backgroundPlane.translate(0f, -2f, 0f);
       theWorld.addObject(backgroundPlane);
       cam = theWorld.getCamera();
       cam.moveCamera(Camera.CAMERA_MOVEOUT, 8f);
       theWorld.addObject(obj);
       obj.setLighting( Object3D.LIGHTING_NO_LIGHTS );
       keyMapper = new com.threed.jpct.util.KeyMapper(this);
       this.addWindowListener(this);
       this.setSize(buffer.getWidth(), buffer.getHeight());
       this.setVisible(true);
       loop();
    }

    public void loop() {
       keepGoing = true;
       while (keepGoing) {
           buffer.clear();
           com.threed.jpct.util.KeyState keyState = keyMapper.poll();
           if (keyState.getState() == com.threed.jpct.util.KeyState.PRESSED)
              keyPressed(keyState.getKeyCode());
           else if (keyState.getState() == com.threed.jpct.util.KeyState.RELEASED)
              keyReleased(keyState.getKeyCode());
           if (turnRight)
              obj.rotateY(-.01f);
           if (turnLeft)
              obj.rotateY(.01f);
           theWorld.renderScene(buffer);
           theWorld.draw(buffer);
           //theWorld.drawWireframe(buffer, Color.yellow);
           buffer.display(this.getGraphics());
           Thread.yield();
       }
       buffer.dispose();
       this.dispose();
       System.exit(0);
    }

    private void keyPressed(int keyCode) {
       if (keyCode == KeyEvent.VK_RIGHT)
           turnRight = true;
       if (keyCode == KeyEvent.VK_LEFT)
           turnLeft = true;
    }
    private void keyReleased(int keyCode) {
       if (keyCode == KeyEvent.VK_RIGHT)
           turnRight = false;
       if (keyCode == KeyEvent.VK_LEFT)
           turnLeft = false;
       if (keyCode == KeyEvent.VK_T) {
           float fade = 1.00f;
           if (transparency < 255)
              fade = (float)((transparency+=8)/255f);
           effect.transparency = 255-transparency;
           obj.setTransparency(255-transparency);
           //boxMap.setAlpha(255-transparency);
           TextureManager.getInstance().replaceTexture("boxMap", boxMap);
           //obj.setAdditionalColor(intensity(boxColor, fade));
           //boxMap.applyEffect();
           Logger.log("Transparency: "+transparency, Logger.MESSAGE);
       }
    }
    public void windowClosing(WindowEvent e) {
       keepGoing = false;
    }
    public void windowClosed(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}

    public static void main(String[] args) {
       new Transparency();
    }
}
class FadeoutEffect implements ITextureEffect {
    public int transparency;
    private Texture tex;
    public FadeoutEffect() {
    }

    public void init(Texture texture) {
       this.tex = texture;
    }

    public void apply(int[] dest, int[] src) {
       /*for (int y =0; y < 512;y++) {
              for (int x = 0; x < 512; x++) {
                     dest[y*x] = transparency;
              }
       }*/
       tex.setAlpha(transparency);
    }

    public boolean containsAlpha() {
       return false;
    }
}
#5
Support / Software Render Color Depth
February 07, 2025, 11:08:25 PM
If I'm not mistaken, the software renderer works with 16 bits for color (and a third byte for transparency?). Is it trivial giving it all 24 bits (plus a byte for transparency). If so, would you?
#6
News / Re: Forum upgraded to 2.1.4
January 31, 2025, 09:52:55 PM
Please try to search for a topic. It doesn't fail sometimes, it fails every time.
#7
News / Re: Forum upgraded to 2.1.4
January 28, 2025, 09:00:20 PM
I've tested it with Edge, just in case. Same: "Database error. Please try again. If you come back to this error screen, report the error to an administrator."
#8
Support / Re: Caching Animations in Software Rendering
January 28, 2025, 08:54:26 PM
When the program is already running, each animation cycle gets progressively faster. It's probably not noticeable on the OpenGL renderer only because the hardware rendering already starts fast. Is there no way around this apart from delaying the execution, then?
#9
Support / Caching Animations in Software Rendering
January 22, 2025, 02:19:16 AM
Is that something you can make the software renderer do? Because otherwise jpct goes through several loops of the animations before they're running at full speed.
#10
News / Re: Forum upgraded to 2.1.4
January 21, 2025, 08:41:30 AM
It's still happening, only now it says, "Please try again. If you come back to this error screen, report the error to an administrator."
#11
News / Re: Forum upgraded to 2.1.4
January 13, 2025, 11:44:50 AM
Your shiny message board's search engine isn't working. Keeps returning "database error."
#12
News / Re: Forum upgraded to 2.1.4
November 24, 2024, 12:32:49 AM
Now all we need is support for a current lwjgl. ; )
#13
Support / Re: GLB
December 19, 2023, 11:20:24 PM
#14
Support / GLB
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?


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);
    }
}
#15
Support / Sorting
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?