private static Geometry createDebugShape(CollisionShape shape) {
   Geometry geom = new Geometry();
   geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
   //        geom.setLocalScale(shape.getScale());
   geom.updateModelBound();
   return geom;
 }
  private void createMarker() {
    // collision marker
    Sphere sphere = new Sphere(8, 8, 0.5f);
    marker = new Geometry("Marker");
    marker.setMesh(sphere);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.6f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    marker.setMaterial(mat);
    rootNode.attachChild(marker);

    // surface normal marker
    Arrow arrow = new Arrow(new Vector3f(0, 1, 0));
    markerNormal = new Geometry("MarkerNormal");
    markerNormal.setMesh(arrow);
    markerNormal.setMaterial(mat);
    rootNode.attachChild(markerNormal);
  }
Example #3
0
  @Override
  protected void initState() {
    main.getInputManager().addRawInputListener(this);
    if (!init) {
      main.getInputManager().deleteMapping("FLYCAM_RotateDrag");
      main.getInputManager()
          .addMapping("FLYCAM_RotateDrag", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
      main.getInputManager().addListener(main.getFlyByCamera(), "FLYCAM_RotateDrag");

      objIcons = main.getAssetManager().loadTexture("Textures/Spatials/ObjIcons.png");

      initCtrlPanel();

      obj1Node =
          new InteractiveNode(screen) {
            @Override
            public void onSpatialMouseDown(MouseButtonEvent evt) {
              handleObjectClick(this);
              evt.setConsumed();
            }

            @Override
            public void onSpatialMouseUp(MouseButtonEvent evt) {
              evt.setConsumed();
            }
          };
      obj1Node.setName("Box");
      Box obj1 = new Box(1, 1, 1);
      Geometry obj1Geom = new Geometry();
      obj1Geom.setMesh(obj1);
      obj1Node.attachChild(obj1Geom);
      obj1Node.setIcon("x=0|y=0|w=64|h=64");
      obj1Node.setDefaultMaterial(getMaterial(ColorRGBA.Blue));
      obj1Node.setHighlightMaterial(getMaterial(new ColorRGBA(0.5f, 0.5f, 1f, 1f)));
      obj1Node.setToolTipText("I'm a Box\n\nPick me up and put\nme in your inventory.");
      obj1Node.setLocalTranslation(-3, 0, 0);

      obj2Node =
          new InteractiveNode(screen) {
            @Override
            public void onSpatialMouseDown(MouseButtonEvent evt) {
              handleObjectClick(this);
              evt.setConsumed();
            }

            @Override
            public void onSpatialMouseUp(MouseButtonEvent evt) {
              evt.setConsumed();
            }
          };
      obj2Node.setName("Sphere");
      Sphere obj2 = new Sphere(8, 8, 1f);
      Geometry obj2Geom = new Geometry();
      obj2Geom.setMesh(obj2);
      obj2Node.attachChild(obj2Geom);
      obj2Node.setIcon("x=64|y=0|w=64|h=64");
      obj2Node.setDefaultMaterial(getMaterial(ColorRGBA.Red));
      obj2Node.setHighlightMaterial(getMaterial(new ColorRGBA(1f, 0.5f, 0.5f, 1f)));
      obj2Node.setToolTipText("I'm a Sphere\n\nPick me up and put\nme in your inventory.");
      obj2Node.setLocalTranslation(0, 0, 0);

      obj3Node =
          new InteractiveNode(screen) {
            @Override
            public void onSpatialMouseDown(MouseButtonEvent evt) {
              handleObjectClick(this);
              evt.setConsumed();
            }

            @Override
            public void onSpatialMouseUp(MouseButtonEvent evt) {
              evt.setConsumed();
            }
          };
      obj3Node.setName("Torus");
      Torus obj3 = new Torus(8, 8, 0.5f, 1f);
      Geometry obj3Geom = new Geometry();
      obj3Geom.setMesh(obj3);
      obj3Node.attachChild(obj3Geom);
      obj3Node.setIcon("x=0|y=64|w=64|h=64");
      obj3Node.setDefaultMaterial(getMaterial(ColorRGBA.Green));
      obj3Node.setHighlightMaterial(getMaterial(new ColorRGBA(0.5f, 1f, 0.5f, 1f)));
      obj3Node.setToolTipText("I'm a Torus\n\nPick me up and put\nme in your inventory.");
      obj3Node.setLocalTranslation(3, 0, 0);

      cursor =
          new ButtonAdapter(
              screen,
              UIDUtil.getUID(),
              Vector2f.ZERO,
              new Vector2f(iconSize, iconSize),
              Vector4f.ZERO,
              null) {
            @Override
            public void update(float tpf) {
              setPosition(screen.getMouseXY().x + 25, screen.getMouseXY().y - 50);
            }
          };
      cursor.setIsEnabled(false);
      cursor.setInterval(1);
      cursor.setTextureAtlasImage(objIcons, iconDefault);
      cursor.setIsModal(true);
      cursor.setIsGlobalModal(true);
      cursor.setEffectZOrder(false);
      cursor.setIgnoreMouse(true);

      init = true;
    }
    screen.setUse3DSceneSupport(true);
    main.getTests().addCtrlPanel(cPanel);
    if (obj1Node.getIsInScene()) main.getRootNode().attachChild(obj1Node);
    if (obj2Node.getIsInScene()) main.getRootNode().attachChild(obj2Node);
    if (obj3Node.getIsInScene()) main.getRootNode().attachChild(obj3Node);
    screen.addElement(cursor);
    cursor.move(0, 0, 20);
    main.addSceneLights();
  }