private void initWidget() {
    SceneApplication.getApplication().addSceneListener(this);
    Sphere sphMesh = new Sphere(32, 32, 2.5f);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 2.5f, false, false);
    TangentBinormalGenerator.generate(sphMesh);
    sphere = new Geometry("previewSphere", sphMesh);
    sphere.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_X));

    Box boxMesh = new Box(new Vector3f(0, 0, 0), 1.75f, 1.75f, 1.75f);
    TangentBinormalGenerator.generate(boxMesh);
    box = new Geometry("previewBox", boxMesh);
    box.setLocalRotation(
        new Quaternion()
            .fromAngleAxis(-FastMath.DEG_TO_RAD * 30, Vector3f.UNIT_X)
            .multLocal(new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Y)));

    Quad quadMesh = new Quad(4.5f, 4.5f);
    TangentBinormalGenerator.generate(quadMesh);
    quad = new Geometry("previewQuad", quadMesh);
    quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));

    currentGeom = sphere;
    sphereButton.setSelected(true);
    init = true;
  }
Esempio n. 2
0
 /**
  * Main constructor; builds a SphericalSprite from a {@link SpriteData} object
  *
  * @param sprite The sprite information to build from
  */
 public SphericalSprite(final SpriteData sprite) {
   aSpriteInfo = sprite;
   try {
     aMaterial = new SphericalMapped(aSpriteInfo.sprite);
     // Calling two times getHeight() because it's a sphere so it doesn't matter.
     // Width of texture is twice as long so it's faster to get the height than to get the width
     // and divide by 2
     final Quad q = new Quad(aMaterial.getHeight(), aMaterial.getHeight());
     final Geometry g =
         new Geometry("SphericalSprite-" + aSpriteInfo.sprite + " @ " + hashCode(), q);
     g.setMaterial(aMaterial);
     final EverNode image = new EverNode(g);
     addNode(image);
     // Offset image so that the origin is around the center of the image
     aSpriteTransform = image.getNewTransform();
     aSpriteTransform
         .translate(
             -aMaterial.getHeight() * aSpriteInfo.scale / 2 + aSpriteInfo.x,
             -aMaterial.getHeight() * aSpriteInfo.scale / 2 + aSpriteInfo.y)
         .commit();
     aSpriteTransform.setScale(aSpriteInfo.scale);
   } catch (final TextureException e) {
     // Do nothing; just a blank node
     aValidSprite = false;
     System.err.println("Warning: Could not load SphericalSprite! Info = " + aSpriteInfo);
   }
 }
 private static Geometry createDebugShape(CollisionShape shape) {
   Geometry geom = new Geometry();
   geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
   //        geom.setLocalScale(shape.getScale());
   geom.updateModelBound();
   return geom;
 }
Esempio n. 4
0
  /**
   * Creates the default axes, which are lines of different colors from the origin to the unit
   * vectors. These are attached to the Node {@link #axes}.
   */
  protected void initAxes() {

    Geometry geometry;
    Line line;
    float lineWidth = 3f;

    // Create the x axis as a red line of unit length.
    line = new Line(Vector3f.ZERO, Vector3f.UNIT_X);
    line.setLineWidth(lineWidth);
    geometry = new Geometry("x", line);
    geometry.setMaterial(materials.get("XAxis"));
    axes.attachChild(geometry);

    // Create the y axis as a green line of unit length.
    line = new Line(Vector3f.ZERO, Vector3f.UNIT_Y);
    line.setLineWidth(lineWidth);
    geometry = new Geometry("y", line);
    geometry.setMaterial(materials.get("YAxis"));
    axes.attachChild(geometry);

    // Create the z axis as a blue line of unit length.
    line = new Line(Vector3f.ZERO, Vector3f.UNIT_Z);
    line.setLineWidth(lineWidth);
    geometry = new Geometry("z", line);
    geometry.setMaterial(materials.get("ZAxis"));
    axes.attachChild(geometry);

    return;
  }
  // debug function that create a displayable frustrum
  protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
      case 0:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
        break;
      case 1:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
        break;
      case 2:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
        break;
      case 3:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
        break;
      default:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
        break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
  }
  private void displayPlayersPositions() {
    Map<Vector3f, Integer> playerPositions = gm.getMapManager().getBoard().getPlayerPositions();

    Iterator it = playerPositions.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      Vector3f pos = (Vector3f) pairs.getKey();
      Integer number = (Integer) pairs.getValue();

      Box b = new Box(Vector3f.ZERO, 2.0f, 1.0f, 2.0f);
      Geometry geom = new Geometry("Box", b);
      Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setColor("Color", ColorRGBA.randomColor());

      geom.setMaterial(mat);
      geom.setLocalTranslation(pos.x, 0, pos.z);

      String geomName = "PLAYERMARKER";
      geom.setName(geomName);
      geom.setUserData(geomName, pos);

      playerNodes.attachChild(geom);

      displayLocationName(number.toString(), new Vector3f(pos.x, 1, pos.z));
    }
  }
Esempio n. 7
0
  @Override
  public void simpleInitApp() {

    /** create a blue box at coordinates (1,-1,1) */
    Box box1 = new Box(new Vector3f(1, -1, 1), 1, 1, 1);
    Geometry blue = new Geometry("Box", box1);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
    mat1.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat1);

    /** create a red box straight above the blue one at (1,3,1) */
    Box box2 = new Box(new Vector3f(1, 3, 1), 1, 1, 1);
    Geometry red = new Geometry("Box", box2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
    mat2.setColor("Color", ColorRGBA.Red);
    red.setMaterial(mat2);

    /** Create a pivot node at (0,0,0) and attach it to the root node */
    Node pivot = new Node("pivot");
    rootNode.attachChild(pivot); // put this node in the scene

    /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
    pivot.attachChild(blue);
    pivot.attachChild(red);
    /** Rotate the pivot node: Note that both boxes have rotated! */
    pivot.rotate(.4f, .4f, 0f);
  }
 /**
  * Returns a player base geometry.
  *
  * @param basevec - Local translation for base.
  * @param basescale - Local scale for base.
  * @return
  */
 public Geometry getBase(Vector3f basevec, Vector3f basescale) {
   Geometry base_geom = new Geometry("Base", new Box(1, 1, 1));
   base_geom.setMaterial(bs.getMaterial("Base"));
   base_geom.setLocalScale(basescale);
   base_geom.setLocalTranslation(basevec);
   return base_geom;
 }
Esempio n. 9
0
  @Override
  public void simpleInitApp() {
    // add a random cube
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.randomColor());
    geom.setMaterial(mat);
    geom.move(
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * 10) - 5,
        (FastMath.nextRandomFloat() * -10));
    rootNode.attachChild(geom);

    // add saved cubes
    String userHome = System.getProperty("user.home");
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);
    try {
      File file = new File(userHome + "/mycoolgame/savedgame.j3o");
      Node sceneNode = (Node) importer.load(file);
      sceneNode.setName("My restored node");
      rootNode.attachChild(sceneNode);
      Logger.getLogger(SaveAndLoad.class.getName()).log(Level.INFO, "Success: Loaded saved node.");
    } catch (IOException ex) {
      Logger.getLogger(SaveAndLoad.class.getName())
          .log(Level.INFO, "Warning: Could not load saved node.", ex);
    }
  }
Esempio n. 10
0
  @Override
  public void simpleInitApp() {
    JmeCanvasContext ctx = (JmeCanvasContext) getContext();
    gui = new GUI(this, ctx.getCanvas());
    gui.show();

    flyCam.setEnabled(false);
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);

    rootNode.attachChild(geom);

    cinematic = new Cinematic(rootNode, 5);
    MotionPath path = new MotionPath();
    path.addWayPoint(Vector3f.ZERO.clone());
    path.addWayPoint(new Vector3f(10, 0, 0));
    MotionEvent motionEvent = new MotionEvent(geom, path, 5);
    cinematic.addCinematicEvent(0, motionEvent);
    cinematic.fitDuration();
    cinematic.setLoopMode(LoopMode.Loop);
    stateManager.attach(cinematic);
  }
  @Override
  public void simpleUpdate(float tpf) {
    Vector3f intersection = getWorldIntersection();
    updateHintText(intersection);

    if (raiseTerrain) {

      if (intersection != null) {
        adjustHeight(intersection, 64, tpf * 60);
      }
    } else if (lowerTerrain) {
      if (intersection != null) {
        adjustHeight(intersection, 64, -tpf * 60);
      }
    }

    if (terrain != null && intersection != null) {
      float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
      Vector3f tl = terrain.getWorldTranslation();
      marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
      markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));

      Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
      ((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
    }
  }
  public void UserJoin(HostedConnection source, Message message) {
    boolean bfound = false;

    // SMObjectShare SMObjshare = (SMObjectShare)smobj;

    for (SMObjectPlayerController player : players) {
      if (source.getId() == Integer.parseInt(player.smobjshare.userid)) {
        SMObjectShare shareobject = (SMObjectShare) message;
        player.smobjshare = shareobject;
        // player.getSpatial().setLocalTranslation(shareobject.x, shareobject.y, shareobject.z);
        bfound = true;
      }
    }

    if (!bfound) {
      Box objplayer = new Box(Vector3f.ZERO, 1, 1, 1);
      Geometry geomplayer = new Geometry("Box", objplayer);
      Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setColor("m_Color", ColorRGBA.Brown);
      geomplayer.setMaterial(mat);
      Spatial spl = (Spatial) geomplayer;

      SMObjectPlayerController newplayer = new SMObjectPlayerController(spl);
      newplayer.smobjshare = new SMObjectShare();
      newplayer.smobjshare.userid = Integer.toString(source.getId());
      newplayer.smobjshare.userid = Integer.toString(source.getId());

      source.send(newplayer.smobjshare);
      rootNode.attachChild(newplayer.getSpatial());
      players.add(newplayer);
    }
  }
Esempio n. 13
0
  @Override
  public void simpleUpdate(float tpf) {
    Juggernaut.Update(tpf);
    // Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
    //        walkDirection.set( 0, 0, 0);
    //        if(left)    { walkDirection.addLocal(Vector3f.UNIT_X.negate().multLocal(0.4f));}
    //        if(right)   { walkDirection.addLocal(Vector3f.UNIT_X.clone().multLocal(0.4f));}
    //        player.setWalkDirection(walkDirection);
    //        if( walkDirection != Vector3f.ZERO){
    //            player.setViewDirection(walkDirection.negate());
    //        }
    //
    //        playerDebug.setLocalTranslation(player.getPhysicsLocation());
    elevator1.setLocalTranslation(304 + 20 * FastMath.cos(timer.getTimeInSeconds()), 20, 0);
    elvtr1.setPhysicsLocation(elevator1.getLocalTranslation());

    //        elevator2.setLocalTranslation( 192, 208 + 35*FastMath.cos(timer.getTimeInSeconds()),
    // 0);
    //        elvtr2.setPhysicsLocation(elevator2.getLocalTranslation());
    elvtr2.setLinearVelocity(new Vector3f(0, 25 * FastMath.cos(timer.getTimeInSeconds()), 0));
    elvtr2.setPhysicsRotation(Matrix3f.IDENTITY);
    System.out.print(landscape.getCollideWithGroups() + "\n");

    for (int i = 0; i < views.length; i++) {
      if (views[i].testForPlayer(Juggernaut)) {
        currentView = views[i];
      }
    }

    cam.setLocation(currentView.CamPosition());
    cam.lookAt(currentView.CamLookAt(), Vector3f.UNIT_Y);
  }
Esempio n. 14
0
  /**
   * Generate a collision shape for a prop.
   *
   * @param propType the type of the prop (not null)
   * @param relativeSize the prop's size relative to standard (&gt;0)
   * @param parts (not null)
   * @return a new instance
   */
  private CollisionShape createShape(String propType, float relativeSize, List<Spatial> parts) {
    assert propType != null;
    assert relativeSize > 0f : relativeSize;
    assert parts != null;
    assert !parts.isEmpty();

    if ("barrel".equals(propType)) {
      /*
       * Generate a cylindrical shape aligned with the Y-axis.
       */
      float halfHeight = 0.5f * relativeSize; // meters
      float radius = 0.472f * relativeSize; // meters
      Vector3f halfExtents = new Vector3f(radius, halfHeight, radius);
      float scaleFactor = scene.getScaleFactor();
      halfExtents.divideLocal(scaleFactor);
      CollisionShape shape = new CylinderCollisionShape(halfExtents, PhysicsSpace.AXIS_Y);
      return shape;
    }
    /*
     * Generate a compound shape composed of GImpact shapes,
     * one for each geometry.
     */
    CompoundCollisionShape shape = new CompoundCollisionShape();
    for (Spatial part : parts) {
      Geometry geometry = (Geometry) part;
      Mesh mesh = geometry.getMesh();
      CollisionShape partShape = new GImpactCollisionShape(mesh);
      Vector3f scale = part.getWorldScale();
      partShape.setScale(scale);
      shape.addChildShape(partShape, Vector3f.ZERO);
    }
    return shape;
  }
 private void attachRandomGeometry(Node node, Material mat) {
   Box box = new Box(0.25f, 0.25f, 0.25f);
   Torus torus = new Torus(16, 16, 0.2f, 0.8f);
   Geometry[] boxes =
       new Geometry[] {
         new Geometry("box1", box),
         new Geometry("box2", box),
         new Geometry("box3", box),
         new Geometry("torus1", torus),
         new Geometry("torus2", torus),
         new Geometry("torus3", torus)
       };
   for (int i = 0; i < boxes.length; i++) {
     Geometry geometry = boxes[i];
     geometry.setLocalTranslation(
         (float) Math.random() * 10 - 10,
         (float) Math.random() * 10 - 10,
         (float) Math.random() * 10 - 10);
     geometry.setLocalRotation(
         new Quaternion()
             .fromAngles(
                 (float) Math.random() * FastMath.PI,
                 (float) Math.random() * FastMath.PI,
                 (float) Math.random() * FastMath.PI));
     geometry.setLocalScale(
         (float) Math.random() * 10 - 10,
         (float) Math.random() * 10 - 10,
         (float) Math.random() * 10 - 10);
     geometry.setMaterial(mat);
     node.attachChild(geometry);
   }
 }
  @Override
  public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    createMaterial();

    Node node = new Node("node1");
    attachRandomGeometry(node, mat1);
    randomizeTransform(node);

    Node node2 = new Node("node2");
    attachRandomGeometry(node2, mat2);
    randomizeTransform(node2);

    node.attachChild(node2);
    rootNode.attachChild(node);

    RigidBodyControl control = new RigidBodyControl(0);
    node.addControl(control);
    getPhysicsSpace().add(control);

    // test single geometry too
    Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
    myGeom.setMaterial(mat3);
    randomizeTransform(myGeom);
    rootNode.attachChild(myGeom);
    RigidBodyControl control3 = new RigidBodyControl(0);
    myGeom.addControl(control3);
    getPhysicsSpace().add(control3);
  }
Esempio n. 17
0
  @Override
  @SuppressWarnings("unchecked")
  public Node apply(Node node, BlenderContext blenderContext) {
    if (invalid) {
      LOGGER.log(
          Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName());
    } // if invalid, animData will be null
    if (animData == null) {
      return node;
    }

    // setting weights for bones
    List<Geometry> geomList =
        (List<Geometry>)
            blenderContext.getLoadedFeature(this.meshOMA, LoadedFeatureDataType.LOADED_FEATURE);
    for (Geometry geom : geomList) {
      Mesh mesh = geom.getMesh();
      if (this.verticesWeights != null) {
        mesh.setMaxNumWeights(this.boneGroups);
        mesh.setBuffer(this.verticesWeights);
        mesh.setBuffer(this.verticesWeightsIndices);
      }
    }

    ArrayList<Animation> animList = animData.anims;
    if (animList != null && animList.size() > 0) {
      List<Constraint> constraints = blenderContext.getConstraints(this.armatureObjectOMA);
      HashMap<String, Animation> anims = new HashMap<String, Animation>();
      for (int i = 0; i < animList.size(); ++i) {
        Animation animation = (Animation) animList.get(i).clone();

        // baking constraints into animations
        if (constraints != null && constraints.size() > 0) {
          for (Constraint constraint : constraints) {
            Long boneOMA = constraint.getBoneOMA();
            Bone bone =
                (Bone)
                    blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
            int targetIndex =
                bone == null
                    ? 0
                    : animData.skeleton.getBoneIndex(
                        bone); // bone==null may mean the object animation
            constraint.affectAnimation(animation, targetIndex);
          }
        }

        anims.put(animation.getName(), animation);
      }

      // applying the control to the node
      SkeletonControl skeletonControl = new SkeletonControl(animData.skeleton);
      AnimControl control = new AnimControl(animData.skeleton);

      control.setAnimations(anims);
      node.addControl(control);
      node.addControl(skeletonControl);
    }
    return node;
  }
Esempio n. 18
0
  Node createDebugGeometry() {
    Line l = new Line(from.getPlanet().getPosition(), to.getPlanet().getPosition());

    line = new Geometry("Line #" + from.getPlanet().getID() + " to #" + to.getPlanet().getID(), l);

    Material material =
        new Material(
            SolarWarsApplication.getInstance().getAssetManager(),
            "Common/MatDefs/Misc/Unshaded.j3md");

    Player p = from.getPlanet().getOwner();
    ColorRGBA c;
    if (p == null) {
      c = ColorRGBA.White.clone();
      c.a = 0.5f;
      material.setColor("Color", c);
    } else {
      c = p.getColor();
      c.a = 0.5f;
      material.setColor("Color", c);
    }
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    line.setMaterial(material);

    createLabel();
    Node lineNode = new Node(line.getName() + "_Node");
    lineNode.attachChild(line);
    lineNode.attachChild(label);
    //        Vector3f pos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //        lineNode.setLocalTranslation(pos.mult(0.5f));
    return lineNode;
  }
 /**
  * Creates a quad with the water material applied to it.
  *
  * @param width
  * @param height
  * @return
  */
 public Geometry createWaterGeometry(float width, float height) {
   Quad quad = new Quad(width, height);
   Geometry geom = new Geometry("WaterGeometry", quad);
   geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
   geom.setMaterial(material);
   return geom;
 }
  public static void makeLods(Collection<Geometry> geometries, Mesh outMesh) {
    // Determine number of LOD levels required.
    int lodLevels = Integer.MAX_VALUE;
    for (Geometry g : geometries) {
      lodLevels = Math.min(lodLevels, g.getMesh().getNumLodLevels());
    }
    if (lodLevels == Integer.MAX_VALUE || lodLevels == 0) {
      // No LOD on any of the meshes.
      return;
    }

    // Sizes of the final LOD index buffers for each level.
    int[] lodSizes = new int[lodLevels];
    for (Geometry g : geometries) {
      for (int i = 0; i < lodLevels; i++) {
        lodSizes[i] += g.getMesh().getLodLevel(i).getData().limit();
      }
    }

    // final LOD buffers for each LOD level.
    IndexBuffer[] lods = new IndexBuffer[lodLevels];
    int bufferPos[] = new int[lodLevels];
    int numOfVertices = 0;
    int curGeom = 0;

    //        int components = compsForBuf[bufType];
    //        for (int tri = 0; tri < geomTriCount; tri++) {
    //            for (int comp = 0; comp < components; comp++) {
    //                int idx = inIdx.get(tri * components + comp) + globalVertIndex;
    //                outIdx.put((globalTriIndex + tri) * components + comp, idx);
    //            }
    //        }

    for (int lodLevel = 0; lodLevel < lodLevels; lodLevel++) {}

    //        for (Geometry g : geometries) {
    //            if (numOfVertices == 0) {
    //                numOfVertices = g.getVertexCount();
    //            }
    //            for (int i = 0; i < lodLevels; i++) {
    //                IndexBuffer buffer =
    // IndexBuffer.wrapIndexBuffer(g.getMesh().getLodLevel(i).getData());
    //                //System.out.println("buffer: " + buffer.capacity() + " limit: " + lodSize[i]
    // + " " + index);
    //                for (int j = 0; j < buffer.size(); j++) {
    //                    lodData[i][bufferPos[i] + j] = buffer.get(j) + numOfVertices * curGeom;
    //                    //bufferPos[i]++;
    //                }
    //                bufferPos[i] += buffer.size();
    //            }
    //            curGeom++;
    //        }
    //        for (int i = 0; i < lodLevels; i++) {
    //            lods[i] = new VertexBuffer(Type.Index);
    //            lods[i].setupData(Usage.Dynamic, 1, Format.UnsignedInt,
    // BufferUtils.createIntBuffer(lodData[i]));
    //        }
    //        outMesh.setLodLevels(lods);
  }
Esempio n. 21
0
 /** A cube object for target practice */
 protected Geometry makeCube(String name, float x, float y, float z) {
   Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);
   Geometry cube = new Geometry(name, box);
   Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat1.setColor("Color", ColorRGBA.randomColor());
   cube.setMaterial(mat1);
   return cube;
 }
Esempio n. 22
0
 /** A floor to show that the "shot" can go through several objects. */
 protected Geometry makeFloor() {
   Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);
   Geometry floor = new Geometry("the Floor", box);
   Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   mat1.setColor("Color", ColorRGBA.Gray);
   floor.setMaterial(mat1);
   return floor;
 }
Esempio n. 23
0
 private Geometry putShape(SimpleApplication game, Mesh shape, ColorRGBA color) {
   Geometry g = new Geometry("coordinate axis", shape);
   Material mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
   mat.getAdditionalRenderState().setWireframe(true);
   mat.setColor("Color", color);
   g.setMaterial(mat);
   game.getRootNode().attachChild(g);
   return g;
 }
Esempio n. 24
0
  private void setupEnvironments() {
    // カメラ設定
    cam.setFrustumPerspective(80f, 1f, 1f, 1000f);
    cam.setLocation(new Vector3f(0, 1.5f, 10));
    // cam.lookAt(new Vector3f(0, 1.6f, 0), Vector3f.UNIT_Y);
    flyCam.setDragToRotate(true);

    // ライティング
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.mult(3.0f));
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);

    // マテリアル設定
    Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg"));
    Material whitemat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");

    // 床面
    Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(textureMat);
    floorGeom.setLocalTranslation(0, 0, 0);
    rootNode.attachChild(floorGeom);

    // 壁面
    wallGeom[0] = new Geometry("Wall1", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[1] = new Geometry("Wall2", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[2] = new Geometry("Wall3", new Box(Vector3f.ZERO, 20f, 4f, 0.1f));
    wallGeom[0].setMaterial(whitemat);
    wallGeom[1].setMaterial(whitemat);
    wallGeom[2].setMaterial(whitemat);
    wallGeom[0].setLocalTranslation(0, 4, -2);
    wallGeom[1].setLocalTranslation(-20, 4, 0);
    wallGeom[2].setLocalTranslation(20, 4, 0);
    wallGeom[1].rotate(0, (float) (Math.PI / 2f), 0);
    wallGeom[2].rotate(0, (float) (Math.PI / 2f), 0);
    rootNode.attachChild(wallGeom[0]);
    rootNode.attachChild(wallGeom[1]);
    rootNode.attachChild(wallGeom[2]);

    // 女性をランダムに追加
    for (int i = 0; i < girl.length; i++) {
      girl[i] = assetManager.loadModel("myAssets/Models/WalkingGirl/WalkingGirl.obj");
      girlPos[i] =
          new Vector3f((float) (Math.random() * 16.0f - 8f), 0, (float) (Math.random() * 8f));
      // 移動スピードをランダムに
      girlSpeed[i] = (float) (Math.random() * -0.02f) + 0.01f;
      if (girlSpeed[i] < 0) {
        girl[i].rotate(0, (float) (-Math.PI / 2.0f), 0);
      } else {
        girl[i].rotate(0, (float) (Math.PI / 2.0f), 0);
      }
      girl[i].setLocalTranslation(girlPos[i]);
      this.rootNode.attachChild(girl[i]);
    }
  }
Esempio n. 25
0
  private void initBox() {
    Box b = new Box(1, 1, 1);
    Geometry blue = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat);

    /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
    rootNode.attachChild(blue);
  }
  private void setupBox() {
    Box boxshape1 = new Box(new Vector3f(-3f, 1.1f, 0f), 1f, 1f, 1f);
    Geometry cube = new Geometry("My Textured Box", boxshape1);
    Material mat_stl = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex_ml = app.getAssetManager().loadTexture("Textures/test.png");
    mat_stl.setTexture("ColorMap", tex_ml);
    cube.setMaterial(mat_stl);

    app.getRootNode().attachChild(cube);
  }
  @Override
  public void simpleUpdate(float tpf) {
    Quaternion q = new Quaternion();
    angle += tpf;
    angle %= FastMath.TWO_PI;
    q.fromAngles(angle, 0, angle);

    offBox.setLocalRotation(q);
    offBox.updateLogicalState(tpf);
    offBox.updateGeometricState();
  }
 private int computeNbTri() {
   int nbTri = 0;
   for (Geometry geometry : listGeoms) {
     if (geometry.getMesh().getNumLodLevels() > 0) {
       nbTri += geometry.getMesh().getLodLevel(lodLevel).getNumElements();
     } else {
       nbTri += geometry.getMesh().getTriangleCount();
     }
   }
   return nbTri;
 }
Esempio n. 29
0
 /** Make a solid floor and add it to the scene. */
 public void initFloor() {
   Geometry floor_geo = new Geometry("Floor", floor);
   floor_geo.setMaterial(floor_mat);
   floor_geo.setShadowMode(ShadowMode.Receive);
   floor_geo.setLocalTranslation(0, -0.1f, 0);
   this.rootNode.attachChild(floor_geo);
   /* Make the floor physical with mass 0.0f! */
   floor_phy = new RigidBodyControl(0.0f);
   floor_geo.addControl(floor_phy);
   bulletAppState.getPhysicsSpace().add(floor_phy);
 }
Esempio n. 30
0
 /**
  * Populates the outputGeometryList with the geometry of the inputGeomtryList that are in the
  * frustum of the given camera
  *
  * @param inputGeometryList The list containing all geometry to check against the camera frustum
  * @param camera the camera to check geometries against
  * @param outputGeometryList the list of all geometries that are in the camera frustum
  */
 public static void getGeometriesInCamFrustum(
     GeometryList inputGeometryList, Camera camera, GeometryList outputGeometryList) {
   for (int i = 0; i < inputGeometryList.size(); i++) {
     Geometry g = inputGeometryList.get(i);
     int planeState = camera.getPlaneState();
     camera.setPlaneState(0);
     if (camera.contains(g.getWorldBound()) != Camera.FrustumIntersect.Outside) {
       outputGeometryList.add(g);
     }
     camera.setPlaneState(planeState);
   }
 }