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

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



■■■  女性比率、47%突破! 累計会員数、3万6千人突破!  ■■■
■■■                             ■■■
■☆■  》》》 “EメールLove”始めませんか? 《《《  ■☆■
■■■                             ■■■
■■■ 今すぐクリック!→   http://www.deai.co.jp/dns.htm    ■■■
-----------------------------------------------------------------------

> もう少し情報が欲しいです。たとえば
>
> (1)どんなシーングラフの構造なのか?

ずいぶん前に教えていただいた、
平面ポリゴンを十字上に配置して人のテクスチャを張るというものです。

> (2)どんなテクスチャーなのか?

人の正面、後ろ、右、左のような写真です。

> (3)どんな GeometryArray なのか?
>   ・頂点配列は?

人が原点の上に立ってるような頂点配列。
っで、わかっていただけるでしょうか?

>   ・テクスチャー座標配列は?

?

> (4)どんなAppearance なのか?
>   ・Texture
>   ・TextureAttributes
>   ・TexCoordGenerator

…、んー、ソース載せます(^_^;)。
どう説明していいかわからない。

っでこれに付随して質問なんですが、
ソースを見てもらうとわかると思うんですが、
前後、左右ともふたつの四角形オブジェクトを背中合わせに二枚配置しています。
ので、オブジェクト数は4枚になりますよね。
もし一つの四角形の両面にテクスチャが張れれば二枚ですむのですが、
両面にテクスチャを張ることは可能なんでしょうか?

こちらもよくわからないままあやふやでやってるんでうまく説明できなくて申し訳な
いです。
いかにソースを載せます。

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

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[0];
  point[1] = vertices[1];
  point[2] = vertices[2];
  point[3] = vertices[3];
  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[4];
  point[1] = vertices[5];
  point[2] = vertices[6];
  point[3] = vertices[7];
  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,0.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();
  TexCoordGeneration texGen = new TexCoordGeneration();
  texGen.setPlaneS( texS );
  texGen.setPlaneT( texT ) ;
  ap.setTexture( texture );
  ap.setTexCoordGeneration( texGen );

  return shape;
 }

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