Hi there,
I have resolved the trouble: i have changed the loader. Now i use
Loader3DS... this is an example of how it works:
/////////BEGIN
import java.applet.Applet; //perhaps not all of these are needed!
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.io.*;
import com.mnstarfire.loaders3d.*;
import java.net.URL;
import java.util.*;
public class YourClass extends JApplet {
private SimpleUniverse SimpleU=null;
private Canvas3D canvas3D= null;
private TransformGroup TGparent=null;
//METHODS
void dress(Shape3D a,Material b, URL img ) {
Appearance app = new Appearance();
TextureLoader texLoader = new TextureLoader(img,this);
Texture2D textre = (Texture2D) texLoader.getTexture();
textre.setBoundaryModeS(Texture2D.WRAP);
textre.setBoundaryModeT(Texture2D.WRAP);
textre.setEnable(true);
app.setTexture(textre);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
app.setTextureAttributes(texAttr);
app.setMaterial(b);
TexCoordGeneration texCoord = new
TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2);
app.setTexCoordGeneration(texCoord);
a.setAppearance(app);
}
public BranchGroup manip_full() {
BranchGroup BG = new BranchGroup();
TransformGroup Tg = new TransformGroup();
TransformGroup model=null;
Color3f black = new Color3f(1f,1f,1f);
Color3f white = new Color3f(0.0f,0.0f,0f);
Color3f red = new Color3f(1f,0.0f,0f);
Color3f yellow = new Color3f(1f,1f,0f);
Color3f blue = new Color3f(0.0f,0.0f,1f);
Color3f objColor = new Color3f(0.4f, 0.8f, 0.3f);
String codeBaseString=null;
URL dove=null,codeBase=null;
Inspector3DS loader;
try {
codeBase = getCodeBase();
codeBaseString = codeBase.toString();
} catch (Exception e) { codeBaseString = "file:./"; }
try
{
dove=new URL(codeBaseString + "meshes/YourMesh.3ds");
}
catch (Exception e)
{ System.out.println("URL not found\n");}
try {
loader = new Inspector3DS(dove);
loader.setURLBase(codeBaseString);
//loader.setLogging(true);
//loader.setDetail(6);
loader.parseIt();
model = loader.getModel();
}
catch(Exception a) {System.out.println("Problem with the Loader");}
Enumeration e = model.getAllChildren();
Shape3D tmp_shape = traverse(e); //get the Shape from the file
Material Copper = new Material(new Color3f(0.3f,0.1f,0f),new
Color3f(0,0,0),new Color3f(0.3f,0.1f,0f),
new Color3f(0.75f,0.3f,0f),20);
try{
dove =new URL(codeBaseString+"images/YourTexture.jpg");
}
catch (Exception e1) {System.out.println("error openoing:
YourTexture.jpg\n");}
dress(tmp_shape,Copper, dove);
Tg.addChild(tmp_shape);
BG.addChild(Tg);
return BG;
}
/* This Function get the first (and supposed only) Shape3D in the file*/
Shape3D traverse(Enumeration e) {
Shape3D donaldDuck=null;
while (e.hasMoreElements())
{
Object o = e.nextElement();
if (o instanceof Shape3D)
{
donaldDuck = new Shape3D();
donaldDuck = (Shape3D) ((Shape3D) o).cloneNode(false);
}
else
if (o instanceof Group) {
return this.traverse(((Group)o).getAllChildren());
}
else
System.out.println("mumble mumble\n");
}
return donaldDuck;
}
public BranchGroup createSceneGraph() {
BranchGroup BG = new BranchGroup();
TGparent=new TransformGroup();
TGparent.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
TGparent.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
TGparent.addChild(manip_full());
BG.addChild(TGparent); // potrebbe servire avere un intermediario...
return BG;
}
BranchGroup setLights() {
BranchGroup BG = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
200.0);
Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
AmbientLight aLgt = new AmbientLight(alColor);
aLgt.setInfluencingBounds(bounds);
DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
lgt1.setInfluencingBounds(bounds);
BG.addChild(aLgt);
BG.addChild(lgt1);
return BG;
}
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
GraphicsConfiguration c =
SimpleUniverse.getPreferredConfiguration();
canvas3D = new Canvas3D(c);
contentPane.add(canvas3D,BorderLayout.CENTER);
BranchGroup scene = createSceneGraph();
BranchGroup luci = setLights();
luci.addChild(scene); //this is a trick that let me fix the
lights while the objects move
scene = luci;
MouseRotate myMouseRotate = new MouseRotate();
myMouseRotate.setTransformGroup(TGparent);
scene.addChild(myMouseRotate);
myMouseRotate.setSchedulingBounds(new BoundingSphere(new
Point3d(0,0,0),100));
MouseZoom myMouseZoom = new MouseZoom();
myMouseZoom.setTransformGroup(TGparent);
scene.addChild(myMouseZoom);
myMouseZoom.setSchedulingBounds(new BoundingSphere(new
Point3d(0,0,0),100));
scene.compile();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
Transform3D casper = new Transform3D();
Transform3D donaldDuck = new Transform3D();
simpleU.getViewingPlatform().getViewPlatformTransform().getTransform(casper);
donaldDuck.set(new Vector3d(0,0,2.5d)); //this is not a very
good way to move the ViewPlatform
donaldDuck.mul(casper);
simpleU.getViewingPlatform().getViewPlatformTransform().setTransform(donaldDuck);
simpleU.addBranchGraph(scene);
}
public static void main(String[] args) {
Frame frame = new MainFrame(new YourClass(), 450, 450);
}
}
////////////////////END
This is not bugless or optimized. I hope someone can get some help from it.
Marco Romano
===========================================================================
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".