1 package com.generalrobotix.ui.util;
3 import java.io.BufferedWriter;
5 import java.io.FileWriter;
6 import java.util.Vector;
7 import java.util.regex.*;
31 int idx = exportPath.lastIndexOf(
File.separatorChar);
33 idx = exportPath.lastIndexOf(
'/');
34 String exportDir = exportPath.substring(0, idx);
38 writer =
new BufferedWriter(
new FileWriter(exportPath));
40 writer.write(
"#VRML V2.0 utf8\n");
42 writer.write(
"PROTO Joint [\n");
43 writer.write(
" exposedField SFVec3f center 0 0 0\n");
44 writer.write(
" exposedField MFNode children []\n");
45 writer.write(
" exposedField MFFloat llimit []\n");
46 writer.write(
" exposedField MFFloat lvlimit []\n");
47 writer.write(
" exposedField SFRotation limitOrientation 0 0 1 0\n");
48 writer.write(
" exposedField SFString name \"\"\n");
49 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
50 writer.write(
" exposedField SFVec3f scale 1 1 1\n");
51 writer.write(
" exposedField SFRotation scaleOrientation 0 0 1 0\n");
52 writer.write(
" exposedField MFFloat stiffness [ 0 0 0 ]\n");
53 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
54 writer.write(
" exposedField MFFloat ulimit []\n");
55 writer.write(
" exposedField MFFloat uvlimit []\n");
56 writer.write(
" exposedField SFString jointType \"\"\n");
57 writer.write(
" exposedField SFInt32 jointId -1\n");
58 writer.write(
" exposedField SFVec3f jointAxis 0 0 1\n");
60 writer.write(
" exposedField SFFloat gearRatio 1\n");
61 writer.write(
" exposedField SFFloat rotorInertia 0\n");
62 writer.write(
" exposedField SFFloat rotorResistor 0\n");
63 writer.write(
" exposedField SFFloat torqueConst 1\n");
64 writer.write(
" exposedField SFFloat encoderPulse 1\n");
67 writer.write(
" Transform {\n");
68 writer.write(
" center IS center\n");
69 writer.write(
" children IS children\n");
70 writer.write(
" rotation IS rotation\n");
71 writer.write(
" scale IS scale\n");
72 writer.write(
" scaleOrientation IS scaleOrientation\n");
73 writer.write(
" translation IS translation\n");
77 writer.write(
"PROTO Segment [\n");
78 writer.write(
" field SFVec3f bboxCenter 0 0 0\n");
79 writer.write(
" field SFVec3f bboxSize -1 -1 -1\n");
80 writer.write(
" exposedField SFVec3f centerOfMass 0 0 0\n");
81 writer.write(
" exposedField MFNode children [ ]\n");
82 writer.write(
" exposedField SFNode coord NULL\n");
83 writer.write(
" exposedField MFNode displacers [ ]\n");
84 writer.write(
" exposedField SFFloat mass 0 \n");
85 writer.write(
" exposedField MFFloat momentsOfInertia [ 0 0 0 0 0 0 0 0 0 ]\n");
86 writer.write(
" exposedField SFString name \"\"\n");
87 writer.write(
" eventIn MFNode addChildren\n");
88 writer.write(
" eventIn MFNode removeChildren\n");
91 writer.write(
" Group {\n");
92 writer.write(
" addChildren IS addChildren\n");
93 writer.write(
" bboxCenter IS bboxCenter\n");
94 writer.write(
" bboxSize IS bboxSize\n");
95 writer.write(
" children IS children\n");
96 writer.write(
" removeChildren IS removeChildren\n");
100 writer.write(
"PROTO Humanoid [\n");
101 writer.write(
" field SFVec3f bboxCenter 0 0 0\n");
102 writer.write(
" field SFVec3f bboxSize -1 -1 -1\n");
103 writer.write(
" exposedField SFVec3f center 0 0 0\n");
104 writer.write(
" exposedField MFNode humanoidBody [ ]\n");
105 writer.write(
" exposedField MFString info [ ]\n");
106 writer.write(
" exposedField MFNode joints [ ]\n");
107 writer.write(
" exposedField SFString name \"\"\n");
108 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
109 writer.write(
" exposedField SFVec3f scale 1 1 1\n");
110 writer.write(
" exposedField SFRotation scaleOrientation 0 0 1 0\n");
111 writer.write(
" exposedField MFNode segments [ ]\n");
112 writer.write(
" exposedField MFNode sites [ ]\n");
113 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
114 writer.write(
" exposedField SFString version \"1.1\"\n");
115 writer.write(
" exposedField MFNode viewpoints [ ]\n");
118 writer.write(
" Transform {\n");
119 writer.write(
" bboxCenter IS bboxCenter\n");
120 writer.write(
" bboxSize IS bboxSize\n");
121 writer.write(
" center IS center\n");
122 writer.write(
" rotation IS rotation\n");
123 writer.write(
" scale IS scale\n");
124 writer.write(
" scaleOrientation IS scaleOrientation\n");
125 writer.write(
" translation IS translation\n");
126 writer.write(
" children [\n");
127 writer.write(
" Group {\n");
128 writer.write(
" children IS viewpoints\n");
129 writer.write(
" }\n");
130 writer.write(
" Group {\n");
131 writer.write(
" children IS humanoidBody \n");
132 writer.write(
" }\n");
133 writer.write(
" ]\n");
134 writer.write(
" }\n");
137 writer.write(
"PROTO VisionSensor [\n");
138 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
139 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
140 writer.write(
" exposedField MFNode children [ ]\n");
141 writer.write(
" exposedField SFFloat fieldOfView 0.785398\n");
142 writer.write(
" exposedField SFString name \"\"\n");
143 writer.write(
" exposedField SFFloat frontClipDistance 0.01\n");
144 writer.write(
" exposedField SFFloat backClipDistance 10.0\n");
145 writer.write(
" exposedField SFString type \"NONE\"\n");
146 writer.write(
" exposedField SFInt32 sensorId -1\n");
147 writer.write(
" exposedField SFInt32 width 320\n");
148 writer.write(
" exposedField SFInt32 height 240\n");
149 writer.write(
" exposedField SFFloat frameRate 30\n");
152 writer.write(
" Transform {\n");
153 writer.write(
" rotation IS rotation\n");
154 writer.write(
" translation IS translation\n");
155 writer.write(
" children IS children\n");
156 writer.write(
" }\n");
160 writer.write(
"PROTO ForceSensor [ \n");
161 writer.write(
" exposedField SFVec3f maxForce -1 -1 -1\n");
162 writer.write(
" exposedField SFVec3f maxTorque -1 -1 -1\n");
163 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
164 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
165 writer.write(
" exposedField MFNode children [ ]\n");
166 writer.write(
" exposedField SFInt32 sensorId -1\n");
169 writer.write(
" Transform {\n");
170 writer.write(
" translation IS translation\n");
171 writer.write(
" rotation IS rotation\n");
172 writer.write(
" children IS children\n");
173 writer.write(
" }\n");
176 writer.write(
"PROTO Gyro [\n");
177 writer.write(
" exposedField SFVec3f maxAngularVelocity -1 -1 -1\n");
178 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
179 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
180 writer.write(
" exposedField MFNode children [ ]\n");
181 writer.write(
" exposedField SFInt32 sensorId -1\n");
184 writer.write(
" Transform {\n");
185 writer.write(
" translation IS translation\n");
186 writer.write(
" rotation IS rotation\n");
187 writer.write(
" children IS children\n");
188 writer.write(
" }\n");
191 writer.write(
"PROTO AccelerationSensor [\n");
192 writer.write(
" exposedField SFVec3f maxAcceleration -1 -1 -1\n");
193 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
194 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
195 writer.write(
" exposedField MFNode children [ ]\n");
196 writer.write(
" exposedField SFInt32 sensorId -1\n");
199 writer.write(
" Transform {\n");
200 writer.write(
" translation IS translation\n");
201 writer.write(
" rotation IS rotation\n");
202 writer.write(
" children IS children\n");
203 writer.write(
" }\n");
206 writer.write(
"PROTO RangeSensor [\n");
207 writer.write(
" exposedField SFVec3f translation 0 0 0\n");
208 writer.write(
" exposedField SFRotation rotation 0 0 1 0\n");
209 writer.write(
" exposedField MFNode children [ ]\n");
210 writer.write(
" exposedField SFInt32 sensorId -1\n");
211 writer.write(
" exposedField SFFloat scanAngle 3.14159 #[rad]\n");
212 writer.write(
" exposedField SFFloat scanStep 0.1 #[rad]\n");
213 writer.write(
" exposedField SFFloat scanRate 10 #[Hz]\n");
214 writer.write(
" exposedField SFFloat maxDistance 10\n");
217 writer.write(
" Transform {\n");
218 writer.write(
" translation IS translation\n");
219 writer.write(
" rotation IS rotation\n");
220 writer.write(
" children IS children\n");
221 writer.write(
" }\n");
224 writer.write(
"PROTO Plane [\n");
225 writer.write(
" exposedField SFVec3f size 10 10 0\n");
228 writer.write(
" Box {\n");
229 writer.write(
" size IS size\n");
230 writer.write(
" }\n");
233 writer.write(
"PROTO ExtraJoint [\n");
234 writer.write(
" exposedField SFString link1Name \"\"\n");
235 writer.write(
" exposedField SFString link2Name \"\"\n");
236 writer.write(
" exposedField SFVec3f link1LocalPos 0 0 0\n");
237 writer.write(
" exposedField SFVec3f link2LocalPos 0 0 0\n");
238 writer.write(
" exposedField SFString jointType \"xyz\"\n");
239 writer.write(
" exposedField SFVec3f jointAxis 1 0 0\n");
244 writer.write(
"NavigationInfo {\n");
245 writer.write(
" avatarSize 0.5\n");
246 writer.write(
" headlight TRUE\n");
247 writer.write(
" type [\"EXAMINE\", \"ANY\"]\n");
250 writer.write(
"Background {\n");
251 writer.write(
" skyColor 0.4 0.6 0.4\n");
254 writer.write(
"Viewpoint {\n");
255 writer.write(
" position 3 0 0.835\n");
256 writer.write(
" orientation 0.5770 0.5775 0.5775 2.0935\n");
263 writer.write(
"DEF "+model.
getName()+
" Humanoid{\n");
264 writer.write(
" humanoidBody [\n");
266 writer.write(
" ]\n");
267 writer.write(
" joints [\n");
268 for (
int i=0;
i<links.size();
i++){
269 writer.write(
" USE "+links.get(
i).getName()+
",\n");
271 writer.write(
" ]\n");
272 writer.write(
" segments [\n");
273 for (
int i=0;
i<links.size();
i++){
277 writer.write(
" USE "+link.
children_.get(
j).getName()+
",\n");
281 writer.write(
" ]\n");
284 }
catch (Exception e) {
288 if (writer !=
null) {
292 }
catch (Exception e) {
308 String exportDir, String mainPath){
309 Vector<GrxLinkItem> links =
new Vector<GrxLinkItem>();
312 writer.write(indent+
"DEF "+link.
getName()+
" Joint {\n");
313 writer.write(indent+
" jointType \""+link.
jointType_+
"\"\n");
314 if (link.
jointId_ != -1) writer.write(indent+
" jointId "+link.
jointId_+
"\n");
316 writer.write(indent+
" jointAxis "+link.getProperty(
"jointAxis")+
"\n");
318 if (!
valueEquals(link.getProperty(
"translation"),
"0.0 0.0 0.0 ")){
319 writer.write(indent+
" translation "+link.getProperty(
"translation")+
"\n");
321 if (!
isZero(link.getProperty(
"rotation"),3)){
322 writer.write(indent+
" rotation "+link.getProperty(
"rotation")+
"\n");
324 if (!link.getProperty(
"ulimit").
equals(
"")) writer.write(indent+
" ulimit ["+link.getProperty(
"ulimit")+
"]\n");
325 if (!link.getProperty(
"llimit").
equals(
"")) writer.write(indent+
" llimit ["+link.getProperty(
"llimit")+
"]\n");
326 if (!link.getProperty(
"uvlimit").
equals(
"")) writer.write(indent+
" uvlimit ["+link.getProperty(
"uvlimit")+
"]\n");
327 if (!link.getProperty(
"lvlimit").
equals(
"")) writer.write(indent+
" lvlimit ["+link.getProperty(
"lvlimit")+
"]\n");
333 writer.write(indent+
" children[\n");
347 indent+
" ", exportDir, mainPath);
348 links.addAll(childLinks);
351 writer.write(indent+
" ]\n");
352 writer.write(indent+
"}\n");
353 }
catch(Exception ex){
354 ex.printStackTrace();
361 String translation = segment.getProperty(
"translation");
362 String rotation = segment.getProperty(
"rotation");
363 boolean useTransform =
false;
366 writer.write(indent+
"Transform {\n");
367 writer.write(indent+
" translation "+translation+
"\n");
368 writer.write(indent+
" rotation "+rotation+
"\n");
369 writer.write(indent+
" children[\n");
372 writer.write(indent+
"DEF "+segment.
getName()+
" Segment{\n");
373 writer.write(indent+
" centerOfMass "+segment.getProperty(
"centerOfMass")+
"\n");
374 writer.write(indent+
" mass "+segment.getProperty(
"mass")+
"\n");
375 writer.write(indent+
" momentsOfInertia [ "+segment.getProperty(
"momentsOfInertia")+
"]\n");
376 writer.write(indent+
" children[\n");
380 exportShape(writer, shape, indent+
" ", exportDir, mainPath);
383 writer.write(indent+
" ]\n");
384 writer.write(indent+
"}\n");
386 writer.write(indent+
" ]\n");
387 writer.write(indent+
"}\n");
389 }
catch(Exception ex){
390 ex.printStackTrace();
404 String nodeType=
"unknown";
405 if (sensor.
type_.equals(
"Force")){
406 nodeType =
"ForceSensor";
407 }
else if(sensor.
type_.equals(
"RateGyro")){
409 }
else if(sensor.
type_.equals(
"Acceleration")){
410 nodeType =
"AccelerationSensor";
411 }
else if(sensor.
type_.equals(
"Vision")){
412 nodeType =
"VisionSensor";
413 }
else if(sensor.
type_.equals(
"Range")){
414 nodeType =
"RangeSensor";
416 writer.write(indent+
"DEF "+sensor.
getName()+
" "+nodeType+
" {\n");
417 writer.write(indent+
" sensorId "+sensor.
id_+
"\n");
418 if (!
valueEquals(sensor.getProperty(
"translation"),
"0.0 0.0 0.0 ")){
419 writer.write(indent+
" translation "+sensor.getProperty(
"translation")+
"\n");
421 if (!
isZero(sensor.getProperty(
"rotation"),3)){
422 writer.write(indent+
" rotation "+sensor.getProperty(
"rotation")+
"\n");
425 if (nodeType.equals(
"VisionSensor")){
426 if (!
valueEquals(sensor.getProperty(
"fieldOfView"),
"0.785398")){
427 writer.write(indent+
" fieldOfView "+sensor.getProperty(
"fieldOfView")+
"\n");
429 if (!
valueEquals(sensor.getProperty(
"frontClipDistance"),
"0.01")){
430 writer.write(indent+
" frontClipDistance "+sensor.getProperty(
"frontClipDistance")+
"\n");
432 if (!
valueEquals(sensor.getProperty(
"backClipDistance"),
"10.0")){
433 writer.write(indent+
" backClipDistance "+sensor.getProperty(
"backClipDistance")+
"\n");
435 if (!
valueEquals(sensor.getProperty(
"width"),
"320")){
436 writer.write(indent+
" width "+sensor.getProperty(
"width")+
"\n");
438 if (!
valueEquals(sensor.getProperty(
"height"),
"240")){
439 writer.write(indent+
" height "+sensor.getProperty(
"height")+
"\n");
441 if (!
valueEquals(sensor.getProperty(
"frameRate"),
"30.0")){
442 writer.write(indent+
" frameRate "+sensor.getProperty(
"frameRate")+
"\n");
444 if (!sensor.getProperty(
"cameraType").
equals(
"NONE")){
445 writer.write(indent+
" type \""+sensor.getProperty(
"cameraType")+
"\"\n");
447 if (!sensor.getProperty(
"name").
equals(
"")){
448 writer.write(indent+
" name \""+sensor.getProperty(
"name")+
"\"\n");
450 }
else if(nodeType.equals(
"ForceSensor")){
451 String maxf = sensor.getProperty(
"maxForce");
453 writer.write(indent+
" maxForce "+maxf+
"\n");
455 String maxt = sensor.getProperty(
"maxTorque");
457 writer.write(indent+
" maxTorque "+maxt+
"\n");
459 }
else if(nodeType.equals(
"Gyro")){
460 String
max = sensor.getProperty(
"maxAngularVelocity");
462 writer.write(indent+
" maxAngularVelocity "+max+
"\n");
464 }
else if(nodeType.equals(
"AccelerationSensor")){
465 String
max = sensor.getProperty(
"maxAcceleration");
467 writer.write(indent+
" maxAcceleration "+max+
"\n");
469 }
else if(nodeType.equals(
"RangeSensor")){
470 String angle = sensor.getProperty(
"scanAngle");
472 writer.write(indent+
" scanAngle "+angle+
"\n");
474 String step = sensor.getProperty(
"scanStep");
476 writer.write(indent+
" scanStep "+step+
"\n");
478 String rate = sensor.getProperty(
"scanRate");
480 writer.write(indent+
" scanRate "+rate+
"\n");
482 String distance = sensor.getProperty(
"maxDistance");
484 writer.write(indent+
" maxDistance "+distance+
"\n");
488 writer.write(indent+
" children[\n");
494 writer.write(indent+
" ]\n");
496 writer.write(indent+
"}\n");
497 }
catch(Exception ex){
498 ex.printStackTrace();
511 System.out.println(
"mainPath = "+ mainPath);
512 System.out.println(
"url of shape = "+shape.
getURL(
false));
518 writer.write(indent+
"Transform {\n");
519 if (!
valueEquals(shape.getProperty(
"translation"),
"0.0 0.0 0.0 ")){
520 writer.write(indent+
" translation "+shape.getProperty(
"translation")+
"\n");
522 if (!
isZero(shape.getProperty(
"rotation"),3)){
523 writer.write(indent+
" rotation "+shape.getProperty(
"rotation")+
"\n");
525 writer.write(indent+
" children[\n");
526 writer.write(indent+
" Shape{\n");
529 writer.write(indent+
" appearance Appearance{\n");
532 writer.write(indent+
" material Material{\n");
533 writer.write(indent+
" diffuseColor " 534 +mat.diffuseColor[0]+
" "+mat.diffuseColor[1]+
" "+mat.diffuseColor[2]+
"\n");
535 writer.write(indent+
" }\n");
539 writer.write(indent+
" texture ImageTexture {\n");
540 String url = tex.url;
541 url = url.replace(
'\\',
'/');
543 writer.write(indent+
" }\n");
545 writer.write(indent+
" }\n");
547 writer.write(indent+
" }\n");
548 writer.write(indent+
" ]\n");
549 writer.write(indent+
"}\n");
551 writer.write(indent+
"Transform {\n");
552 if (!
valueEquals(shape.getProperty(
"translation"),
"0.0 0.0 0.0 ")){
553 writer.write(indent+
" translation "+shape.getProperty(
"translation")+
"\n");
555 if (!
isZero(shape.getProperty(
"rotation"),3)){
556 writer.write(indent+
" rotation "+shape.getProperty(
"rotation")+
"\n");
558 writer.write(indent+
" children[\n");
560 writer.write(indent+
" ]\n");
561 writer.write(indent+
"}\n");
563 }
catch(Exception ex){
564 ex.printStackTrace();
570 writer.write(
"DEF "+extraJoint.
getName()+
" ExtraJoint{\n");
571 writer.write(
" link1Name \""+extraJoint.getProperty(
"link1Name")+
"\"\n");
572 writer.write(
" link2Name \""+extraJoint.getProperty(
"link2Name")+
"\"\n");
573 writer.write(
" link1LocalPos "+extraJoint.getProperty(
"link1LocalPos")+
"\n");
574 writer.write(
" link2LocalPos "+extraJoint.getProperty(
"link2LocalPos")+
"\n");
575 writer.write(
" jointType \""+extraJoint.getProperty(
"jointType")+
"\"\n");
576 writer.write(
" jointAxis "+extraJoint.getProperty(
"jointAxis")+
"\n");
578 }
catch(Exception ex){
579 ex.printStackTrace();
590 Pattern localPattern = Pattern.compile(
"\\\\");
592 Matcher localMatcher = localPattern.matcher(
"/");
593 String localStr = localMatcher.replaceAll(
"\\\\\\\\");
595 String [] dirs1 = absPath.split( localStr );
596 String [] dirs2 = baseDir.split( localStr );
600 if (System.getProperty(
"os.name").equals(
"Linux") || System.getProperty(
"os.name").equals(
"Mac OS X")) {
601 while (cnt < dirs1.length && cnt < dirs2.length && dirs1[cnt].equals(dirs2[cnt])) cnt++;
602 for (
int i=0;
i<dirs2.length-cnt;
i++) relPath +=
"../";
603 for (
int i=cnt;
i<dirs1.length;
i++){
605 if (
i != dirs1.length-1) relPath +=
"/";
608 if(dirs1[0].equals(dirs2[0])) {
609 while (cnt < dirs1.length && cnt < dirs2.length && dirs1[cnt].equals(dirs2[cnt])) cnt++;
610 for (
int i=0;
i<dirs2.length-cnt;
i++) relPath +=
"../";
612 for (
int i=cnt;
i<dirs1.length;
i++){
614 if (
i != dirs1.length-1) relPath +=
"/";
623 ShapePrimitiveType ptype = info.primitiveType;
624 float [] pparams = info.primitiveParameters;
626 if (ptype == ShapePrimitiveType.SP_MESH){
627 writer.write(indent+
"geometry IndexedFaceSet {\n");
628 writer.write(indent+
"ccw TRUE\n");
629 writer.write(indent+
"coord Coordinate {\n");
630 writer.write(indent+
"point [\n");
631 for(
int i=0;
i<info.vertices.length;)
632 writer.write(indent+info.vertices[
i++]+
" "+info.vertices[
i++]+
" "+info.vertices[
i++]+
",\n");
633 writer.write(indent+
"]\n");
634 writer.write(indent+
"}\n");
635 writer.write(indent+
"coordIndex [\n");
636 for(
int i=0;
i<info.triangles.length;)
637 writer.write(indent+info.triangles[
i++]+
" "+info.triangles[
i++]+
" "+info.triangles[
i++]+
" -1,\n");
638 writer.write(indent+
"]\n");
641 if(appinfo.normals.length != 0){
642 if(!appinfo.normalPerVertex)
643 writer.write(indent+
"normalPerVertex FALSE\n");
644 writer.write(indent+
"normal Normal {\n");
645 writer.write(indent+
"vector [\n");
646 for(
int i=0;
i<appinfo.normals.length;)
647 writer.write(indent+appinfo.normals[
i++]+
" "+appinfo.normals[
i++]+
" "+appinfo.normals[
i++]+
",\n");
648 writer.write(indent+
"]\n");
649 writer.write(indent+
"}\n");
651 if(appinfo.normalIndices.length != 0){
652 writer.write(indent+
"normalIndex [\n");
653 if(appinfo.normalPerVertex){
654 for(
int i=0;
i<appinfo.normalIndices.length;)
655 writer.write(indent+appinfo.normalIndices[
i++]+
" "+appinfo.normalIndices[
i++]+
" "+appinfo.normalIndices[
i++]+
" -1,\n");
657 for(
int i=0;
i<appinfo.normalIndices.length;
i++){
658 if(
i%3==0) writer.write(indent+
" ");
659 writer.write(appinfo.normalIndices[
i]+
" ");
660 if(
i%3==2) writer.write(
"\n");
663 writer.write(indent+
"]\n");
666 writer.write(indent+
"solid FALSE\n");
667 if (appinfo.creaseAngle != 0.0f)
668 writer.write(indent+
"creaseAngle "+ appinfo.creaseAngle+
"\n");
669 if(appinfo.colors.length != 0){
670 if(!appinfo.colorPerVertex)
671 writer.write(indent+
"colorPerVertex FALSE\n");
672 writer.write(indent+
"color Color {\n");
673 writer.write(indent+
"color [\n");
674 for(
int i=0;
i<appinfo.colors.length;)
675 writer.write(indent+appinfo.colors[
i++]+
" "+appinfo.colors[
i++]+
" "+appinfo.colors[
i++]+
",\n");
676 writer.write(indent+
"]\n");
677 writer.write(indent+
"}\n");
679 if(appinfo.colorIndices.length != 0){
680 writer.write(indent+
"colorIndex [\n");
681 if(appinfo.colorPerVertex){
682 for(
int i=0;
i<appinfo.colorIndices.length;)
683 writer.write(indent+appinfo.colorIndices[
i++]+
" "+appinfo.colorIndices[
i++]+
" "+appinfo.colorIndices[
i++]+
" -1,\n");
685 for(
int i=0;
i<appinfo.colorIndices.length;
i++){
686 if(
i%3==0) writer.write(indent+
" ");
687 writer.write(appinfo.colorIndices[
i]+
" ");
688 if(
i%3==2) writer.write(
"\n");
691 writer.write(indent+
"]\n");
693 TextureInfo texinfo = shape.
textures_[0];
695 writer.write(indent+
"texCoord TextureCoordinate {\n");
696 writer.write(indent+
"point [\n");
697 for(
int i=0;
i<appinfo.textureCoordinate.length;)
698 writer.write(indent+appinfo.textureCoordinate[
i++]+
" "+appinfo.textureCoordinate[
i++]+
",\n");
699 writer.write(indent+
"]\n");
700 writer.write(indent+
"}\n");
701 writer.write(indent+
"texCoordIndex [\n");
702 for(
int i=0;
i<appinfo.textureCoordIndices.length;)
703 writer.write(indent+appinfo.textureCoordIndices[
i++]+
" "+appinfo.textureCoordIndices[
i++]+
" "+appinfo.textureCoordIndices[
i++]+
" -1,\n");
704 writer.write(indent+
"]\n");
707 writer.write(indent+
"}\n");
708 }
else if (ptype == ShapePrimitiveType.SP_BOX){
709 writer.write(indent+
"geometry Box{\n");
710 writer.write(indent+
" size " 714 writer.write(indent+
"}\n");
715 }
else if (ptype == ShapePrimitiveType.SP_CYLINDER){
716 writer.write(indent+
"geometry Cylinder{\n");
717 writer.write(indent+
" radius "+pparams[0]+
"\n");
718 writer.write(indent+
" height "+pparams[1]+
"\n");
720 writer.write(indent+
" top FALSE\n");
723 writer.write(indent+
" bottom FALSE\n");
726 writer.write(indent+
" side FALSE\n");
728 writer.write(indent+
"}\n");
729 }
else if (ptype == ShapePrimitiveType.SP_CONE){
730 writer.write(indent+
"geometry Cone{\n");
731 writer.write(indent+
" bottomRadius "+pparams[0]+
"\n");
732 writer.write(indent+
" height "+pparams[1]+
"\n");
734 writer.write(indent+
" bottom FALSE\n");
737 writer.write(indent+
" side FALSE\n");
739 writer.write(indent+
"}\n");
740 }
else if (ptype == ShapePrimitiveType.SP_SPHERE){
741 writer.write(indent+
"geometry Sphere{\n");
742 writer.write(indent+
" radius "+pparams[0]+
"\n");
743 writer.write(indent+
"}\n");
744 }
else if (ptype == ShapePrimitiveType.SP_PLANE){
745 writer.write(indent+
"geometry Plane{\n");
746 writer.write(indent+
" size "+pparams[0]+
" "+pparams[1]+
" "+pparams[2]+
"\n");
747 writer.write(indent+
"}\n");
749 }
catch(Exception ex){
750 ex.printStackTrace();
755 final double EPS = 0.00000001;
756 String[] ss1 = s1.split(
" ");
757 String[] ss2 = s2.split(
" ");
761 for(
int i=0;
i<
n;
i++){
763 if( Math.abs(Double.parseDouble(ss1[
i]) - Double.parseDouble(ss2[i])) > EPS )
765 }
catch(Exception ex){
773 String[] ss1 = s1.split(
" ");
776 if( Math.abs(Double.parseDouble(ss1[i])) < 1e-10 )
780 }
catch(Exception ex){
#define null
our own NULL pointer
item corresponds to a robot model
String getURL(boolean expand)
boolean equals(Object obj)
check whether obj equals to this
static Vector< GrxLinkItem > exportLink(BufferedWriter writer, GrxLinkItem link, String indent, String exportDir, String mainPath)
export link information
Vector< GrxExtraJointItem > extraJoints_
static void exportGeometry(BufferedWriter writer, GrxShapeItem shape, String indent)
static void exportShape(BufferedWriter writer, GrxShapeItem shape, String indent, String exportDir, String mainPath)
export shape item
static void exportSegment(BufferedWriter writer, GrxSegmentItem segment, String indent, String exportDir, String mainPath)
GrxLinkItem rootLink()
get root link
static boolean export(GrxModelItem model, String exportPath)
export model item to a VRML97 file
def j(str, encoding="cp932")
static boolean valueEquals(String s1, String s2)
static void exportSensor(BufferedWriter writer, GrxSensorItem sensor, String indent, String exportDir, String mainPath)
final String getName()
get name
MaterialInfo[] materials_
static boolean isZero(String s1, int i)
static void exportExtraJoint(BufferedWriter writer, GrxExtraJointItem extraJoint)
static int max(int a, int b)
static String _absPath2relPath(String absPath, String baseDir)
convert absolute path into relative path
AppearanceInfo[] appearances_