com.jme3.scene.shape.Box类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中com.jme3.scene.shape.Box类的一些代码示例,展示了Box类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Box类的具体详情如下:
包路径:com.jme3.scene.shape.Box
类名称:Box

Box介绍

[英]A box with solid (filled) faces.
[中]具有实心(填充)面的长方体。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Creates a clone of this box.
 * <p>
 * The cloned box will have '_clone' appended to its name, but all other
 * properties will be the same as this box.
 */
@Override
public Box clone() {
  return new Box(center.clone(), xExtent, yExtent, zExtent);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Set the collision shape based on the controlled spatial and its
 * descendents.
 */
protected void createCollisionShape() {
  if (spatial == null) {
    return;
  }
  if (spatial instanceof Geometry) {
    Geometry geom = (Geometry) spatial;
    Mesh mesh = geom.getMesh();
    if (mesh instanceof Sphere) {
      collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
      return;
    } else if (mesh instanceof Box) {
      collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
      return;
    }
  }
  if (mass > 0) {
    collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
  } else {
    collisionShape = CollisionShapeFactory.createMeshShape(spatial);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

rootNode.addLight(dl);
Box box = new Box(1, 1, 1);
indicesHW.setUsage(Usage.CpuOnly);
weightsHW.setUsage(Usage.CpuOnly);
box.setBuffer(weightsHW);
box.setBuffer(indicesHW);
FloatBuffer weights = FloatBuffer.allocate( box.getVertexCount() * 4 );
VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight);
weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights);
box.setBuffer(weightsBuf);
ByteBuffer indices = ByteBuffer.allocate( box.getVertexCount() * 4 );
VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex);
indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices);
box.setBuffer(indicesBuf);
box.generateBindPose();
for (int i = 0; i < box.getVertexCount() * 4; i += 4){
box.setMaxNumWeights(1);

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected void doUpdateGeometryIndices() {
  if (getBuffer(Type.Index) == null){
    setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(GEOMETRY_INDICES_DATA));
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected void doUpdateGeometryVertices() {
  FloatBuffer fpb = BufferUtils.createVector3Buffer(24);
  Vector3f[] v = computeVertices();
  fpb.put(new float[] {
      v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back
      v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right
      v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front
      v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left
      v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top
      v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z  // bottom
  });
  setBuffer(Type.Position, 3, fpb);
  updateBound();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private void createWall() {
  float xOff = -144;
  float zOff = -40;
  float startpt = bLength / 4 - xOff;
  float height = 6.1f;
  brick = new Box(bLength, bHeight, bWidth);
  brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
  for (int j = 0; j < 15; j++) {
    for (int i = 0; i < 4; i++) {
      Vector3f vt = new Vector3f(i * bLength * 2 + startpt, bHeight + height, zOff);
      addBrick(vt);
    }
    startpt = -startpt;
    height += 1.01f * bHeight;
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
  public void onAction(String name, boolean isPressed, float tpf) {
    if (name.equals("change") && isPressed) {
      box.setBuffer(VertexBuffer.Type.MorphTarget0, 3, target2.getBuffer(VertexBuffer.Type.Position));
    }
  }
}, "change");

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void setupFloor() {
  Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
  Box floor = new Box(50, 1f, 50);
  TangentBinormalGenerator.generate(floor);
  floor.scaleTextureCoordinates(new Vector2f(5, 5));
  Geometry floorGeom = new Geometry("Floor", floor);
  floorGeom.setMaterial(mat);
  floorGeom.setShadowMode(ShadowMode.Receive);
  rootNode.attachChild(floorGeom);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected void doUpdateGeometryNormals() {
  if (getBuffer(Type.Normal) == null){
    setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(GEOMETRY_NORMALS_DATA));
  }
}

代码示例来源:origin: org.jmonkeyengine/jme3-core

protected void duUpdateGeometryVertices() {
  FloatBuffer fpb = BufferUtils.createVector3Buffer(24);
  Vector3f[] v = computeVertices();
  fpb.put(new float[] {
      v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back
      v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right
      v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front
      v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left
      v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top
      v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z  // bottom
  });
  setBuffer(Type.Position, 3, fpb);
  updateBound();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void initialize(){
  super.initialize();
  System.out.println("Initialize");
  // create a box
  boxGeom = new Geometry("Box", new Box(2, 2, 2));
  // load some default material
  boxGeom.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m"));
  // attach box to display in primary viewport
  viewPort.attachScene(boxGeom);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void setupFloor(){
  Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
  Box floor = new Box(50, 1f, 50);
  TangentBinormalGenerator.generate(floor);
  floor.scaleTextureCoordinates(new Vector2f(5, 5));
  Geometry floorGeom = new Geometry("Floor", floor);
  floorGeom.setMaterial(mat);
  floorGeom.setShadowMode(ShadowMode.Receive);
  rootNode.attachChild(floorGeom);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Set the collision shape based on the controlled spatial and its
 * descendents.
 */
protected void createCollisionShape() {
  if (spatial == null) {
    return;
  }
  if (spatial instanceof Geometry) {
    Geometry geom = (Geometry) spatial;
    Mesh mesh = geom.getMesh();
    if (mesh instanceof Sphere) {
      collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
      return;
    } else if (mesh instanceof Box) {
      collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
      return;
    }
  }
  if (mass > 0) {
    collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
  } else {
    collisionShape = CollisionShapeFactory.createMeshShape(spatial);
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected void doUpdateGeometryTextures() {
  if (getBuffer(Type.TexCoord) == null){
    setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
  }
}

代码示例来源:origin: info.projectkyoto/mms-engine

protected void duUpdateGeometryVertices() {
  FloatBuffer fpb = BufferUtils.createVector3Buffer(24);
  Vector3f[] v = computeVertices();
  fpb.put(new float[] {
      v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, // back
      v[1].x, v[1].y, v[1].z, v[4].x, v[4].y, v[4].z, v[6].x, v[6].y, v[6].z, v[2].x, v[2].y, v[2].z, // right
      v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[7].x, v[7].y, v[7].z, v[6].x, v[6].y, v[6].z, // front
      v[5].x, v[5].y, v[5].z, v[0].x, v[0].y, v[0].z, v[3].x, v[3].y, v[3].z, v[7].x, v[7].y, v[7].z, // left
      v[2].x, v[2].y, v[2].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z, v[3].x, v[3].y, v[3].z, // top
      v[0].x, v[0].y, v[0].z, v[5].x, v[5].y, v[5].z, v[4].x, v[4].y, v[4].z, v[1].x, v[1].y, v[1].z  // bottom
  });
  setBuffer(Type.Position, 3, fpb);
  updateBound();
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void randomGenerator() {
  for (int i = startAt; i < maxCubes - 1; i++) {
    randomize();
    Geometry box = new Geometry("Box" + i, new Box(1, 1, 1));
    box.setLocalTranslation(new Vector3f(xPosition.get(xPosition.size() - 1),
        yPosition.get(yPosition.size() - 1),
        zPosition.get(zPosition.size() - 1)));
    batchNode.attachChild(box);
    if (i < 500) {
      box.setMaterial(mat1);
    } else if (i < 1000) {
      box.setMaterial(mat2);
    } else if (i < 1500) {
      box.setMaterial(mat3);
    } else {
      box.setMaterial(mat4);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

protected Geometry makeFloor() {
  Box box = new Box(220, .2f, 220);
  box.scaleTextureCoordinates(new Vector2f(10, 10));
  Geometry floor = new Geometry("the Floor", box);
  floor.setLocalTranslation(200, -9, 200);
  Material matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
  grass.setWrap(WrapMode.Repeat);
  matGroundL.setTexture("DiffuseMap", grass);
  floor.setMaterial(matGroundL);
  floor.setShadowMode(ShadowMode.CastAndReceive);
  return floor;
 }
}

代码示例来源:origin: info.projectkyoto/mms-engine

protected void createCollisionShape() {
  if (spatial == null) {
    return;
  }
  if (spatial instanceof Geometry) {
    Geometry geom = (Geometry) spatial;
    Mesh mesh = geom.getMesh();
    if (mesh instanceof Sphere) {
      collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
      return;
    } else if (mesh instanceof Box) {
      collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
      return;
    }
  }
  if (mass > 0) {
    collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
  } else {
    collisionShape = CollisionShapeFactory.createMeshShape(spatial);
  }
}

代码示例来源:origin: org.jmonkeyengine/jme3-core

protected void duUpdateGeometryTextures() {
  if (getBuffer(Type.TexCoord) == null){
    setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(GEOMETRY_TEXTURE_DATA));
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@Override
public void simpleInitApp(){
  Geometry geom = new Geometry("Box", new Box(1, 1, 1));
  Material material = new Material(getAssetManager(), "/Common/MatDefs/Misc/Unshaded.j3md");
  material.setColor("Color", ColorRGBA.Blue); //a color is needed to start with
  geom.setMaterial(material);
  getRootNode().attachChild(geom);
  
  exampleAsyncTask = new ExampleAsyncTask(material);
  exampleAsyncTask.getThread().start();
}

相关文章