Skip to content

Commit 94279ea

Browse files
committed
Adding API calls for #8
Body seems entirely broken so all of the methods to add objects to body needed to be hand crafted
1 parent 185a24a commit 94279ea

File tree

2 files changed

+130
-13
lines changed

2 files changed

+130
-13
lines changed

src/main/java/org/mujoco/xml/BodyarchType.java

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,46 @@ private JAXBElement<?> buildRecoursive(Object o) throws NoSuchMethodException, S
389389
throw new NullPointerException();
390390
if(BodyarchType.class.isInstance(product)) {
391391
BodyarchType bat = (BodyarchType)product;
392-
JAXBElement<BodyarchType> element =new JAXBElement<BodyarchType>(new QName("body"),BodyarchType.class,bat);
393-
return element;
392+
return new JAXBElement<BodyarchType>(new QName("body"),BodyarchType.class,bat);
393+
}
394+
//GeomType
395+
if(GeomType.class.isInstance(product)) {
396+
GeomType bat = (GeomType)product;
397+
return new JAXBElement<GeomType>(new QName("geom"),GeomType.class,bat);
398+
}
399+
//LightType
400+
if(LightType.class.isInstance(product)) {
401+
LightType bat = (LightType)product;
402+
return new JAXBElement<LightType>(new QName("light"),LightType.class,bat);
403+
}
404+
//JointType
405+
if(JointType.class.isInstance(product)) {
406+
JointType bat = (JointType)product;
407+
return new JAXBElement<JointType>(new QName("freejoint"),JointType.class,bat);
408+
}
409+
//CameraType
410+
if(CameraType.class.isInstance(product)) {
411+
CameraType bat = (CameraType)product;
412+
return new JAXBElement<CameraType>(new QName("camera"),CameraType.class,bat);
394413
}
395414
return buildRecoursive(product);
396415
}
397-
416+
/**
417+
* Returns a new builder to build an additional value of the "camera" property.
418+
* Use {@link org.mujoco.xml.body.CameraType.Builder#end()} to return to the current builder.
419+
*
420+
* @return
421+
* a new builder to build an additional value of the "camera" property.
422+
* Use {@link org.mujoco.xml.body.CameraType.Builder#end()} to return to the current builder.
423+
*/
424+
public org.mujoco.xml.body.CameraType.Builder<? extends BodyType.Builder<_B>> addCamera() {
425+
if (this.inertialOrJointOrFreejoint == null) {
426+
this.inertialOrJointOrFreejoint = new ArrayList<Buildable>();
427+
}
428+
final org.mujoco.xml.body.CameraType.Builder<BodyType.Builder<_B>> camera_Builder = new org.mujoco.xml.body.CameraType.Builder<BodyType.Builder<_B>>(this, null, false);
429+
this.inertialOrJointOrFreejoint.add(camera_Builder);
430+
return camera_Builder;
431+
}
398432
/**
399433
* Returns a new builder to build an additional value of the "body" property.
400434
* Use {@link org.mujoco.xml.BodyarchType.Builder#end()} to return to the current builder.
@@ -412,7 +446,56 @@ public BodyarchType.Builder<? extends BodyType.Builder<_B>> addBody() {
412446
this.inertialOrJointOrFreejoint.add(body_Builder);
413447
return body_Builder;
414448
}
415-
449+
/**
450+
* Returns a new builder to build an additional value of the "geom" property.
451+
* Use {@link org.mujoco.xml.body.GeomType.Builder#end()} to return to the current builder.
452+
*
453+
* @return
454+
* a new builder to build an additional value of the "geom" property.
455+
* Use {@link org.mujoco.xml.body.GeomType.Builder#end()} to return to the current builder.
456+
*/
457+
public org.mujoco.xml.body.GeomType.Builder<? extends BodyType.Builder<_B>> addGeom() {
458+
if (this.inertialOrJointOrFreejoint == null) {
459+
this.inertialOrJointOrFreejoint = new ArrayList<Buildable>();
460+
}
461+
final org.mujoco.xml.body.GeomType.Builder<BodyType.Builder<_B>> geom_Builder = new org.mujoco.xml.body.GeomType.Builder<BodyType.Builder<_B>>(this, null, false);
462+
this.inertialOrJointOrFreejoint.add(geom_Builder);
463+
return geom_Builder;
464+
}
465+
466+
/**
467+
* Returns a new builder to build an additional value of the "light" property.
468+
* Use {@link org.mujoco.xml.body.LightType.Builder#end()} to return to the current builder.
469+
*
470+
* @return
471+
* a new builder to build an additional value of the "light" property.
472+
* Use {@link org.mujoco.xml.body.LightType.Builder#end()} to return to the current builder.
473+
*/
474+
public org.mujoco.xml.body.LightType.Builder<? extends BodyType.Builder<_B>> addLight() {
475+
if (this.inertialOrJointOrFreejoint == null) {
476+
this.inertialOrJointOrFreejoint = new ArrayList<Buildable>();
477+
}
478+
final org.mujoco.xml.body.LightType.Builder<BodyType.Builder<_B>> light_Builder = new org.mujoco.xml.body.LightType.Builder<BodyType.Builder<_B>>(this, null, false);
479+
this.inertialOrJointOrFreejoint.add(light_Builder);
480+
return light_Builder;
481+
}
482+
//JointType
483+
/**
484+
* Returns a new builder to build an additional value of the "joint" property.
485+
* Use {@link org.mujoco.xml.body.JointType.Builder#end()} to return to the current builder.
486+
*
487+
* @return
488+
* a new builder to build an additional value of the "joint" property.
489+
* Use {@link org.mujoco.xml.body.JointType.Builder#end()} to return to the current builder.
490+
*/
491+
public org.mujoco.xml.body.JointType.Builder<? extends BodyType.Builder<_B>> addFreejoint() {
492+
if (this.inertialOrJointOrFreejoint == null) {
493+
this.inertialOrJointOrFreejoint = new ArrayList<Buildable>();
494+
}
495+
final org.mujoco.xml.body.JointType.Builder<BodyType.Builder<_B>> light_Builder = new org.mujoco.xml.body.JointType.Builder<BodyType.Builder<_B>>(this, null, false);
496+
this.inertialOrJointOrFreejoint.add(light_Builder);
497+
return light_Builder;
498+
}
416499
/**
417500
* Adds the given items to the value of "inertialOrJointOrFreejoint"
418501
*

src/test/java/mujoco/java/XMLtest.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.*;
44

55
import java.io.File;
6+
import java.math.BigDecimal;
67
import java.util.Arrays;
78
import java.util.Iterator;
89

@@ -15,6 +16,8 @@
1516
import org.mujoco.MuJoCoXML;
1617
import org.mujoco.xml.Mujoco;
1718
import org.mujoco.xml.Mujoco.Builder;
19+
import org.mujoco.xml.attributetypes.CameramodeType;
20+
import org.mujoco.xml.attributetypes.GeomtypeType;
1821
import org.mujoco.xml.body.LightType;
1922

2023
import com.kscs.util.jaxb.BoundList;
@@ -29,20 +32,51 @@ public void marshal() throws JAXBException {
2932
builder.addActuator().addCylinder();
3033
builder.addActuator().addMotor();
3134
Mujoco.Worldbody.Builder<?> addWorldbody = builder.addWorldbody();
32-
BodyarchType.Builder<?> topbody = addWorldbody.addBody();
33-
topbody.withName("torso");
34-
topbody.withChildclass("body");
35-
topbody.withPos("0 0 1.282");
35+
addWorldbody.addGeom()
36+
.withName("floor")
37+
.withType(GeomtypeType.PLANE)
38+
.withCondim(3)
39+
.withSize("0 0 .05")
40+
.withMaterial("grid")
41+
;
42+
addWorldbody.addCamera();
3643

44+
addWorldbody.addLight()
45+
.withName("spotlight")
46+
.withMode(CameramodeType.TARGETBODYCOM)
47+
.withTarget("torso")
48+
.withPos("0 -6 4")
49+
.withCutoff(BigDecimal.valueOf(30))
50+
.withDiffuse(".8 .8 .8")
51+
.withSpecular(null)
52+
;
53+
BodyarchType.Builder<?> topbody = addWorldbody.addBody();
54+
topbody .withName("torso")
55+
.withChildclass("body")
56+
.withPos("0 0 1.282")
57+
.addGeom()
58+
.withName("torso")
59+
60+
;
61+
topbody.addLight()
62+
.withName("top")
63+
.withMode(CameramodeType.TRACKCOM)
64+
.withPos("0 0 2")
65+
;
66+
topbody.addCamera();
67+
topbody.addFreejoint().withName("root");
68+
3769
//topbody.addBody();
3870
// In the future if this test breaks after generating code, see the solution in
3971
// https://github.com/CommonWealthRobotics/mujoco-java/pull/6/commits/e8d65eeec490bb935111a99f5d049991735864c0
40-
topbody.addBody().withName("Head").withPos("0 0 2.2")
41-
.addBody()
42-
.withName("mowhawk")
43-
.withPos("0 0 1.2")
72+
topbody.addBody()
73+
.withName("Head")
74+
.withPos("0 0 2.2")
75+
.addBody()
76+
.withName("mowhawk")
77+
.withPos("0 0 1.2")
4478
;
45-
79+
topbody.addBody().withName("arm").withPos("0 1.1 0");
4680

4781
//topbody.addBody(topbody.ge);
4882
//org.mujoco.xml.BodyarchType.Builder<?> lightBuilder = topbody.addLight(element );

0 commit comments

Comments
 (0)