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

[Java3Djp:01088] Re: Re: [Q] ¥Þ¥¦¥¹¤ÇÊ£¿ô¤Î¥ª¥Ö¥¸¥§¥¯¥È¤òÊÌ¡¹¤ËÆ°¤«¤¹ÊýË¡



:::::::::::::::::::::::::::::::::::::::::::::::::::::::
     <<<<¤Ê¤«¤è¤·¤ß¤ó¤Ê¤Ç³Ú¤·¤¤¤ª¤·¤ã¤Ù¤ê¡ª>>>>
             Âç³Ø¡¦ÍĤʤ¸¤ß¡¦Æ±´üÆþ¼Ò
         £Ä£Î£Ó¤Î£Í£Ì¤Ê¤é¤ß¤ó¤Ê¤º¤Ã¤È°ì½ï¡ª
          ±¿ÍÑ´Êñ¡¦²÷Ŭ¤á¡¼¤ê¤ó¤°¤ê¤¹¤È
         http://www.dns-ml.co.jp/ml.html
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

¥¿¥Ê¥«¡÷¾¦Á¥Âç¤Ç¤¹¡£

¥¢¥É¥Ð¥¤¥¹¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£-> ¤¨¤ó¤É¤¦¤µ¤ó

 >> 
 >> Exception in thread "main" javax.media.j3d.RestrictedAccessException: Cannot mod
 >> ify capability bits on a live or compiled object
 >> 
 >> ¤È¤¤¤¦Îã³°¤¬½Ð¤Æ¡¢¼Â¹Ô¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¡£
 >
 >¥¨¥é¡¼¤Î½Ð¤Æ¤¤¤ë²Õ½ê¤ÎÁ°¸å¤Î¥½¡¼¥¹¥³¡¼¥É¤¬¸«¤¿¤¤¤Ç¤¹¡£(¿ô¹Ô¤Ç¤«¤Þ¤¤¤Þ¤»¤ó)

ÌäÂê¤Î¥½¡¼¥¹¤Ï¡¢°Ê²¼¤Î¤è¤¦¤Ê¤â¤Î¤Ç¤¹¡£
¾Êά¤·¤Æ¤è¤¤Éôʬ¤¬¤è¤¯Ê¬¤«¤é¤Ê¤¤¤Î¤Ç¡¢
¾ÈÌÀÀßÄꤰ¤é¤¤¤·¤«¾Êά¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£¡Ê¤¹¤¤¤Þ¤»¤ó¡Ë


[ ÀâÌÀ ]
Shoulder¥¯¥é¥¹¤Ë¤Ï¡¢3D¥â¥Ç¥ë¤Î¥í¡¼¥É´ØÏ¢¤Î¥á¥Ã¥½¥É¤È¡¢
MouseMotionEventAdapter¥¯¥é¥¹¤«¤éÊÑ¿ô¡ÊYangle)¤òÊѹ¹
¤Ç¤­¤ë¤è¤¦¤Ë¡¢static´Ø¿ô(Rotation(double angle))¤òºî
¤ê¤Þ¤·¤¿¡£
¡ÊShoulder¥ª¥Ö¥¸¥§¥¯¥È·Ðͳ¤Ç¡¢MouseMotionEventAdapterÆ⤫¤é¡¢
Shoulder¤Î¥í¡¼¥«¥ëÊÑ¿ô¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¡¢Shoulder¥ª¥Ö¥¸¥§¥¯
¥È¤òÀ¸À®¤¹¤ë¤È¼Â¹Ô»þ¤Ë¡¢NullPointerException¤¬½Ð¤Æ¤·¤Þ¤Ã¤¿¤Î
¤Ç¡¢¶ìÆù¤Îºö¤Ç¤³¤¦¤·¤Æ¤ß¤Þ¤·¤¿¡£¡Ë

¤³¤Î¥×¥í¥°¥é¥à¤òñÂΤǵ¯Æ°¤¹¤ëʬ¤Ë¤Ï¡¢Îɤ¤¤Î¤Ç¤¹¤¬¡¢
°Ê²¼¤ÎSym.java¥×¥í¥°¥é¥à¤Ç¡¢BranchGroup¤ËShoulder¥ª
¥Ö¥¸¥§¥¯¥È¤ò¤Ö¤é²¼¤²¤è¤¦¤È¤¹¤ë¤È¡¢¼Â¹Ô»þ¤Ë¾åµ­¤ÎÎã³°
¤¬½Ð¤Æ¤·¤Þ¤¤¤Þ¤¹¡£


¼«Ê¬¤ÎÃæ¤Ç¤Ï¡¢static´Ø¿ô¤¬ÌäÂê¤Ê¤Î¤À¤È»×¤¦¤Î¤Ç¤¹¤¬
»ä¼«¿È¤Î¥×¥í¥°¥é¥ß¥ó¥°¤Î´ðÁÃÍý²ò¤¬¤·¤Ã¤«¤ê¤·¤Æ¤¤¤Ê
¤¤¤¿¤á¡¢ÌÀ³Î¤ÊÌäÂêÅÀ¤¬¤ï¤«¤ê¤Þ¤»¤ó¡£

¼«Ê¬¤Ê¤ê¤Ë¤âÊÙ¶¯¤·¤Æ¤ß¤Þ¤¹¤¬¡¢¥¢¥É¥Ð¥¤¥¹¤ò¤è¤í¤·¤¯¤ª´ê¤¤¤·¤Þ¤¹¡£

---------------------------- Shoulder.java -------------------------------------
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.*;

public class Shoulder extends Applet {
   // 3D¥â¥Ç¥ë¤Î¥é¥ó¥¿¥¤¥à»þ¤Ë°ÌÃÖÊѹ¹¤¹¤ëÍ×ÁǤˤĤ¤¤Æ¤Ï¡¢
   // static¤Ë¤·¤Æ³°Éô¤«¤éľÀÜ¥¢¥¯¥»¥¹¤Ç¤­¤ë¤è¤¦¤Ë¤·¤¿¡£
   public static TransformGroup shoulderTrans = null;	// °À­ÀßÄê
   public static Transform3D shoulderT3d = null;	// ¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖÀßÄê
   public static double Yangle;				// ¥â¥Ç¥ë¤ÎY¼´¼þ¤ê³ÑÅÙ
   public double scale;					// ¥â¥Ç¥ë¤Î½Ì¼Ü
   public Vector3f position = null;			// ¥â¥Ç¥ë¤Î°ÌÃÖ

   private boolean noTriangulate = false;
   private boolean noStripify = false;
   private double creaseAngle = 60.0;
   private Canvas3D canvas = null;
   private String filename = null;

   private MouseMotionEventAdapter mouseMotionEvt= null; //¥Þ¥¦¥¹Æ°Åª¥¤¥Ù¥ó¥ÈÍÑ

   public Shoulder() {
	filename = "shoulder.obj";   // 3D¥â¥Ç¥ë¥Õ¥¡¥¤¥ë̾
	scale = 0.4;
	position = new Vector3f(0.0f,0.0f,0.0f);	
	Yangle = 0.0;

	shoulderTrans = new TransformGroup();
	shoulderT3d = new Transform3D();
	mouseMotionEvt = new MouseMotionEventAdapter();
	
	setLayout(new BorderLayout());
	
	GraphicsConfiguration config =
	   SimpleUniverse.getPreferredConfiguration();
	
	canvas = new Canvas3D(config);
	add("Center", canvas);
		
	// ÉÁ²èÎΰè¤Ë¥Þ¥¦¥¹¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤òÉղ乤ë
	canvas.addMouseMotionListener(mouseMotionEvt);
	
	BranchGroup scene = createShoulder();
	
	SimpleUniverse u = new SimpleUniverse(canvas);
	u.getViewingPlatform().setNominalViewingTransform();
	u.addBranchGraph(scene);
   }
   
   public BranchGroup createShoulder() {
	BranchGroup objRoot = new BranchGroup();

	// ¥ª¥Ö¥¸¥§¥¯¥È°ÌÃÖÀßÄê
	shoulderT3d.setScale(scale);
       	shoulderT3d.setTranslation(position);
	shoulderT3d.rotY(Yangle);
       	shoulderTrans.setTransform(shoulderT3d);
	shoulderTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
	shoulderTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

	// ¥í¡¼¥ÀÍѥե饰ÀßÄê
	int flags = ObjectFile.RESIZE;
	if (!noTriangulate) flags |= ObjectFile.TRIANGULATE;
	if (!noStripify) flags |= ObjectFile.STRIPIFY;

	// ¥í¡¼¥À¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®
	ObjectFile f = new ObjectFile(flags, 
	  (float)(creaseAngle * Math.PI / 180.0));

	Scene s = null;
	try {
		s = f.load(filename);
	}
	catch (FileNotFoundException e) {
		System.err.println(e);
		System.exit(1);
	}
	catch (ParsingErrorException e) {
		System.err.println(e);
		System.exit(1);
	}
	catch (IncorrectFormatException e) {
		System.err.println(e);
		System.exit(1);
	}
	
	// Scene(s)¤òtransformGroup(shoulderTrans)¤Ë¤Ö¤é²¼¤²¤ë
	shoulderTrans.addChild(s.getSceneGroup());
	
	BoundingSphere bounds =
	  new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

	objRoot.addChild(shoulderTrans);
	return objRoot;
   }
   
   public static void setRotation(double angle) {
	Yangle = angle;
//	System.out.println("Yangle=" + Yangle);
	shoulderT3d.rotY(Yangle);
	shoulderTrans.setTransform(shoulderT3d);
   }
   
   public static void main(String[] args) {
	Shoulder s = new Shoulder();
	MainFrame f = new MainFrame(s, 500, 500);
   }
}

class MouseMotionEventAdapter implements MouseMotionListener {
   private int mousePosition;
   private double degree;
   
   public MouseMotionEventAdapter() {
	mousePosition = 0;
	degree = 0.0;
   }

   public void mouseMoved( MouseEvent e) {}

   public void mouseDragged( MouseEvent e) {
	mousePosition = e.getX();
	degree = (double)((mousePosition) * Math.PI / 180.0);
	Shoulder.setRotation(degree);
   }
}
// -------------------- end of Shoulder.java --------------------------

// ------------------------ Sym.java ----------------------------------

import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.io.*;

public class Sym extends Applet {
   private Canvas3D canvas = null;
   private double wholeScale;		// Á´ÂΤν̼Ü

   public Sym() {
	wholeScale = 0.2;
	GraphicsConfiguration config = 
	   SimpleUniverse.getPreferredConfiguration();
	canvas = new Canvas3D(config);

	this.setLayout(new BorderLayout());
	this.add(canvas, "Center");
	
	// ºÇ¾å°Ì¤Î¶õ´ÖÍѥΡ¼¥É
	SimpleUniverse universe = new SimpleUniverse(canvas);

	// universe¤Î»ëÅÀÀßÄê¡£»ëÅÀ¤ò¾¯¤·¸å¤í¤Ë¤º¤é¤·¤Æ¤¤¤ë¤Î¤Ç
	// ¥·¡¼¥óÆâ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¸«¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
	universe.getViewingPlatform().setNominalViewingTransform();
	
	// ¥ª¥Ö¥¸¥§¥¯¥ÈÍѥΡ¼¥É¡Ê»Ò¥Î¡¼¥É¡Ë
	BranchGroup scene = createSceneGraph();

	universe.addBranchGraph(scene);
   }

   public BranchGroup createSceneGraph() {
	// »Þgraph¤Î¥ë¡¼¥È¤òÀ¸À®
	BranchGroup objRoot = new BranchGroup();

        // Á´ÂΤΥ¹¥±¡¼¥ëÀßÄê¡ÊTransformGroup(objScale)¤òÀ¸À®¡Ë
        TransformGroup objScale = new TransformGroup();
        Transform3D t3d = new Transform3D();
        t3d.setScale(wholeScale);
        objScale.setTransform(t3d);
        objRoot.addChild(objScale);

	// ¥Þ¥¦¥¹Æ°ºîÍÑTransformGroup(objTrans)
	// ¥í¥Ü¥Ã¥È¥¢¡¼¥à¤Î¥Ñ¡¼¥Ä¥ª¥Ö¥¸¥§¥¯¥È¤Ï¤³¤Î²¼¤Ë¤Ö¤é²¼¤²¤ë
	TransformGroup objTrans = new TransformGroup();	

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

	// ³Æ¥Ñ¡¼¥Ä¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®
	Shoulder s = new Shoulder();
	BranchGroup shoulder = s.createShoulder();

	// ¥Ñ¡¼¥Ä¥ª¥Ö¥¸¥§¥¯¥È¤ò¿Æ¥Î¡¼¥É(objTrans)¤Ë¤Ö¤é²¼¤²¤ë
	objTrans.addChild(shoulder);

	// ¥Ñ¡¼¥Ä¤Î¿Æ¥Î¡¼¥É¤ò¥¹¥±¡¼¥ëÄ´À°¥°¥é¥Õ(objScale)¤Ë¤Ö¤é²¼¤²¤ë
	objScale.addChild(objTrans);

        // ÇØ·ÊÀßÄê
        Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
        Background bgNode = new Background(bgColor);
        bgNode.setApplicationBounds(bounds);
        objRoot.addChild(bgNode);

	return objRoot;
    }

    private void usage()
    {
    	System.exit(0);
    }
}

// ----------------------- end of Sym.java -------------------------------

----
Kensuke Tanaka  ktanaka@xxxxxxxxxx