GrxShapeItem.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 
11 /*
12  * GrxModelItem.java
13  *
14  * @author Yuichiro Kawasumi (General Robotix, Inc.)
15  * @author Shin'ichiro Nakaoka (AIST)
16  */
17 
18 package com.generalrobotix.ui.item;
19 
20 import java.awt.image.BufferedImage;
21 import java.awt.image.DataBufferByte;
22 import java.awt.image.DataBufferInt;
23 import java.awt.image.DataBufferUShort;
24 import java.util.List;
25 
26 import javax.media.j3d.Appearance;
27 import javax.media.j3d.BranchGroup;
28 import javax.media.j3d.Geometry;
29 import javax.media.j3d.GeometryArray;
30 import javax.media.j3d.ImageComponent;
31 import javax.media.j3d.ImageComponent2D;
32 import javax.media.j3d.Material;
33 import javax.media.j3d.Node;
34 import javax.media.j3d.PolygonAttributes;
35 import javax.media.j3d.QuadArray;
36 import javax.media.j3d.Shape3D;
37 import javax.media.j3d.Switch;
38 import javax.media.j3d.Texture;
39 import javax.media.j3d.Texture2D;
40 import javax.media.j3d.TextureAttributes;
41 import javax.media.j3d.Transform3D;
42 import javax.media.j3d.TransformGroup;
43 import javax.media.j3d.TransparencyAttributes;
44 import javax.vecmath.Color3f;
45 import javax.vecmath.Matrix3d;
46 import javax.vecmath.Matrix4d;
47 import javax.vecmath.Point2f;
48 import javax.vecmath.Point3f;
49 import javax.vecmath.Vector3d;
50 import javax.vecmath.Vector3f;
51 
52 import jp.go.aist.hrp.simulator.AppearanceInfo;
53 import jp.go.aist.hrp.simulator.MaterialInfo;
54 import jp.go.aist.hrp.simulator.SceneInfo;
55 import jp.go.aist.hrp.simulator.ShapeInfo;
56 import jp.go.aist.hrp.simulator.ShapePrimitiveType;
57 import jp.go.aist.hrp.simulator.TextureInfo;
58 import jp.go.aist.hrp.simulator.TransformedShapeIndex;
59 
60 import org.eclipse.jface.action.Action;
61 import org.eclipse.jface.dialogs.InputDialog;
62 import org.eclipse.jface.dialogs.MessageDialog;
63 import org.eclipse.osgi.util.NLS;
64 
69 import com.sun.j3d.utils.geometry.Box;
70 import com.sun.j3d.utils.geometry.Cone;
71 import com.sun.j3d.utils.geometry.Cylinder;
72 import com.sun.j3d.utils.geometry.GeometryInfo;
73 import com.sun.j3d.utils.geometry.NormalGenerator;
74 import com.sun.j3d.utils.geometry.Primitive;
75 import com.sun.j3d.utils.geometry.Sphere;
76 import com.sun.j3d.utils.image.TextureLoader;
77 import com.sun.j3d.utils.picking.PickTool;
78 
79 @SuppressWarnings("serial") //$NON-NLS-1$
83 public class GrxShapeItem extends GrxShapeTransformItem{
84  public boolean isInline_ = false;
85  public ShapeInfo[] shapes_;
86  public AppearanceInfo[] appearances_;
87  public MaterialInfo[] materials_;
88  public TextureInfo[] textures_;
89  //public double transform_;
90  private int primitiveFlag = Primitive.GEOMETRY_NOT_SHARED | Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS;
91  private Appearance appearance_=null;
92  private BranchGroup bg_;
93 
104  public GrxShapeItem(String name, GrxPluginManager manager, GrxModelItem model){
105  super(name, manager, model);
106  bg_ = new BranchGroup();
107  bg_.setCapability(BranchGroup.ALLOW_DETACH);
108  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
109  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
110 
111  }
112 
113  public void loadShape(Matrix4d shapeT, int index, Matrix4d segmentT) {
114  GrxModelItem model = model();
115 
116  shapes_ = new ShapeInfo[1];
117  appearances_ = new AppearanceInfo[1];
118  materials_ = new MaterialInfo[1];
119  textures_ = new TextureInfo[1];
120 
121  Matrix4d invSegmentT = new Matrix4d();
122  invSegmentT.invert(segmentT);
123  Matrix4d shapeT0 = new Matrix4d();
124  shapeT0.mul(invSegmentT, shapeT);
125  Transform3D t3d = new Transform3D(shapeT0);
126 
127  setShapeInfofromModel((short) index, 0);
128  Shape3D shape3d = createShape3D(shapes_[0], appearances_[0], materials_[0], textures_[0]);
129  bg_.addChild(shape3d);
130  tg_.addChild(bg_);
131  setPrimitiveProperty(model.shapes[index]);
132 
133  tg_.setTransform(t3d);
134  setURL(model.shapes[index].url);
135 
136  initialize(t3d);
137 
138  }
139 
140  public void createnewPrimitiveShape(int type){
141  shapes_ = new ShapeInfo[1];
142  shapes_[0] = new ShapeInfo();
143  appearances_ = new AppearanceInfo[1];
144  appearances_[0] = new AppearanceInfo();
145  materials_ = new MaterialInfo[1];
146  materials_[0] = new MaterialInfo();
147  textures_ = new TextureInfo[1];
148  textures_[0] = null;
149 
150  Appearance appearance = createAppearance();
151  materials_[0].diffuseColor = new float[3];
152  materials_[0].diffuseColor[0] = materials_[0].diffuseColor[1] = materials_[0].diffuseColor[2] =0.8f;
153  materials_[0].emissiveColor = new float[3];
154  materials_[0].emissiveColor[0] = materials_[0].emissiveColor[1] = materials_[0].emissiveColor[2] =0.0f;
155  materials_[0].specularColor = new float[3];
156  materials_[0].specularColor[0] = materials_[0].specularColor[1] = materials_[0].specularColor[2] =0.0f;
157  materials_[0].ambientIntensity = 0.2f;
158  materials_[0].shininess = 0.2f;
159  materials_[0].transparency = 0.0f;
160  setMaterial(appearance, materials_[0]);
161  appearance_ = appearance;
162 
163  Primitive primitive=null;
164  switch(type){
165  case ShapePrimitiveType._SP_BOX :
166  float[] size=new float[3];
167  size[0] = size[1] = size[2] = 1.0f;
168  primitive = new Box(size[0]/2, size[1]/2, size[2]/2, primitiveFlag, appearance);
169  shapes_[0].primitiveType = ShapePrimitiveType.SP_BOX;
170  shapes_[0].primitiveParameters = size;
171  setFltAry("size", size); //$NON-NLS-1$
172  break;
173  case ShapePrimitiveType._SP_CONE :
174  float bottomRadius = 1.0f;
175  float height = 2.0f;
176  primitive = new Cone(bottomRadius, height, primitiveFlag, appearance);
177  shapes_[0].primitiveType = ShapePrimitiveType.SP_CONE;
178  float[] param = new float[4];
179  param[0] = bottomRadius;
180  param[1] = height;
181  param[2] = 1;
182  param[3] = 1;
183  shapes_[0].primitiveParameters = param;
184  setFlt("bottomRadius", bottomRadius); //$NON-NLS-1$
185  setFlt("height", height); //$NON-NLS-1$
186  setProperty("side","true"); //$NON-NLS-1$ //$NON-NLS-2$
187  setProperty("bottom","true"); //$NON-NLS-1$ //$NON-NLS-2$
188  break;
189  case ShapePrimitiveType._SP_CYLINDER :
190  float radius = 1.0f;
191  height = 2.0f;
192  primitive = new Cylinder(radius, height, primitiveFlag, appearance);
193  shapes_[0].primitiveType = ShapePrimitiveType.SP_CYLINDER;
194  param = new float[5];
195  param[0] = radius;
196  param[1] = height;
197  param[2] = 1;
198  param[3] = 1;
199  param[4] = 1;
200  shapes_[0].primitiveParameters = param;
201  setFlt("radius", radius); //$NON-NLS-1$
202  setFlt("height", height); //$NON-NLS-1$
203  setProperty("side","true"); //$NON-NLS-1$ //$NON-NLS-2$
204  setProperty("bottom","true"); //$NON-NLS-1$ //$NON-NLS-2$
205  setProperty("top","true"); //$NON-NLS-1$ //$NON-NLS-2$
206  break;
207  case ShapePrimitiveType._SP_SPHERE :
208  radius = 1.0f;
209  primitive = new Sphere(radius, primitiveFlag, appearance);
210  shapes_[0].primitiveType = ShapePrimitiveType.SP_SPHERE;
211  param = new float[1];
212  param[0] = radius;
213  shapes_[0].primitiveParameters = param;
214  setFlt("radius", radius); //$NON-NLS-1$
215  break;
216  default :
217  break;
218  }
219  bg_.addChild(primitive);
220  Transform3D t3d = new Transform3D();
221  tg_.setTransform(t3d);
222  tg_.addChild(bg_);
223 
224  initialize(t3d);
225  setFltAry("diffuseColor", materials_[0].diffuseColor); //$NON-NLS-1$
226  }
227 
228  public void loadInlineShape(Matrix4d[] shapeT, Matrix4d inlinedT, int[] index, Matrix4d segmentT){
229  isInline_ = true;
230  int n = index.length;
231  shapes_ = new ShapeInfo[n];
232  appearances_ = new AppearanceInfo[n];
233  materials_ = new MaterialInfo[n];
234  textures_ = new TextureInfo[n];
235  for(int i=0; i<n; i++){
236  setShapeInfofromModel((short) index[i], i);
237  }
238 
239  setShape(shapeT, inlinedT, n, segmentT);
240  setURL(model().shapes[index[0]].url);
241  }
242 
243  private void setShape(Matrix4d[] shapeT, Matrix4d inlinedT, int n, Matrix4d segmentT){
244  Matrix4d invertIT = new Matrix4d();
245  invertIT.invert(inlinedT);
246  for(int i=0; i<n; i++){
247  TransformGroup tfg = new TransformGroup();
248  Matrix4d shapeT0 = new Matrix4d();
249  shapeT0.mul(invertIT, shapeT[i]);
250  Transform3D transform3d = new Transform3D(shapeT0);
251  tfg.setTransform(transform3d);
252 
253  Shape3D linkShape3D = createShape3D(shapes_[i], appearances_[i], materials_[i], textures_[i]);
254  tfg.addChild(linkShape3D);
255  tg_.addChild(tfg);
256  }
257  Matrix4d invSegmentT = new Matrix4d();
258  invSegmentT.invert(segmentT);
259  Matrix4d inlinedT0 = new Matrix4d();
260  inlinedT0.mul(invSegmentT, inlinedT);
261  Transform3D t3d = new Transform3D(inlinedT0);
262  tg_.setTransform(t3d);
263 
264  initialize(t3d);
265  }
266 
267  public void loadnewInlineShape(SceneInfo sInfo){
268  isInline_ = true;
269  ShapeInfo[] shapes = sInfo.shapes();
270  AppearanceInfo[] appearances = sInfo.appearances();
271  MaterialInfo[] materials = sInfo.materials();
272  TextureInfo[] textures = sInfo.textures();
273 
274  TransformedShapeIndex[] tsi = sInfo.shapeIndices();
275  int n = tsi.length;
276  shapes_ = new ShapeInfo[n];
277  appearances_ = new AppearanceInfo[n];
278  materials_ = new MaterialInfo[n];
279  textures_ = new TextureInfo[n];
280  Matrix4d[] shapeT = new Matrix4d[n];
281  for(int k=0; k<n; k++){
282  ShapeInfo shapeInfo = shapes[tsi[k].shapeIndex];
283  AppearanceInfo appearanceInfo = null;
284  MaterialInfo materialInfo = null;
285  TextureInfo textureInfo = null;
286  if (shapeInfo.appearanceIndex >= 0){
287  appearanceInfo = appearances[shapeInfo.appearanceIndex];
288  if (appearanceInfo.materialIndex >= 0){
289  materialInfo = materials[appearanceInfo.materialIndex];
290  }
291  if (appearanceInfo.textureIndex >= 0){
292  textureInfo = textures[appearanceInfo.textureIndex];
293  }
294  }
295  shapes_[k] = shapeInfo;
296  appearances_[k] = appearanceInfo;
297  materials_[k] = materialInfo;
298  textures_[k] = textureInfo;
299  double[] m = tsi[k].transformMatrix;
300  shapeT[k] = new Matrix4d(m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7],m[8],m[9],m[10],m[11],0,0,0,1);
301  }
302  setShape(shapeT, new Matrix4d(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1), n, new Matrix4d(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1));
303  }
304 
305  protected void initialize(Transform3D t3d){
306  Vector3d trans = new Vector3d();
307  Matrix3d rotat = new Matrix3d();
308  t3d.get(rotat, trans);
309 
310  double [] pos = new double[3];
311  trans.get(pos);
312  translation(pos);
313  AxisAngle4d a4d = new AxisAngle4d();
314  rotat.normalize();
315  a4d.setMatrix(rotat);
316  double [] rot = new double[4];
317  a4d.get(rot);
318  rotation(rot);
319 
320  resizeBoundingBox();
321  getMenu().clear();
322 
323  Action item;
324 
325  // rename
326  item = new Action(){
327  public String getText(){
328  return MessageBundle.get("GrxShapeItem.menu.rename"); //$NON-NLS-1$
329  }
330  public void run(){
331  InputDialog dialog = new InputDialog( null, getText(),
332  MessageBundle.get("GrxShapeItem.dialog.message.newName"), getName(),null); //$NON-NLS-1$
333  if ( dialog.open() == InputDialog.OK && dialog.getValue() != null)
334  rename( dialog.getValue() );
335  }
336  };
337  setMenuItem(item);
338 
339  // delete
340  item = new Action(){
341  public String getText(){
342  return MessageBundle.get("GrxShapeItem.menu.delete"); //$NON-NLS-1$
343  }
344  public void run(){
345  String mes = MessageBundle.get("GrxShapeItem.dialog.message.delete"); //$NON-NLS-1$
346  mes = NLS.bind(mes, new String[]{getName()});
347 
348  if( MessageDialog.openQuestion( null, MessageBundle.get("GrxShapeItem.dialog.title.delete"), //$NON-NLS-1$
349  mes) ){
350  delete();
351  }
352 
353  }
354  };
355  setMenuItem(item);
356 
357  /* disable copy and paste menus until they are implemented
358  // menu item : copy
359  item = new Action(){
360  public String getText(){
361  return "copy";
362  }
363  public void run(){
364  GrxDebugUtil.println("GrxModelItem.GrxShapeItem copy Action");
365  manager_.setSelectedGrxBaseItemList();
366  }
367  };
368  setMenuItem(item);
369 
370  // menu item : paste
371  item = new Action(){
372  public String getText(){
373  return "paste";
374  }
375  public void run(){
376  }
377  };
378  setMenuItem(item);
379  */
380 
381  setIcon("segment.png"); //$NON-NLS-1$
382  }
383 
384  protected Appearance createAppearance(){
385  Appearance appearance = new Appearance();
386  appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
387  appearance.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
388  appearance.setCapability(Appearance.ALLOW_MATERIAL_READ);
389  appearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
390 
391  PolygonAttributes pa = new PolygonAttributes();
392  pa.setCapability(PolygonAttributes.ALLOW_MODE_READ);
393  pa.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
394  pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
395  pa.setCullFace(PolygonAttributes.CULL_NONE);
396  pa.setBackFaceNormalFlip(true);
397  appearance.setPolygonAttributes(pa);
398 
399  return appearance;
400  }
401 
402  private void setShapeInfofromModel(short shapeIndex, int id){
403  ShapeInfo shapeInfo = model().shapes[shapeIndex];
404  AppearanceInfo appearanceInfo = null;
405  MaterialInfo materialInfo = null;
406  TextureInfo textureInfo = null;
407  if (shapeInfo.appearanceIndex >= 0){
408  appearanceInfo = model().appearances[shapeInfo.appearanceIndex];
409  if (appearanceInfo.materialIndex >= 0){
410  materialInfo = model().materials[appearanceInfo.materialIndex];
411  }
412  if (appearanceInfo.textureIndex >= 0){
413  textureInfo = model().textures[appearanceInfo.textureIndex];
414  }
415  }
416  shapes_[id] = shapeInfo;
417  appearances_[id] = appearanceInfo;
418  materials_[id] = materialInfo;
419  textures_[id] = textureInfo;
420  }
421 
430  @SuppressWarnings("deprecation") //$NON-NLS-1$
431  private Shape3D createShape3D
432  (ShapeInfo shapeInfo, AppearanceInfo appearanceInfo, MaterialInfo materialInfo, TextureInfo textureInfo){
433 
434  GeometryInfo geometryInfo = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
435 
436  // set vertices
437  int numVertices = shapeInfo.vertices.length / 3;
438  Point3f[] vertices = new Point3f[numVertices];
439  for(int i=0; i < numVertices; ++i){
440  vertices[i] = new Point3f(shapeInfo.vertices[i*3], shapeInfo.vertices[i*3+1], shapeInfo.vertices[i*3+2]);
441  }
442  geometryInfo.setCoordinates(vertices);
443  geometryInfo.setCoordinateIndices(shapeInfo.triangles);
444 
445  Appearance appearance = createAppearance();
446  if (appearanceInfo != null){
447  setColors(geometryInfo, shapeInfo, appearanceInfo);
448  setNormals(geometryInfo, shapeInfo, appearanceInfo);
449  if(appearanceInfo.solid){
450  PolygonAttributes pa = appearance.getPolygonAttributes();
451  pa.setCullFace(PolygonAttributes.CULL_BACK);
452  appearance.setPolygonAttributes(pa);
453  }
454 
455  if(materialInfo != null)
456  setMaterial( appearance, materialInfo);
457 
458  if(textureInfo != null){
459  setTexture( appearance, textureInfo);
460 
461 
462  int numTexCoordinate = appearanceInfo.textureCoordinate.length / 2;
463  Point2f[] texCoordinate = new Point2f[numTexCoordinate];
464  for(int i=0, j=0; i<numTexCoordinate; i++)
465  texCoordinate[i] = new Point2f( appearanceInfo.textureCoordinate[j++], appearanceInfo.textureCoordinate[j++] );
466 
467  geometryInfo.setTextureCoordinates(texCoordinate);
468  geometryInfo.setTextureCoordinateIndices(appearanceInfo.textureCoordIndices);
469  }
470  }
471 
472  Shape3D shape3D = new Shape3D(geometryInfo.getGeometryArray());
473  shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
474  shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
475  shape3D.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
476  shape3D.setCapability(GeometryArray.ALLOW_COUNT_READ);
477  PickTool.setCapabilities(shape3D, PickTool.INTERSECT_FULL);
478  appearance_ = appearance;
479  shape3D.setAppearance(appearance);
480 
481  return shape3D;
482  }
483 /*
484  private Primitive createPrimitive
485  (ShapeInfo shapeInfo, AppearanceInfo appearanceInfo, MaterialInfo materialInfo, TextureInfo textureInfo){
486 
487  Appearance appearance = createAppearance();
488  if(appearanceInfo != null){
489  if(materialInfo != null)
490  setMaterial( appearance, materialInfo);
491  if(textureInfo != null){
492  setTexture( appearance, textureInfo);
493  TextureAttributes texAttrBase = new TextureAttributes();
494  Transform3D t3d = new Transform3D(new Matrix4d(
495  appearanceInfo.textransformMatrix[0], appearanceInfo.textransformMatrix[1], appearanceInfo.textransformMatrix[2], 0,
496  appearanceInfo.textransformMatrix[3], appearanceInfo.textransformMatrix[4], appearanceInfo.textransformMatrix[5], 0,
497  0, 0, 1, 0,
498  0, 0, 0, 1 ));
499 
500  //System.out.println(t3d.toString());
501  texAttrBase.setTextureTransform(t3d);
502  appearance.setTextureAttributes(texAttrBase);
503  }
504  }
505 
506  int flag = Primitive.GEOMETRY_NOT_SHARED | Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS | Primitive.ENABLE_GEOMETRY_PICKING;
507  if(shapeInfo.primitiveType == ShapePrimitiveType.SP_BOX || shapeInfo.primitiveType == ShapePrimitiveType.SP_PLANE){
508  Box box = new Box((float)(shapeInfo.primitiveParameters[0]/2.0), (float)(shapeInfo.primitiveParameters[1]/2.0),
509  (float)(shapeInfo.primitiveParameters[2]/2.0), flag, appearance );
510  return box;
511  }else if( shapeInfo.primitiveType == ShapePrimitiveType.SP_CYLINDER ){
512  Cylinder cylinder = new Cylinder(shapeInfo.primitiveParameters[0], shapeInfo.primitiveParameters[1],
513  flag, appearance );
514  if((int)shapeInfo.primitiveParameters[2]==0) //TOP
515  cylinder.removeChild(cylinder.getShape(Cylinder.TOP));
516  if((int)shapeInfo.primitiveParameters[3]==0) //BOTTOM
517  cylinder.removeChild(cylinder.getShape(Cylinder.BOTTOM));
518  if((int)shapeInfo.primitiveParameters[4]==0) //SIDE
519  cylinder.removeChild(cylinder.getShape(Cylinder.BODY));
520  return cylinder;
521  }else if( shapeInfo.primitiveType == ShapePrimitiveType.SP_CONE ){
522  Cone cone = new Cone(shapeInfo.primitiveParameters[0], shapeInfo.primitiveParameters[1],
523  flag, appearance );
524  if((int)shapeInfo.primitiveParameters[2]==0) //BOTTOM
525  cone.removeChild(cone.getShape(Cone.CAP));
526  if((int)shapeInfo.primitiveParameters[3]==0) //SIDE
527  cone.removeChild(cone.getShape(Cone.BODY));
528  return cone;
529  }else if( shapeInfo.primitiveType == ShapePrimitiveType.SP_SPHERE ){
530  Sphere sphere = new Sphere(shapeInfo.primitiveParameters[0], flag, appearance );
531  return sphere;
532  }
533 
534  return null;
535  }
536 */
537  protected void setMaterial(Appearance appearance, MaterialInfo materialInfo){
538  if(materialInfo.transparency > 0.0f){
539  TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, materialInfo.transparency);
540  ta.setCapability(TransparencyAttributes.ALLOW_MODE_READ);
541  ta.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
542  ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
543  ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
544  appearance.setTransparencyAttributes(ta);
545  }
546  if(materialInfo != null){
547  appearance.setMaterial(createMaterial(materialInfo));
548  }
549  }
550 
551  protected void setTexture( Appearance appearance, TextureInfo textureInfo ){
552  TextureInfoLocal texInfo = new TextureInfoLocal(textureInfo);
553  if((texInfo.width != 0) && (texInfo.height != 0)){
554  ImageComponent2D icomp2d = texInfo.readImage;
555  Texture2D texture2d=null;
556  switch (texInfo.numComponents) {
557  case 1:
558  texture2d = new Texture2D(Texture.BASE_LEVEL, Texture.LUMINANCE, texInfo.width, texInfo.height);
559  break;
560  case 2:
561  texture2d = new Texture2D(Texture.BASE_LEVEL, Texture.LUMINANCE_ALPHA, texInfo.width, texInfo.height);
562  appearance.setTransparencyAttributes( new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));
563  break;
564  case 3:
565  texture2d = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, texInfo.width, texInfo.height);
566  break;
567  case 4:
568  texture2d = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, texInfo.width, texInfo.height);
569  appearance.setTransparencyAttributes( new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));
570  break;
571  }
572  texture2d.setImage(0, icomp2d);
573  appearance.setTexture(texture2d);
574  }else{
575  if(!texInfo.url.equals("")){ //$NON-NLS-1$
576  try{
577  TextureLoader tloader = new TextureLoader(texInfo.url, null);
578  Texture texture = tloader.getTexture();
579  appearance.setTexture(texture);
580  }catch(Exception ex){
581  System.out.println(ex+" "+texInfo.url); //$NON-NLS-1$
582  }
583  }
584  }
585  TextureAttributes texAttrBase = new TextureAttributes();
586  texAttrBase.setTextureMode(TextureAttributes.REPLACE);
587  appearance.setTextureAttributes(texAttrBase);
588  }
589 
590 
591  protected Material createMaterial(MaterialInfo materialInfo){
592 
593  Material material = new Material();
594 
595  float[] dColor = materialInfo.diffuseColor;
596  material.setDiffuseColor(new Color3f(dColor[0], dColor[1], dColor[2]));
597 
598  float[] sColor = materialInfo.specularColor;
599  material.setSpecularColor(new Color3f(sColor[0], sColor[1], sColor[2]));
600 
601  float[] eColor = materialInfo.emissiveColor;
602  material.setEmissiveColor(new Color3f(eColor[0], eColor[1], eColor[2]));
603 
604  float r = materialInfo.ambientIntensity;
605  material.setAmbientColor(new Color3f(r * dColor[0], r * dColor[1], r * dColor[2]));
606 
607  float shininess = materialInfo.shininess * 127.0f + 1.0f;
608  material.setShininess(shininess);
609 
610  material.setCapability(Material.ALLOW_COMPONENT_READ);
611  material.setCapability(Material.ALLOW_COMPONENT_WRITE);
612 
613  return material;
614  }
615 
616  private void setColors(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo) {
617 
618  int numColors = appearanceInfo.colors.length / 3;
619 
620  if(numColors > 0){
621  float[] orgColors = appearanceInfo.colors;
622  Color3f[] colors = new Color3f[numColors];
623  for(int i=0; i < numColors; ++i){
624  colors[i] = new Color3f(orgColors[i*3], orgColors[i*3+1], orgColors[i*3+2]);
625  }
626  geometryInfo.setColors(colors);
627 
628  int[] orgColorIndices = appearanceInfo.colorIndices;
629  int numOrgColorIndices = orgColorIndices.length;
630  int numTriangles = shapeInfo.triangles.length / 3;
631  int[] colorIndices = new int[numTriangles * 3];
632 
633  if(numOrgColorIndices > 0){
634  if(appearanceInfo.colorPerVertex){
635  colorIndices = orgColorIndices;
636  } else {
637  int pos = 0;
638  for(int i=0; i < numTriangles; ++i){
639  int colorIndex = orgColorIndices[i];
640  for(int j=0; j < 3; ++j){
641  colorIndices[pos++] = colorIndex;
642  }
643  }
644  }
645  } else {
646  if(appearanceInfo.colorPerVertex){
647  for(int i=0; i < colorIndices.length; ++i){
648  colorIndices[i] = shapeInfo.triangles[i];
649  }
650  } else {
651  int pos = 0;
652  for(int i=0; i < numTriangles; ++i){
653  for(int j=0; j < 3; ++j){
654  colorIndices[pos++] = i;
655  }
656  }
657 
658  }
659  }
660  geometryInfo.setColorIndices(colorIndices);
661  }
662  }
663 
664 
665  private void setNormals(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo) {
666 
667  int numNormals = appearanceInfo.normals.length / 3;
668 
669  if(numNormals == 0){
670  NormalGenerator ng = new NormalGenerator(appearanceInfo.creaseAngle);
671  ng.generateNormals(geometryInfo);
672 
673  } else {
674 
675  float[] orgNormals = appearanceInfo.normals;
676  Vector3f[] normals = new Vector3f[numNormals];
677  for(int i=0; i < numNormals; ++i){
678  normals[i] = new Vector3f(orgNormals[i*3], orgNormals[i*3+1], orgNormals[i*3+2]);
679  }
680  geometryInfo.setNormals(normals);
681 
682  int[] orgNormalIndices = appearanceInfo.normalIndices;
683  int numOrgNormalIndices = orgNormalIndices.length;
684  int numTriangles = shapeInfo.triangles.length / 3;
685  int[] normalIndices = new int[numTriangles * 3];
686 
687  if(numOrgNormalIndices > 0){
688  if(appearanceInfo.normalPerVertex){
689  normalIndices = orgNormalIndices;
690  } else {
691  int pos = 0;
692  for(int i=0; i < numTriangles; ++i){
693  int normalIndex = orgNormalIndices[i];
694  for(int j=0; j < 3; ++j){
695  normalIndices[pos++] = normalIndex;
696  }
697  }
698  }
699  } else {
700  if(appearanceInfo.normalPerVertex){
701  for(int i=0; i < normalIndices.length; ++i){
702  normalIndices[i] = shapeInfo.triangles[i];
703  }
704  } else {
705  int pos = 0;
706  for(int i=0; i < numTriangles; ++i){
707  for(int j=0; j < 3; ++j){
708  normalIndices[pos++] = i;
709  }
710  }
711 
712  }
713  }
714 
715  geometryInfo.setNormalIndices(normalIndices);
716  }
717  }
718 
719 
726  public boolean propertyChanged(String property, String value) {
727  if (super.propertyChanged(property, value)){
728  }else if(property.equals("translation")){ //$NON-NLS-1$
729  translation(value);
730  }else if(property.equals("rotation")){ //$NON-NLS-1$
731  rotation(value);
732  }else if(property.equals("size")){ //$NON-NLS-1$
733  size(value);
734  }else if(property.equals("bottomRadius") || property.equals("height") || property.equals("radius") || //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
735  property.equals("side") || property.equals("bottom") || property.equals("top")){ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
736  if(shapes_[0].primitiveType==ShapePrimitiveType.SP_CONE){
737  coneSize(property, value);
738  }else if(shapes_[0].primitiveType==ShapePrimitiveType.SP_CYLINDER){
739  cylinderSize(property, value);
740  }else{
741  sphereSize(value);
742  }
743  }else if(property.equals("diffuseColor")){ //$NON-NLS-1$
744  diffuseColor(value);
745  }else
746  return false;
747  return true;
748  }
749 
750  private void size(float[] newSize){
751  if (newSize != null && newSize.length == 3){
752  setFltAry("size", newSize); //$NON-NLS-1$
753  tg_.removeChild(bg_);
754  bg_ = new BranchGroup();
755  bg_.setCapability(BranchGroup.ALLOW_DETACH);
756  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
757  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
758  Primitive primitive = new Box(newSize[0]/2, newSize[1]/2, newSize[2]/2, primitiveFlag, appearance_);
759  bg_.addChild(primitive);
760  tg_.addChild(bg_);
761  resizeBoundingBox();
762  if (model_ != null) model_.notifyModified();
763  shapes_[0].primitiveParameters = newSize;
764  }
765  }
766 
767  public void size(String size){
768  float[] newSize = getFltAry(size);
769  size(newSize);
770  }
771 
772  public void coneSize(String property, String size){
773  float bottomRadius = getFlt("bottomRadius", 0.0f); //$NON-NLS-1$
774  float height = getFlt("height", 0.0f); //$NON-NLS-1$
775  boolean side = isTrue("side"); //$NON-NLS-1$
776  boolean bottom = isTrue("bottom"); //$NON-NLS-1$
777  if(property.equals("bottomRadius")){ //$NON-NLS-1$
778  float newsize = getFlt(size);
779  setFlt(property, newsize );
780  bottomRadius = newsize;
781  }else if(property.equals("height")){ //$NON-NLS-1$
782  float newsize = getFlt(size);
783  setFlt(property, newsize );
784  height = newsize;
785  }else if(property.equals("side")){ //$NON-NLS-1$
786  boolean flg = size.equals("true"); //$NON-NLS-1$
787  setBool(property, flg);
788  side = flg;
789  }else if(property.equals("bottom")){ //$NON-NLS-1$
790  boolean flg = size.equals("true"); //$NON-NLS-1$
791  setBool(property, flg);
792  bottom = flg;
793  }
794  tg_.removeChild(bg_);
795  bg_ = new BranchGroup();
796  bg_.setCapability(BranchGroup.ALLOW_DETACH);
797  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
798  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
799  Primitive primitive = new Cone( bottomRadius, height, primitiveFlag, appearance_);
800  if(!bottom)
801  primitive.removeChild(primitive.getShape(Cone.CAP));
802  if(!side)
803  primitive.removeChild(primitive.getShape(Cone.BODY));
804  bg_.addChild(primitive);
805  tg_.addChild(bg_);
806  resizeBoundingBox();
807  if (model_ != null) model_.notifyModified();
808  float[] param = new float[4];
809  param[0] = bottomRadius;
810  param[1] = height;
811  param[2] = bottom ? 1: 0;
812  param[3] = side? 1 : 0;
813  shapes_[0].primitiveParameters = param;
814  }
815 
816  public void cylinderSize(String property, String size){
817  float radius = getFlt("radius", 0.0f); //$NON-NLS-1$
818  float height = getFlt("height", 0.0f); //$NON-NLS-1$
819  boolean side = isTrue("side"); //$NON-NLS-1$
820  boolean bottom = isTrue("bottom"); //$NON-NLS-1$
821  boolean top = isTrue("top"); //$NON-NLS-1$
822  if(property.equals("radius")){ //$NON-NLS-1$
823  float newsize = getFlt(size);
824  setFlt(property, newsize );
825  radius = newsize;
826  }else if(property.equals("height")){ //$NON-NLS-1$
827  float newsize = getFlt(size);
828  setFlt(property, newsize );
829  height = newsize;
830  }else if(property.equals("side")){ //$NON-NLS-1$
831  boolean flg = size.equals("true"); //$NON-NLS-1$
832  setBool(property, flg);
833  side = flg;
834  }else if(property.equals("bottom")){ //$NON-NLS-1$
835  boolean flg = size.equals("true"); //$NON-NLS-1$
836  setBool(property, flg);
837  bottom = flg;
838  }else if(property.equals("top")){ //$NON-NLS-1$
839  boolean flg = size.equals("true"); //$NON-NLS-1$
840  setBool(property, flg);
841  top = flg;
842  }
843 
844  tg_.removeChild(bg_);
845  bg_ = new BranchGroup();
846  bg_.setCapability(BranchGroup.ALLOW_DETACH);
847  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
848  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
849  Primitive primitive = new Cylinder( radius, height, primitiveFlag, appearance_);
850  bg_.addChild(primitive);
851  if(!bottom)
852  primitive.removeChild(primitive.getShape(Cylinder.BOTTOM));
853  if(!top)
854  primitive.removeChild(primitive.getShape(Cylinder.TOP));
855  if(!side)
856  primitive.removeChild(primitive.getShape(Cylinder.BODY));
857  tg_.addChild(bg_);
858  resizeBoundingBox();
859  if (model_ != null) model_.notifyModified();
860  float[] param = new float[5];
861  param[0] = radius;
862  param[1] = height;
863  param[2] = top ? 1 : 0;
864  param[3] = bottom? 1 : 0;
865  param[4] = side? 1 : 0;
866  shapes_[0].primitiveParameters = param;
867  }
868 
869  private void sphereSize(float[] newSize){
870  if (newSize != null && newSize.length == 1){
871  setFlt("radius", newSize[0]); //$NON-NLS-1$
872  tg_.removeChild(bg_);
873  bg_ = new BranchGroup();
874  bg_.setCapability(BranchGroup.ALLOW_DETACH);
875  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
876  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
877  Primitive primitive = new Sphere(newSize[0], primitiveFlag, appearance_);
878  bg_.addChild(primitive);
879  tg_.addChild(bg_);
880  resizeBoundingBox();
881  if (model_ != null) model_.notifyModified();
882  shapes_[0].primitiveParameters = newSize;
883  }
884  }
885 
886  public void sphereSize(String size){
887  float[] newSize = getFltAry(size);
888  sphereSize(newSize);
889  }
890 
891  void diffuseColor(float[] newValue){
892  if (newValue != null && newValue.length == 3){
893  setFltAry("diffuseColor", newValue); //$NON-NLS-1$
894  materials_[0].diffuseColor = newValue;
895  setMaterial(appearance_, materials_[0]);
896  if (model_ != null) model_.notifyModified();
897  }
898  }
899 
900  void diffuseColor(String value){
901  float[] newValue = getFltAry(value);
902  diffuseColor(newValue);
903  }
904 
905  public class TextureInfoLocal
906  {
907  public short numComponents;
908  public short width;
909  public short height;
910  public boolean repeatS;
911  public boolean repeatT;
912  public ImageComponent2D readImage;
913  String url;
914 
915  public TextureInfoLocal(TextureInfo texinfo) {
916  width = texinfo.width;
917  height = texinfo.height;
918  numComponents = texinfo.numComponents;
919  //System.out.println("numComponents= " + numComponents);
920  repeatS = texinfo.repeatS;
921  repeatT = texinfo.repeatT;
922  url = texinfo.url;
923 
924  if((width == 0) || (height == 0)){
925  numComponents = 3;
926  repeatS = false;
927  repeatT = false;
928  width = 0;
929  height = 0;
930  return;
931  }
932 
933  //width and height must be power of 2
934  short w=1;
935  do{
936  w *=2;
937  }while(w<=width);
938  short width_new = (short)(w);
939  if(width_new-width > width-width_new/2)
940  width_new /=2;
941  w=1;
942  do{
943  w *=2;
944  }while(w<=height);
945  short height_new = (short)(w);
946  if(height_new-height > height-height_new/2)
947  height_new /=2;
948 
949 
950  BufferedImage bimageRead=null;
951  switch(numComponents){
952  case 1:
953  bimageRead = new BufferedImage(width_new, height_new, BufferedImage.TYPE_BYTE_GRAY);
954  byte[] bytepixels = ( ( DataBufferByte)bimageRead.getRaster().getDataBuffer() ).getData();
955  for(int i=0; i<height_new; i++){
956  for(int j=0; j<width_new; j++){
957  int k = (int)(i*height/height_new)*width+(int)(j*width/width_new);
958  bytepixels[i*width_new+j] = texinfo.image[k];
959  }
960  }
961  break;
962  case 2:
963  bimageRead = new BufferedImage(width_new, height_new, BufferedImage.TYPE_USHORT_GRAY);
964  short[] shortpixels = ( ( DataBufferUShort)bimageRead.getRaster().getDataBuffer() ).getData();
965  for(int i=0; i<height_new; i++){
966  for(int j=0; j<width_new; j++){
967  int k = (int)(i*height/height_new)*width*2+(int)(j*width/width_new)*2;
968  short l = texinfo.image[k];
969  short a = texinfo.image[k+1];
970  shortpixels[i*width_new+j] = (short)((l&0xff) << 8 | (a&0xff)) ;
971  }
972  }
973  break;
974  case 3:
975  bimageRead = new BufferedImage(width_new, height_new, BufferedImage.TYPE_INT_RGB);
976  int[] intpixels = ( (DataBufferInt)bimageRead.getRaster().getDataBuffer() ).getData();
977  for(int i=0; i<height_new; i++){
978  for(int j=0; j<width_new; j++){
979  int k = (int)(i*height/height_new)*width*3+(int)(j*width/width_new)*3;
980  short r = texinfo.image[k];
981  short g = texinfo.image[k+1];
982  short b = texinfo.image[k+2];
983  intpixels[i*width_new+j] = (r&0xff) << 16 | (g&0xff) << 8 | (b&0xff);
984  }
985  }
986  break;
987  case 4:
988  bimageRead = new BufferedImage(width_new, height_new, BufferedImage.TYPE_INT_ARGB);
989  intpixels = ( (DataBufferInt)bimageRead.getRaster().getDataBuffer() ).getData();
990  for(int i=0; i<height_new; i++){
991  for(int j=0; j<width_new; j++){
992  int k = (int)(i*height/height_new)*width*4+(int)(j*width/width_new)*4;
993  short r = texinfo.image[k];
994  short g = texinfo.image[k+1];
995  short b = texinfo.image[k+2];
996  short a = texinfo.image[k+3];
997  intpixels[i*width_new+j] = (a&0xff) << 24 | (r&0xff) << 16 | (g&0xff) << 8 | (b&0xff);
998  }
999  }
1000  break;
1001  }
1002  height = height_new;
1003  width = width_new;
1004 
1005  switch(numComponents){
1006  case 1:
1007  readImage = new ImageComponent2D(ImageComponent.FORMAT_CHANNEL8, bimageRead);
1008  break;
1009  case 2:
1010  readImage = new ImageComponent2D(ImageComponent.FORMAT_LUM8_ALPHA8, bimageRead);
1011  break;
1012  case 3:
1013  readImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimageRead);
1014  break;
1015  case 4:
1016  readImage = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bimageRead);
1017  break;
1018  }
1019 
1020  }
1021  }
1022 
1028  GrxShapeItem ret = (GrxShapeItem)super.clone();
1029 /*
1030  ret.tg_ = new TransformGroup();
1031  ret.tg_.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
1032  ret.tg_.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
1033  ret.tg_.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
1034  ret.bg_ = new BranchGroup();
1035  ret.bg_.setCapability(BranchGroup.ALLOW_DETACH);
1036 
1037  Vector3d v3d = new Vector3d(transform[3], transform[7], transform[11]);
1038  Matrix3d m3d = new Matrix3d(transform[0], transform[1], transform[2],
1039  transform[4], transform[5], transform[6],
1040  transform[8], transform[9], transform[10]);
1041  AxisAngle4d a4d = new AxisAngle4d();
1042  a4d.set(m3d);
1043  Transform3D t3d = new Transform3D();
1044  t3d.setTranslation(v3d);
1045  t3d.setRotation(a4d);
1046 
1047  double [] pos = new double[3];
1048  v3d.get(pos);
1049  setDblAry("translation", pos);
1050  double [] rot = new double[4];
1051  a4d.get(rot);
1052  setDblAry("rotation", rot);
1053 
1054  tg_.setTransform(t3d);
1055  Shape3D linkShape3D = createLinkShape3D(shapeInfo, appearanceInfo, materialInfo, textureInfo);
1056  tg_.addChild(linkShape3D);
1057 
1058  bg_.addChild(tg_);
1059  */
1060 
1061 /*
1062  Deep copy suspension list
1063  public BranchGroup bg_;
1064  public TransformGroup tg_;
1065  public GrxLinkItem parent_;
1066  public ShapeInfo shapeInfo_;
1067  public AppearanceInfo appearanceInfo_;
1068  public MaterialInfo materialInfo_;
1069  public TextureInfo textureInfo_;
1070 */
1071 
1072  return ret;
1073  }
1074 
1075  void setColor(java.awt.Color color, Node node){
1076  if (node instanceof Shape3D){
1077  Color3f c3f = new Color3f(color);
1078  Shape3D s3d = (Shape3D)node;
1079  Appearance app = s3d.getAppearance();
1080  if (app != null){
1081  Material ma = app.getMaterial();
1082  if (ma != null){
1083  ma.setAmbientColor(c3f);
1084  }
1085  }
1086  }else if (node instanceof Primitive){
1087  Primitive prim = (Primitive)node;
1088  for (int j=0; j<prim.numChildren(); j++){
1089  setColor(color, (Shape3D)prim.getChild(j));
1090  }
1091  }else if(node instanceof TransformGroup ){
1092  TransformGroup tfg = (TransformGroup)node;
1093  for(int j=0; j<tfg.numChildren(); j++){
1094  setColor(color, tfg.getChild(j));
1095  }
1096  }else if(node instanceof BranchGroup ){
1097  BranchGroup bg = (BranchGroup)node;
1098  for(int j=0; j<bg.numChildren(); j++){
1099  setColor(color, bg.getChild(j));
1100  }
1101  }
1102  }
1103 
1104  void setColor(java.awt.Color color){
1105  setColor(color, tg_);
1106  }
1107 
1108  void restoreColor(Node node, int id){
1109  if(node instanceof Shape3D){
1110  Shape3D s3d = (Shape3D)node;
1111  Appearance app = s3d.getAppearance();
1112  setMaterial(app, materials_[id]);
1113  }else if(node instanceof Primitive){
1114  Primitive prim = (Primitive)node;
1115  for (int j=0; j<prim.numChildren(); j++){
1116  restoreColor((Shape3D)prim.getChild(j), id);
1117  }
1118  }else if(node instanceof TransformGroup ){
1119  TransformGroup tfg = (TransformGroup)node;
1120  for(int j=0; j<tfg.numChildren(); j++){
1121  restoreColor(tfg.getChild(j), id);
1122  }
1123  }else if(node instanceof BranchGroup ){
1124  BranchGroup bg = (BranchGroup)node;
1125  for(int j=0; j<bg.numChildren(); j++){
1126  restoreColor(bg.getChild(j), id);
1127  }
1128  }
1129  }
1130 
1131  void restoreColor(){
1132  restoreColor(tg_, 0);
1133  }
1134 
1135  private void setPrimitiveProperty(ShapeInfo shapeInfo){
1136  switch(shapeInfo.primitiveType.value()){
1137  case ShapePrimitiveType._SP_BOX :
1138  setFltAry("size", shapeInfo.primitiveParameters); //$NON-NLS-1$
1139  setFltAry("diffuseColor", materials_[0].diffuseColor); //$NON-NLS-1$
1140  break;
1141  case ShapePrimitiveType._SP_CONE :
1142  setFlt("bottomRadius", shapeInfo.primitiveParameters[0]); //$NON-NLS-1$
1143  setFlt("height", shapeInfo.primitiveParameters[1]); //$NON-NLS-1$
1144  setProperty("bottom",shapeInfo.primitiveParameters[2]==0?"false":"true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1145  setProperty("side",shapeInfo.primitiveParameters[3]==0?"false":"true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1146  setFltAry("diffuseColor", materials_[0].diffuseColor); //$NON-NLS-1$
1147  break;
1148  case ShapePrimitiveType._SP_CYLINDER :
1149  setFlt("radius", shapeInfo.primitiveParameters[0]); //$NON-NLS-1$
1150  setFlt("height", shapeInfo.primitiveParameters[1]); //$NON-NLS-1$
1151  setProperty("top",shapeInfo.primitiveParameters[2]==0?"false":"true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1152  setProperty("bottom",shapeInfo.primitiveParameters[3]==0?"false":"true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1153  setProperty("side",shapeInfo.primitiveParameters[4]==0?"false":"true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1154  setFltAry("diffuseColor", materials_[0].diffuseColor); //$NON-NLS-1$
1155  break;
1156  case ShapePrimitiveType._SP_SPHERE :
1157  setFlt("radius", shapeInfo.primitiveParameters[0]); //$NON-NLS-1$
1158  setFltAry("diffuseColor", materials_[0].diffuseColor); //$NON-NLS-1$
1159  break;
1160  default :
1161  break;
1162  }
1163  }
1164 
1165  @Override
1166  public ValueEditType GetValueEditType(String key) {
1167 
1168  if(shapes_.length == 1 && shapes_[0].primitiveType == ShapePrimitiveType.SP_CONE &&
1169  (key.equals("side") || key.equals("bottom")))
1170  {
1171  return new ValueEditCombo(booleanComboItem_);
1172  }
1173  else if(shapes_.length == 1 && shapes_[0].primitiveType == ShapePrimitiveType.SP_CYLINDER &&
1174  (key.equals("side") || key.equals("bottom") || key.equals("top")))
1175  {
1176  return new ValueEditCombo(booleanComboItem_);
1177  }
1178  return super.GetValueEditType(key);
1179  }
1180 }
static final String get(String key)
png_infop png_charp png_int_32 png_int_32 int * type
Definition: png.h:2332
#define null
our own NULL pointer
Definition: IceTypes.h:57
void setShapeInfofromModel(short shapeIndex, int id)
png_uint_32 size
Definition: png.h:1521
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void setPrimitiveProperty(ShapeInfo shapeInfo)
item corresponds to a robot model
void setMaterial(Appearance appearance, MaterialInfo materialInfo)
w
png_uint_32 i
Definition: png.h:2735
GrxShapeItem clone()
Override clone method.
long b
Definition: jpegint.h:371
png_infop png_bytep * trans
Definition: png.h:2435
png_infop png_uint_32 png_uint_32 * height
Definition: png.h:2309
void setNormals(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo)
string a
Material createMaterial(MaterialInfo materialInfo)
def run(tree, args)
boolean propertyChanged(String property, String value)
update value of property
void loadInlineShape(Matrix4d[] shapeT, Matrix4d inlinedT, int[] index, Matrix4d segmentT)
typedef int
Definition: png.h:1113
void coneSize(String property, String size)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void setColors(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo)
void setTexture(Appearance appearance, TextureInfo textureInfo)
def getText(self, nodes=None)
void loadShape(Matrix4d shapeT, int index, Matrix4d segmentT)
org
void setShape(Matrix4d[] shapeT, Matrix4d inlinedT, int n, Matrix4d segmentT)
ValueEditType GetValueEditType(String key)
GrxShapeItem(String name, GrxPluginManager manager, GrxModelItem model)
constructor
void cylinderSize(String property, String size)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03