[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Java3Djp:00962] Re: テクスチャの張り方2



◆◇◆  ≪eオークション≫      価格創造        ◆◇◆
厳選された極めつけの商品。
ホテルスィートルーム、スノーボード、香水、ブランドバック
 
日本を代表する売り手企業群。だから安心して入札に参加できます。
 
◆◇◆  ≪eオークション≫  http://www.eac.ne.jp/  ◆◇◆
-----------------------------------------------------------

> えんどうです。
> >   TexCoordGeneration texGen = new TexCoordGeneration();
> >   texGen.setPlaneS( texS );
> >   texGen.setPlaneT( texT ) ;
>
> >   ap.setTexCoordGeneration( texGen );
>
> をとりあえずやめてみてください。

すみません、間違えました。
この部分は使ってません。
以下が今のソースです。

----------------------------------

import java.awt.Frame;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.behaviors.picking.*;

public class ObjMake {

  public ObjMake(){
    Canvas3D canvas = new Canvas3D(null);
    SimpleUniverse universe = new SimpleUniverse( canvas );

    BranchGroup root = new BranchGroup();
    TransformGroup trans = new TransformGroup();
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);


    Point3d[] vertices = new Point3d[8];

    vertices[0] = new Point3d(-0.5, 1.5, 0.0);
    vertices[1] = new Point3d(-0.5, 0.0, 0.0);
    vertices[2] = new Point3d(0.5, 0.0, 0.0);
    vertices[3] = new Point3d(0.5, 1.5, 0.0);
    vertices[4] = new Point3d(0.0, 1.5, 0.5);
    vertices[5] = new Point3d(0.0, 0.0, 0.5);
    vertices[6] = new Point3d(0.0,0.0,-0.5);
    vertices[7] = new Point3d(0.0,1.5,-0.5);


    Point3d[] point = new Point3d[4];


    //正面
    point[0] = vertices[3];
    point[1] = vertices[0];
    point[2] = vertices[1];
    point[3] = vertices[2];
    trans.addChild(DrawRect(universe,point,"front.gif",new
Vector4f(1.0f,0.0f,0.0f,0.0f),new Vector4f(0.0f,0.7f,0.0f,0.0f)));

    //背面

    point[0] = vertices[0];
    point[1] = vertices[3];
    point[2] = vertices[2];
    point[3] = vertices[1];
    trans.addChild(DrawRect(universe,point,"rear.gif",new
Vector4f(-1.0f,0.0f,0.0f,0.0f),new Vector4f(0.0f,0.7f,0.0f,0.0f)));

   //左
    point[0] = vertices[7];
    point[1] = vertices[4];
    point[2] = vertices[5];
    point[3] = vertices[6];
    trans.addChild(DrawRect(universe,point,"left.gif",new
Vector4f(0.0f,0.0f,1.0f,0.0f),new Vector4f(0.0f,0.7f,0.0f,0.0f)));
    //右
    point[0] = vertices[4];
    point[1] = vertices[7];
    point[2] = vertices[6];
    point[3] = vertices[5];
    trans.addChild(DrawRect(universe,point,"right.gif",new
Vector4f(0.0f,0.0f,-1.0f,0.0f),new Vector4f(0.0f,0.7f,0.0f,0.0f)));







    BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),10.0);

    PickMouseBehavior behavior1=new PickRotateBehavior(root,canvas,bounds);
    root.addChild(behavior1);
    PickMouseBehavior behavior2=new
PickTranslateBehavior(root,canvas,bounds);
    root.addChild(behavior2);
    PickMouseBehavior behavior3=new PickZoomBehavior(root,canvas,bounds);
    root.addChild(behavior3);

    root.addChild(trans);
    universe.addBranchGraph(root);

    // Observer

    TransformGroup transform;
    Transform3D translation=new Transform3D();
    translation.setTranslation(new Vector3d(0.0,1.5,2.0));

    transform=universe.getViewingPlatform().getViewPlatformTransform();
    transform.setTransform(translation);


    // Phisical Windows
    Frame frame = new Frame( "Room" );
    frame.add( universe.getCanvas(), "Center" );
    frame.setSize( 400, 400 );
    frame.show();
  }

  // 四角形描画メソッド
  private Shape3D DrawRect(SimpleUniverse universe,Point3d[] vertices,String
tex,Vector4f texS,Vector4f texT){


    QuadArray geometry =
      new QuadArray(vertices.length,
GeometryArray.COORDINATES|GeometryArray.NORMALS|GeometryArray.TEXTURE_COORDI
NATE_2);
    geometry.setCoordinates(0, vertices);


    Appearance ap = new Appearance();

    Shape3D shape = new Shape3D(geometry,ap);

    TextureLoader tloader
      = new TextureLoader( tex, universe.getCanvas() );
    Texture texture = tloader.getTexture();

    geometry.setTextureCoordinate(0,new Point2f(1.0f,1.0f));
    geometry.setTextureCoordinate(1,new Point2f(0.0f,1.0f));
    geometry.setTextureCoordinate(2,new Point2f(0.0f,0.0f));
    geometry.setTextureCoordinate(3,new Point2f(1.0f,0.0f));


    ap.setTexture( texture );


    return shape;
  }

  /** 実行用のメソッド */
  public static void main( String[] args ) {
    ObjMake test = new ObjMake();
  }
}