public void fixColor(double mu) {
   if (mu >= 0) {
     Node3D.setMaterial(getMaterial(Color.red), redShape);
     Node3D.setMaterial(getMaterial(Color.blue), blueShape);
   } else {
     Node3D.setMaterial(getMaterial(Color.blue), blueShape);
     Node3D.setMaterial(getMaterial(Color.blue), blueShape);
   }
 }
 public void read(JMEImporter e) throws IOException {
   super.read(e);
   InputCapsule capsule = e.getCapsule(this);
   float len = capsule.readFloat("mdlength", 1f);
   float rad = capsule.readFloat("mdradius", 0.2f);
   updateGeometry(len, rad);
 }
  public void updateGeometry(double length, double radius) {
    this.length = (float) length;
    this.radius = (float) radius;
    if (redShape == null) {
      redShape = new UprightCylinder();
      redShape.setName("red shape");

      redShape.setLocalTranslation(0, this.length * 0.375f, 0);
      this.attachChild(redShape);

      Node3D.setMaterial(getMaterial(Color.red), redShape);
    }

    if (blueShape == null) {
      blueShape = new UprightCylinder();
      blueShape.setName("blue shape");

      blueShape.setLocalTranslation(0, -this.length * 0.375f, 0);
      this.attachChild(blueShape);

      Node3D.setMaterial(getMaterial(Color.blue), blueShape);
    }

    if (centerShape == null) {
      centerShape = new UprightCylinder();
      centerShape.setName("center shape");
      this.attachChild(centerShape);

      TMaterial cMat = ColorUtil.getMaterial(Color.gray);
      cMat.setShininess(90f / 128f);
      Node3D.setMaterial(cMat, centerShape);
    }

    redShape.updateGeometry(4, 24, this.radius, this.radius, this.length / 4f, true, false);
    blueShape.updateGeometry(4, 24, this.radius, this.radius, this.length / 4f, true, false);
    centerShape.updateGeometry(4, 24, this.radius, this.radius, this.length / 2f, true, false);
  }
Exemple #4
0
  public WireNode(double len, double rad) {
    //		super(2);
    //
    //		setGeometry(0,Cylinder.makeGeometry(24,rad,len).getIndexedGeometryArray(),0);
    super();
    Shape3D wire = new Shape3D();
    initShape(wire);
    wire.setGeometry(Cylinder.makeGeometry(24, rad, len).getIndexedGeometryArray());
    Appearance app = Node3D.makeAppearance(new Color3f(new Color(154, 105, 0)), .8f, 0.5f, false);
    TransparencyAttributes ta =
        new TransparencyAttributes(
            TransparencyAttributes.NICEST, 0.5f); // app.getTransparencyAttributes();
    // ta.setTransparency(0.5f);
    app.setTransparencyAttributes(ta);
    wire.setAppearance(app);

    mContents.addChild(wire);

    //////////////////////////////////////////////////////////////////////
    /*
    txt = new Text2D("This is a Text2D!!", new Color3f(0.f,0.f,0.f),"SansSerif",70,Font.PLAIN);
    txt.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    txt.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    txt.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    txt.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    Appearance a = txt.getAppearance();
    a.setCapability(Appearance.ALLOW_TEXTURE_READ);
    a.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    txt.setAppearance(a);
    TransformGroup bbtg = new TransformGroup();
    bbtg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D t = new Transform3D();
    t.setScale(50.);
    bbtg.setTransform(t);
    bbtg.addChild(txt);
    Billboard bb = new Billboard(bbtg,Billboard.ROTATE_ABOUT_POINT,new Point3f(0.f,0.f,0.f));
    bb.setSchedulingBounds(new BoundingSphere(new Point3d(0.,0.,0.), 100.));
    bbtg.addChild(bb);
    mContents.addChild(bbtg);
    */
    ///////////////////////////////////////////////////////////////////////

    Shape3D line = new Shape3D();
    initShape(line);
    // line.setGeometry(sLine);
    Geometry stem =
        teal.render.j3d.geometry.Cylinder.makeGeometry(20, 0.05, 1, 0.5)
            .getIndexedGeometryArray(true);
    line.setGeometry(stem);

    Cone fatcone = new Cone(0.2f, 0.25f);
    Shape3D cone = new Shape3D();
    initShape(cone);
    cone.setGeometry(fatcone.getShape(Cone.BODY).getGeometry());
    cone.addGeometry(fatcone.getShape(Cone.CAP).getGeometry());

    TransformGroup translated_cone = new TransformGroup();
    Transform3D tran = new Transform3D();
    // tran.set( new Vector3f(0.f,0.95f,0.f));
    tran.set(new Vector3f(0.f, 1.f, 0.f));
    translated_cone.addChild(cone);
    translated_cone.setTransform(tran);

    arrow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    arrow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // arrow.addChild(line);
    // arrow.addChild(translated_cone);
    Appearance arrowAppearance =
        Node3D.makeAppearance(new Color3f(new Color(154, 105, 0)), 0.f, 0.f, false);
    line.setAppearance(arrowAppearance);
    cone.setAppearance(arrowAppearance);
    arrow.addChild(line);
    arrow.addChild(translated_cone);

    Transform3D tran2 = new Transform3D();
    // tran2.set(new Vector3f(0.f,-0.5f,0.f));
    tran2.setScale(4.);
    arrow.setTransform(tran2);
    mContents.addChild(arrow);
  }
 @Override
 protected void doSetElement(TAbstractRendered element, final boolean inRenderThread) {
   super.doSetElement(element, inRenderThread);
   if (element instanceof HasLength) length = (float) ((HasLength) element).getLength();
   if (element instanceof HasRadius) radius = (float) ((HasRadius) element).getRadius();
 }
 public void write(JMEExporter e) throws IOException {
   super.write(e);
   OutputCapsule capsule = e.getCapsule(this);
   capsule.write(length, "mdlength", 1f);
   capsule.write(radius, "mdradius", 0.2f);
 }