18 package com.generalrobotix.ui.item;
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;
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;
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;
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;
79 @SuppressWarnings(
"serial")
84 public boolean isInline_ =
false;
90 private int primitiveFlag = Primitive.GEOMETRY_NOT_SHARED | Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS;
91 private Appearance appearance_=
null;
92 private BranchGroup
bg_;
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);
113 public void loadShape(Matrix4d shapeT,
int index, Matrix4d segmentT) {
116 shapes_ =
new ShapeInfo[1];
117 appearances_ =
new AppearanceInfo[1];
118 materials_ =
new MaterialInfo[1];
119 textures_ =
new TextureInfo[1];
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);
127 setShapeInfofromModel((
short) index, 0);
128 Shape3D shape3d = createShape3D(shapes_[0], appearances_[0], materials_[0], textures_[0]);
129 bg_.addChild(shape3d);
131 setPrimitiveProperty(model.
shapes[index]);
133 tg_.setTransform(t3d);
134 setURL(model.
shapes[index].url);
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];
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;
163 Primitive primitive=
null;
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);
173 case ShapePrimitiveType._SP_CONE :
174 float bottomRadius = 1.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;
183 shapes_[0].primitiveParameters = param;
184 setFlt(
"bottomRadius", bottomRadius);
185 setFlt(
"height", height);
186 setProperty(
"side",
"true");
187 setProperty(
"bottom",
"true");
189 case ShapePrimitiveType._SP_CYLINDER :
192 primitive =
new Cylinder(radius, height, primitiveFlag, appearance);
193 shapes_[0].primitiveType = ShapePrimitiveType.SP_CYLINDER;
194 param =
new float[5];
200 shapes_[0].primitiveParameters = param;
201 setFlt(
"radius", radius);
202 setFlt(
"height", height);
203 setProperty(
"side",
"true");
204 setProperty(
"bottom",
"true");
205 setProperty(
"top",
"true");
207 case ShapePrimitiveType._SP_SPHERE :
209 primitive =
new Sphere(radius, primitiveFlag, appearance);
210 shapes_[0].primitiveType = ShapePrimitiveType.SP_SPHERE;
211 param =
new float[1];
213 shapes_[0].primitiveParameters = param;
214 setFlt(
"radius", radius);
219 bg_.addChild(primitive);
220 Transform3D t3d =
new Transform3D();
221 tg_.setTransform(t3d);
225 setFltAry(
"diffuseColor", materials_[0].diffuseColor);
228 public void loadInlineShape(Matrix4d[] shapeT, Matrix4d inlinedT,
int[] index, Matrix4d segmentT){
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);
239 setShape(shapeT, inlinedT, n, segmentT);
240 setURL(model().shapes[index[0]].url);
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);
253 Shape3D linkShape3D = createShape3D(shapes_[i], appearances_[i], materials_[i], textures_[i]);
254 tfg.addChild(linkShape3D);
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);
269 ShapeInfo[] shapes = sInfo.shapes();
270 AppearanceInfo[] appearances = sInfo.appearances();
271 MaterialInfo[] materials = sInfo.materials();
272 TextureInfo[] textures = sInfo.textures();
274 TransformedShapeIndex[] tsi = sInfo.shapeIndices();
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];
291 if (appearanceInfo.textureIndex >= 0){
292 textureInfo = textures[appearanceInfo.textureIndex];
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);
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));
306 Vector3d
trans =
new Vector3d();
307 Matrix3d rotat =
new Matrix3d();
308 t3d.get(rotat, trans);
310 double [] pos =
new double[3];
316 double [] rot =
new double[4];
331 InputDialog dialog =
new InputDialog(
null,
getText(),
333 if ( dialog.open() == InputDialog.OK && dialog.getValue() !=
null)
334 rename( dialog.getValue() );
346 mes = NLS.bind(mes,
new String[]{getName()});
381 setIcon(
"segment.png");
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);
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);
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];
412 if (appearanceInfo.textureIndex >= 0){
413 textureInfo = model().textures[appearanceInfo.textureIndex];
416 shapes_[id] = shapeInfo;
417 appearances_[id] = appearanceInfo;
418 materials_[id] = materialInfo;
419 textures_[id] = textureInfo;
430 @SuppressWarnings(
"deprecation")
431 private Shape3D createShape3D
432 (ShapeInfo shapeInfo, AppearanceInfo appearanceInfo, MaterialInfo materialInfo, TextureInfo textureInfo){
434 GeometryInfo geometryInfo =
new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
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]);
442 geometryInfo.setCoordinates(vertices);
443 geometryInfo.setCoordinateIndices(shapeInfo.triangles);
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);
455 if(materialInfo !=
null)
456 setMaterial( appearance, materialInfo);
458 if(textureInfo !=
null){
459 setTexture( appearance, textureInfo);
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++] );
467 geometryInfo.setTextureCoordinates(texCoordinate);
468 geometryInfo.setTextureCoordinateIndices(appearanceInfo.textureCoordIndices);
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);
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);
546 if(materialInfo !=
null){
547 appearance.setMaterial(createMaterial(materialInfo));
551 protected void setTexture( Appearance appearance, TextureInfo textureInfo ){
554 ImageComponent2D icomp2d = texInfo.
readImage;
555 Texture2D texture2d=
null;
558 texture2d =
new Texture2D(Texture.BASE_LEVEL, Texture.LUMINANCE, texInfo.
width, texInfo.
height);
561 texture2d =
new Texture2D(Texture.BASE_LEVEL, Texture.LUMINANCE_ALPHA, texInfo.
width, texInfo.
height);
562 appearance.setTransparencyAttributes(
new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));
565 texture2d =
new Texture2D(Texture.BASE_LEVEL, Texture.RGB, texInfo.
width, texInfo.
height);
568 texture2d =
new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, texInfo.
width, texInfo.
height);
569 appearance.setTransparencyAttributes(
new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f));
572 texture2d.setImage(0, icomp2d);
573 appearance.setTexture(texture2d);
575 if(!texInfo.url.equals(
"")){
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);
585 TextureAttributes texAttrBase =
new TextureAttributes();
586 texAttrBase.setTextureMode(TextureAttributes.REPLACE);
587 appearance.setTextureAttributes(texAttrBase);
593 Material material =
new Material();
595 float[] dColor = materialInfo.diffuseColor;
596 material.setDiffuseColor(
new Color3f(dColor[0], dColor[1], dColor[2]));
598 float[] sColor = materialInfo.specularColor;
599 material.setSpecularColor(
new Color3f(sColor[0], sColor[1], sColor[2]));
601 float[] eColor = materialInfo.emissiveColor;
602 material.setEmissiveColor(
new Color3f(eColor[0], eColor[1], eColor[2]));
604 float r = materialInfo.ambientIntensity;
605 material.setAmbientColor(
new Color3f(r * dColor[0], r * dColor[1], r * dColor[2]));
607 float shininess = materialInfo.shininess * 127.0f + 1.0f;
608 material.setShininess(shininess);
610 material.setCapability(Material.ALLOW_COMPONENT_READ);
611 material.setCapability(Material.ALLOW_COMPONENT_WRITE);
616 private void setColors(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo) {
618 int numColors = appearanceInfo.colors.length / 3;
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]);
626 geometryInfo.setColors(colors);
628 int[] orgColorIndices = appearanceInfo.colorIndices;
629 int numOrgColorIndices = orgColorIndices.length;
630 int numTriangles = shapeInfo.triangles.length / 3;
631 int[] colorIndices =
new int[numTriangles * 3];
633 if(numOrgColorIndices > 0){
634 if(appearanceInfo.colorPerVertex){
635 colorIndices = orgColorIndices;
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;
646 if(appearanceInfo.colorPerVertex){
647 for(
int i=0;
i < colorIndices.length; ++
i){
648 colorIndices[
i] = shapeInfo.triangles[
i];
652 for(
int i=0;
i < numTriangles; ++
i){
653 for(
int j=0; j < 3; ++j){
654 colorIndices[pos++] =
i;
660 geometryInfo.setColorIndices(colorIndices);
665 private void setNormals(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo) {
667 int numNormals = appearanceInfo.normals.length / 3;
670 NormalGenerator ng =
new NormalGenerator(appearanceInfo.creaseAngle);
671 ng.generateNormals(geometryInfo);
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]);
680 geometryInfo.setNormals(normals);
682 int[] orgNormalIndices = appearanceInfo.normalIndices;
683 int numOrgNormalIndices = orgNormalIndices.length;
684 int numTriangles = shapeInfo.triangles.length / 3;
685 int[] normalIndices =
new int[numTriangles * 3];
687 if(numOrgNormalIndices > 0){
688 if(appearanceInfo.normalPerVertex){
689 normalIndices = orgNormalIndices;
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;
700 if(appearanceInfo.normalPerVertex){
701 for(
int i=0;
i < normalIndices.length; ++
i){
702 normalIndices[
i] = shapeInfo.triangles[
i];
706 for(
int i=0;
i < numTriangles; ++
i){
707 for(
int j=0; j < 3; ++j){
708 normalIndices[pos++] =
i;
715 geometryInfo.setNormalIndices(normalIndices);
727 if (super.propertyChanged(property, value)){
728 }
else if(property.equals(
"translation")){
730 }
else if(property.equals(
"rotation")){
732 }
else if(property.equals(
"size")){
734 }
else if(property.equals(
"bottomRadius") ||
property.equals(
"height") ||
property.equals(
"radius") ||
735 property.equals(
"side") ||
property.equals(
"bottom") ||
property.equals(
"top")){
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);
743 }
else if(property.equals(
"diffuseColor")){
750 private void size(
float[] newSize){
751 if (newSize !=
null && newSize.length == 3){
752 setFltAry(
"size", newSize);
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);
762 if (model_ !=
null) model_.notifyModified();
763 shapes_[0].primitiveParameters = newSize;
768 float[] newSize = getFltAry(size);
773 float bottomRadius = getFlt(
"bottomRadius", 0.0
f);
774 float height = getFlt(
"height", 0.0
f);
775 boolean side = isTrue(
"side");
776 boolean bottom = isTrue(
"bottom");
777 if(property.equals(
"bottomRadius")){
778 float newsize = getFlt(size);
779 setFlt(property, newsize );
780 bottomRadius = newsize;
781 }
else if(property.equals(
"height")){
782 float newsize = getFlt(size);
783 setFlt(property, newsize );
785 }
else if(property.equals(
"side")){
786 boolean flg = size.equals(
"true");
787 setBool(property, flg);
789 }
else if(property.equals(
"bottom")){
790 boolean flg = size.equals(
"true");
791 setBool(property, flg);
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_);
801 primitive.removeChild(primitive.getShape(Cone.CAP));
803 primitive.removeChild(primitive.getShape(Cone.BODY));
804 bg_.addChild(primitive);
807 if (model_ !=
null) model_.notifyModified();
808 float[] param =
new float[4];
809 param[0] = bottomRadius;
811 param[2] = bottom ? 1: 0;
812 param[3] = side? 1 : 0;
813 shapes_[0].primitiveParameters = param;
817 float radius = getFlt(
"radius", 0.0
f);
818 float height = getFlt(
"height", 0.0
f);
819 boolean side = isTrue(
"side");
820 boolean bottom = isTrue(
"bottom");
821 boolean top = isTrue(
"top");
822 if(property.equals(
"radius")){
823 float newsize = getFlt(size);
824 setFlt(property, newsize );
826 }
else if(property.equals(
"height")){
827 float newsize = getFlt(size);
828 setFlt(property, newsize );
830 }
else if(property.equals(
"side")){
831 boolean flg = size.equals(
"true");
832 setBool(property, flg);
834 }
else if(property.equals(
"bottom")){
835 boolean flg = size.equals(
"true");
836 setBool(property, flg);
838 }
else if(property.equals(
"top")){
839 boolean flg = size.equals(
"true");
840 setBool(property, flg);
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);
852 primitive.removeChild(primitive.getShape(Cylinder.BOTTOM));
854 primitive.removeChild(primitive.getShape(Cylinder.TOP));
856 primitive.removeChild(primitive.getShape(Cylinder.BODY));
859 if (model_ !=
null) model_.notifyModified();
860 float[] param =
new float[5];
863 param[2] = top ? 1 : 0;
864 param[3] = bottom? 1 : 0;
865 param[4] = side? 1 : 0;
866 shapes_[0].primitiveParameters = param;
870 if (newSize !=
null && newSize.length == 1){
871 setFlt(
"radius", newSize[0]);
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);
881 if (model_ !=
null) model_.notifyModified();
882 shapes_[0].primitiveParameters = newSize;
887 float[] newSize = getFltAry(size);
891 void diffuseColor(
float[] newValue){
892 if (newValue !=
null && newValue.length == 3){
893 setFltAry(
"diffuseColor", newValue);
894 materials_[0].diffuseColor = newValue;
895 setMaterial(appearance_, materials_[0]);
896 if (model_ !=
null) model_.notifyModified();
900 void diffuseColor(String
value){
901 float[] newValue = getFltAry(value);
902 diffuseColor(newValue);
916 width = texinfo.width;
917 height = texinfo.height;
918 numComponents = texinfo.numComponents;
920 repeatS = texinfo.repeatS;
921 repeatT = texinfo.repeatT;
924 if((width == 0) || (height == 0)){
938 short width_new = (short)(w);
939 if(width_new-width > width-width_new/2)
945 short height_new = (short)(w);
946 if(height_new-height > height-height_new/2)
950 BufferedImage bimageRead=
null;
951 switch(numComponents){
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];
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)) ;
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);
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);
1002 height = height_new;
1005 switch(numComponents){
1007 readImage =
new ImageComponent2D(ImageComponent.FORMAT_CHANNEL8, bimageRead);
1010 readImage =
new ImageComponent2D(ImageComponent.FORMAT_LUM8_ALPHA8, bimageRead);
1013 readImage =
new ImageComponent2D(ImageComponent.FORMAT_RGB, bimageRead);
1016 readImage =
new ImageComponent2D(ImageComponent.FORMAT_RGBA, bimageRead);
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();
1081 Material ma = app.getMaterial();
1083 ma.setAmbientColor(c3f);
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));
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));
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));
1104 void setColor(java.awt.Color color){
1105 setColor(color, tg_);
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);
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);
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);
1131 void restoreColor(){
1132 restoreColor(tg_, 0);
1136 switch(shapeInfo.primitiveType.value()){
1137 case ShapePrimitiveType._SP_BOX :
1138 setFltAry(
"size", shapeInfo.primitiveParameters);
1139 setFltAry(
"diffuseColor", materials_[0].diffuseColor);
1141 case ShapePrimitiveType._SP_CONE :
1142 setFlt(
"bottomRadius", shapeInfo.primitiveParameters[0]);
1143 setFlt(
"height", shapeInfo.primitiveParameters[1]);
1144 setProperty(
"bottom",shapeInfo.primitiveParameters[2]==0?
"false":
"true");
1145 setProperty(
"side",shapeInfo.primitiveParameters[3]==0?
"false":
"true");
1146 setFltAry(
"diffuseColor", materials_[0].diffuseColor);
1148 case ShapePrimitiveType._SP_CYLINDER :
1149 setFlt(
"radius", shapeInfo.primitiveParameters[0]);
1150 setFlt(
"height", shapeInfo.primitiveParameters[1]);
1151 setProperty(
"top",shapeInfo.primitiveParameters[2]==0?
"false":
"true");
1152 setProperty(
"bottom",shapeInfo.primitiveParameters[3]==0?
"false":
"true");
1153 setProperty(
"side",shapeInfo.primitiveParameters[4]==0?
"false":
"true");
1154 setFltAry(
"diffuseColor", materials_[0].diffuseColor);
1156 case ShapePrimitiveType._SP_SPHERE :
1157 setFlt(
"radius", shapeInfo.primitiveParameters[0]);
1158 setFltAry(
"diffuseColor", materials_[0].diffuseColor);
1168 if(shapes_.length == 1 && shapes_[0].primitiveType == ShapePrimitiveType.SP_CONE &&
1169 (key.equals(
"side") || key.equals(
"bottom")))
1173 else if(shapes_.length == 1 && shapes_[0].primitiveType == ShapePrimitiveType.SP_CYLINDER &&
1174 (key.equals(
"side") || key.equals(
"bottom") || key.equals(
"top")))
1178 return super.GetValueEditType(key);
static final String get(String key)
png_infop png_charp png_int_32 png_int_32 int * type
#define null
our own NULL pointer
void setShapeInfofromModel(short shapeIndex, int id)
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void setPrimitiveProperty(ShapeInfo shapeInfo)
item corresponds to a robot model
void loadnewInlineShape(SceneInfo sInfo)
void setMaterial(Appearance appearance, MaterialInfo materialInfo)
void sphereSize(float[] newSize)
GrxShapeItem clone()
Override clone method.
png_infop png_bytep * trans
void initialize(Transform3D t3d)
TextureInfoLocal(TextureInfo texinfo)
ImageComponent2D readImage
Appearance createAppearance()
png_infop png_uint_32 png_uint_32 * height
void size(float[] newSize)
void setNormals(GeometryInfo geometryInfo, ShapeInfo shapeInfo, AppearanceInfo appearanceInfo)
Material createMaterial(MaterialInfo materialInfo)
boolean propertyChanged(String property, String value)
update value of property
void setMatrix(Matrix3d m1)
void loadInlineShape(Matrix4d[] shapeT, Matrix4d inlinedT, int[] index, Matrix4d segmentT)
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)
MaterialInfo [] materials_
void sphereSize(String size)
void loadShape(Matrix4d shapeT, int index, Matrix4d segmentT)
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)
AppearanceInfo [] appearances_
void createnewPrimitiveShape(int type)