0

I am using Java3D (A java extension by oracle) to make 3d stuff (obviously) and I am trying to spin a 3D object but I keep on getting this error:

Exception in thread "GameThread" javax.media.j3d.CapabilityNotSetException: Group: no capability to set transform
    at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
    at Main.Second.render(Second.java:98)
    at Main.Second.access$0(Second.java:95)
    at Main.Second$1.run(Second.java:80)
    at java.base/java.lang.Thread.run(Thread.java:832)

this is the class where the error is pointed out:

package Main;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JPanel;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.universe.SimpleUniverse;

import Actions.LightBulb;
import Actions.Rotate;
import Actions.Wrap;
import Main.Shapes.Square;

public class Second extends JPanel{
    float Size = 1f;
    boolean running = false;
    int frames = 0;
    float Spinner;
    Transform3D Transform = new Transform3D();
    TransformGroup tg = new TransformGroup();
    
    private static final long serialVersionUID = 1L;
    
    public Second() {
        
        Shape3D sq = new Square().Make(Size);
        
        new Wrap(sq, new Color3f(1f,1f,1f));
        
        //Uni
        SimpleUniverse universe = new SimpleUniverse();
        
        //Group
        BranchGroup Group = new BranchGroup();

        //Trans3D
        Transform.setTranslation(new Vector3f(-Size/2f,-Size/2f,-Size/2f));
        
        
        //TransG
        tg.setTransform(Transform);
        tg.addChild(sq);
        
        new Rotate(Transform);
        
        Group.addChild(tg);
        
        //Lighting
        new LightBulb(Group, new Color3f(1f,1f,1f), 1f);
        
        //Finals
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.addBranchGraph(Group);
        
        new Thread(new Runnable() {
            @Override
            public void run(){
                running = true;
                long lastTime = System.nanoTime();
                final double amountOfTicks = 20.0;
                double ns = 1000000000 / amountOfTicks;
                double delta = 0;
                int updates = 0;
                long timer = System.currentTimeMillis();

                while(running){
                    long now = System.nanoTime();
                    delta += (now - lastTime) / ns;
                    lastTime = now;
                    if(delta >= 1){
                        tick();
                        updates++;
                        delta--;
                    }
                    render();
                    frames++;

                    if(System.currentTimeMillis() - timer > 1000){
                        timer += 1000;
                        System.out.println(updates + " Ticks, Fps " + frames);
                        updates = 0;
                        frames = 0;
                    }

                }
            }
        }, "GameThread").start();
    }
    
    private void render() {
        Spinner++;
        Transform.setRotation(new AxisAngle4f(0f,0.5f,0f,Spinner));
        tg.setTransform(Transform);
    }
    
    public void tick(){
        
    }
}

if you couldn't see I'm using a separate thread for my game loop and the game loop itself is what is causing the error :)

Thanks in advance!

Hoax
  • 76
  • 8
  • 2
    Google is your friend, see if this helps https://community.oracle.com/tech/developers/discussion/1275874/capability-not-set-exception – JCompetence Jul 19 '21 at 20:49
  • By the way, Java3D is no longer maintained by Oracle and you use an obsolete version. – gouessej Jul 20 '21 at 10:35

1 Answers1

0

After:

TransformGroup tg = new TransformGroup();

Try:

tg.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
Michael Ziluck
  • 599
  • 6
  • 19