Hi all, Anyone give me any pointers as to why nothing is appearing in my scene. Its probably something easy but its driving me mad. Thanks, Dave.
Wall Class: import java.applet.*; import java.awt.*; import java.awt.Frame; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.keyboard.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; import com.sun.j3d.loaders.*; import java.io.*; import java.util.*; public class Wall extends Applet { private void buildMultiTexturedWall(Appearance floorAp , int roomSize, Point3d p1,Point3d p2) { TransformGroup transformGroup = null; BranchGroup bg = new BranchGroup(); Vector3d dir = new Vector3d(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); double wallLength = Math.sqrt(dir.x*dir.x + dir.y*dir.y); int itePlan = (int) wallLength/roomSize; int iteZ = (int) dir.z/roomSize; Vector3d dirScaled = new Vector3d(dir.x/itePlan, dir.y/itePlan, roomSize); for (int j = 0; j < iteZ; j++) { for (int i = 0; i < itePlan; i++) { GeometryArray floor = new QuadArray(4,QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); floor.setCapability(QuadArray.ALLOW_COLOR_WRITE|TransformGroup.ALLOW_TRANSFORM_READ |TransformGroup.ALLOW_TRANSFORM_WRITE|Group.ALLOW_CHILDREN_EXTEND| Group.ALLOW_CHILDREN_READ| Group.ALLOW_CHILDREN_WRITE); Point3d pp0 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + j*dirScaled.z); Point3d pp1 = new Point3d(p1.x + (i+1)*dirScaled.x , p1.y + (i+1)*dirScaled.y , p1.z + j*dirScaled.z); Point3d pp2 = new Point3d(p1.x + (i+1)*dirScaled.x, p1.y + (i+1)*dirScaled.y, p1.z + (j+1)*dirScaled.z); Point3d pp3 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + (j+1)*dirScaled.z); if ((p1.x < 0.0) && (p2.x < 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.x > 0.0) && (p2.x > 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.y > 0.0) && (p2.y > 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } else if ((p1.y < 0.0) && (p2.y < 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } Shape3D floorShape3D = new Shape3D(floor, floorAp); floorShape3D.getGeometry().setCapability(Geometry.ALLOW_INTERSECT); bg.addChild(floorShape3D); } } transformGroup.addChild(bg); //added multiTexture } } And a test class: import java.applet.*; import java.awt.*; import java.awt.Frame; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.keyboard.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; import com.sun.j3d.loaders.*; import java.io.*; import com.sun.j3d.utils.image.TextureLoader; import java.util.*; public class test extends Applet { BranchGroup branchGroup; Canvas3D c; SimpleUniverse u; private BoundingSphere bounds; String imageName; public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); return objRoot; } ////////////////////////////////////////////// //Adds the wall to the scene private BranchGroup addWall() { Appearance floorAp = new Appearance(); String filename = "stripe.gif"; TextureLoader loader = new TextureLoader(filename, null); ImageComponent2D image = loader.getImage(); if(image == null) { System.out.println("load failed for texture: "+filename); } // can't use parameterless constuctor Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight()); texture.setImage(0, image); //texture.setEnable(false); floorAp.setTexture(texture); floorAp.setTransparencyAttributes( new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f)); BranchGroup branchGroup = new BranchGroup(); WallManager wall = new WallManager(branchGroup); Point3d p1 = new Point3d(10,1,1); Point3d p2 = new Point3d(1,0,10); //something here. Think its coordinates. Look up point3d coordinates!!!!!!!! wall.buildMultiTexturedWall(floorAp, 40, p1, p2); bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); branchGroup.compile(); return branchGroup; } public void buildMultiTexturedWall(Appearance floorAp, int roomSize, Point3d p1,Point3d p2) { TransformGroup transformGroup = null; BranchGroup bg = new BranchGroup(); Vector3d dir = new Vector3d(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); double wallLength = Math.sqrt(dir.x*dir.x + dir.y*dir.y); int itePlan = (int) wallLength/roomSize; int iteZ = (int) dir.z/roomSize; Vector3d dirScaled = new Vector3d(dir.x/itePlan, dir.y/itePlan, roomSize); for (int j = 0; j < iteZ; j++) { for (int i = 0; i < itePlan; i++) { GeometryArray floor = new QuadArray(4,QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); floor.setCapability(QuadArray.ALLOW_COLOR_WRITE|TransformGroup.ALLOW_TRANSFORM_READ |TransformGroup.ALLOW_TRANSFORM_WRITE|Group.ALLOW_CHILDREN_EXTEND| Group.ALLOW_CHILDREN_READ| Group.ALLOW_CHILDREN_WRITE); Point3d pp0 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + j*dirScaled.z); Point3d pp1 = new Point3d(p1.x + (i+1)*dirScaled.x , p1.y + (i+1)*dirScaled.y , p1.z + j*dirScaled.z); Point3d pp2 = new Point3d(p1.x + (i+1)*dirScaled.x, p1.y + (i+1)*dirScaled.y, p1.z + (j+1)*dirScaled.z); Point3d pp3 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + (j+1)*dirScaled.z); if ((p1.x < 0.0) && (p2.x < 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.x > 0.0) && (p2.x > 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.y > 0.0) && (p2.y > 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } else if ((p1.y < 0.0) && (p2.y < 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } Shape3D floorShape3D = new Shape3D(floor, floorAp); floorShape3D.getGeometry().setCapability(Geometry.ALLOW_INTERSECT); bg.addChild(floorShape3D); } } transformGroup.addChild(bg); //added multiTexture } public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); c = new Canvas3D(config); add("Center", c); u = new SimpleUniverse(c); BranchGroup scene = createSceneGraph(); u.addBranchGraph(addWall()); u.addBranchGraph(scene); } public static void main(String[] args) { Frame frame = new MainFrame(new test(), 600, 400); } } wall Manager: import java.io.*; import javax.media.j3d.*; import javax.vecmath.*; public class WallManager { BranchGroup branchGroup; public WallManager(BranchGroup b) { branchGroup = b; } public void buildMultiTexturedWall(Appearance floorAp , int roomSize, Point3d p1,Point3d p2) { TransformGroup transformGroup = null; BranchGroup bg = new BranchGroup(); Vector3d dir = new Vector3d(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); double wallLength = Math.sqrt(dir.x*dir.x + dir.y*dir.y); int itePlan = (int) wallLength/roomSize; int iteZ = (int) dir.z/roomSize; Vector3d dirScaled = new Vector3d(dir.x/itePlan, dir.y/itePlan, roomSize); for (int j = 0; j < iteZ; j++) { for (int i = 0; i < itePlan; i++) { GeometryArray floor = new QuadArray(4,QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); floor.setCapability(QuadArray.ALLOW_COLOR_WRITE|TransformGroup.ALLOW_TRANSFORM_READ |TransformGroup.ALLOW_TRANSFORM_WRITE|Group.ALLOW_CHILDREN_EXTEND| Group.ALLOW_CHILDREN_READ| Group.ALLOW_CHILDREN_WRITE); Point3d pp0 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + j*dirScaled.z); Point3d pp1 = new Point3d(p1.x + (i+1)*dirScaled.x , p1.y + (i+1)*dirScaled.y , p1.z + j*dirScaled.z); Point3d pp2 = new Point3d(p1.x + (i+1)*dirScaled.x, p1.y + (i+1)*dirScaled.y, p1.z + (j+1)*dirScaled.z); Point3d pp3 = new Point3d(p1.x + i*dirScaled.x, p1.y + i*dirScaled.y, p1.z + (j+1)*dirScaled.z); if ((p1.x < 0.0) && (p2.x < 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.x > 0.0) && (p2.x > 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(0, new Point2f(0, 0)); floor.setTextureCoordinate(1, new Point2f(0, 1)); floor.setTextureCoordinate(2, new Point2f(1, 1)); floor.setTextureCoordinate(3, new Point2f(1, 0)); } else if ((p1.y > 0.0) && (p2.y > 0.0)) { floor.setCoordinate(0,pp0); floor.setCoordinate(1,pp1); floor.setCoordinate(2,pp2); floor.setCoordinate(3,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } else if ((p1.y < 0.0) && (p2.y < 0.0)) { floor.setCoordinate(3,pp0); floor.setCoordinate(2,pp1); floor.setCoordinate(1,pp2); floor.setCoordinate(0,pp3); floor.setTextureCoordinate(3, new Point2f(0, 0)); floor.setTextureCoordinate(2, new Point2f(0, 1)); floor.setTextureCoordinate(1, new Point2f(1, 1)); floor.setTextureCoordinate(0, new Point2f(1, 0)); } Shape3D floorShape3D = new Shape3D(floor, floorAp); floorShape3D.getGeometry().setCapability(Geometry.ALLOW_INTERSECT); bg.addChild(floorShape3D); } } } } =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".