2012-07-12 88 views
0

下面是一张椅子我使用搅拌机创建:为什么我的物体的纹理没有显示出来?

enter image description here

现在,当我把它用Java3D的,这是我所得到的显示:

enter image description here

为什么我的纹理显示不出来在java中?这里是我的显示椅子代码:

package com; 

import java.applet.Applet; 
import java.awt.BorderLayout; 
import java.awt.Frame; 
import java.awt.GraphicsConfiguration; 

import javax.media.j3d.Alpha; 
import javax.media.j3d.Appearance; 
import javax.media.j3d.Background; 
import javax.media.j3d.BoundingSphere; 
import javax.media.j3d.BranchGroup; 
import javax.media.j3d.Canvas3D; 
import javax.media.j3d.DirectionalLight; 
import javax.media.j3d.RotationInterpolator; 
import javax.media.j3d.Transform3D; 
import javax.media.j3d.TransformGroup; 
import javax.vecmath.Color3f; 
import javax.vecmath.Point3d; 
import javax.vecmath.Vector3f; 

import com.microcrowd.loader.java3d.max3ds.Loader3DS; 
import com.sun.j3d.loaders.Scene; 
import com.sun.j3d.loaders.objectfile.ObjectFile; 
import com.sun.j3d.utils.applet.MainFrame; 
import com.sun.j3d.utils.geometry.ColorCube; 
import com.sun.j3d.utils.universe.SimpleUniverse; 

public class LoadAnObject extends Applet 
{ 
    public LoadAnObject() 
    { 
     setLayout(new BorderLayout()); 
     GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); 
     Canvas3D canvas = new Canvas3D(config); 
     add("Center", canvas); 

     BranchGroup content = getScene(); 
     content.compile(); 

     SimpleUniverse universe = new SimpleUniverse(canvas); 
     universe.getViewingPlatform().setNominalViewingTransform(); 
     universe.addBranchGraph(content); 
    } 

    public BranchGroup getScene() 
    { 
     BranchGroup group = new BranchGroup(); 

     Loader3DS loader = new Loader3DS(); 

     Scene scene = null; 

     try 
     { 
      scene = loader.load("/Users/John/ArtOfIllusion/Chair.3ds"); 
     }catch(Exception e){e.printStackTrace();} 

     TransformGroup rotateGroup = new TransformGroup(); 
     Transform3D rotate = new Transform3D(); 
     rotate.rotX(- Math.PI/8); 
     rotateGroup.setTransform(rotate); 
     rotateGroup.addChild(scene.getSceneGroup()); 

     TransformGroup objSpin = new TransformGroup(); 
     objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
     //objSpin.addChild(new ColorCube(.5)); 
     Alpha rotationAlpha = new Alpha(-1, 4000); 
     RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); 

     BoundingSphere boundSphere = new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 200); 
     rotator.setSchedulingBounds(boundSphere); 
     objSpin.addChild(rotator); 
     objSpin.addChild(rotateGroup); 

     TransformGroup moveGroup = new TransformGroup(); 
     Transform3D move = new Transform3D(); 
     move.setTranslation(new Vector3f(0.0f, 0.0f, -20.0f)); 
     moveGroup.setTransform(move); 
     moveGroup.addChild(objSpin); 

     group.addChild(moveGroup); 

     Background background = new Background(0.0f, 1.0f, 1.0f); 
     background.setApplicationBounds(new BoundingSphere()); 
     group.addChild(background); 

     Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); 
     BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); 
     Vector3f light1Direction = new Vector3f(0, 0, 10); 
     DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); 
     light1.setInfluencingBounds(bounds); 
     group.addChild(light1); 

     return group; 
    } 

    public static void main(String args[]) 
    { 
     Frame frame = new MainFrame(new LoadAnObject(), 256, 256); 
    } 
} 

我正在使用的文件格式是.3DS,这里是我从拿到装载机:

如何我得到的椅子纹理显示在Java?


编辑:

我编我的椅子到.3DS文件,而不是一个目标文件,我现在不得不使用.3DS装载机,我从这里得到:

代码不会有太大变化,而不是使用ObjectFile我现在使用Loader3DS

enter image description here

所以,现在很明显,你可以看到,材料调过来的,但没有质感,我如何得到纹理展现出来?

+1

+1了详尽的问题。我不明白为什么有人会低估它。 – Kay 2012-07-13 08:14:59

+0

谢谢,我也不明白 – John 2012-07-13 17:19:39

回答

1

爪哇显然,除非它们被从图像生成不加载纹理。我能够加载纹理的唯一方法是从图像贴图纹理。我尝试了几种不同的格式,但我什么也没有。如果您要尝试在Java3D中使用纹理,请确保使用图像贴图纹理!

相关问题