/** * Create a hull collision shape for the specified geometry. * * @param geom the geometry on which to base the shape (not null) * @param parent */ private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { HullCollisionShape dynamicShape = new HullCollisionShape(mesh); dynamicShape.setScale(trans.getScale()); return dynamicShape; } else { return null; } }
/** * Instantiate a collision shape based on the specified JME mesh. For best * performance and stability, use the mesh should have no more than 100 * vertices. * * @param mesh a mesh on which to base the shape (not null, at least one * vertex) */ public HullCollisionShape(Mesh mesh) { this.points = getPoints(mesh); createShape(); }
/** * Instantiate the configured shape in Bullet. */ protected void createShape() { // ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); // for (int i = 0; i < points.length; i += 3) { // pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); // } // objectId = new ConvexHullShape(pointList); // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); ByteBuffer bbuf=BufferUtils.createByteBuffer(points.length * 4); // fbuf = bbuf.asFloatBuffer(); // fbuf.rewind(); // fbuf.put(points); for (int i = 0; i < points.length; i++) { float f = points[i]; bbuf.putFloat(f); } bbuf.rewind(); objectId = createShape(bbuf); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); }
return new HullCollisionShape(p);
/** * Instantiate a collision shape based on the specified array of * coordinates. * * @param points an array of coordinates on which to base the shape (not * null, not empty, length a multiple of 3) */ public HullCollisionShape(float[] points) { this.points = points; createShape(); }
protected void createShape(float[] points) { ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); for (int i = 0; i < points.length; i += 3) { pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); } cShape = new ConvexHullShape(pointList); cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
return new HullCollisionShape(p);
public HullCollisionShape(float[] points) { this.points = points; createShape(this.points); }
protected void createShape(float[] points) { ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); for (int i = 0; i < points.length; i += 3) { pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); } cShape = new ConvexHullShape(pointList); cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
public HullCollisionShape(Mesh mesh) { this.points = getPoints(mesh); createShape(this.points); }
protected void createShape() { // ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); // for (int i = 0; i < points.length; i += 3) { // pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); // } // objectId = new ConvexHullShape(pointList); // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); ByteBuffer bbuf=BufferUtils.createByteBuffer(points.length * 4); // fbuf = bbuf.asFloatBuffer(); // fbuf.rewind(); // fbuf.put(points); for (int i = 0; i < points.length; i++) { float f = points[i]; bbuf.putFloat(f); } bbuf.rewind(); objectId = createShape(bbuf); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); }
/** * Create a hull collision shape for the specified geometry. * * @param geom the geometry on which to base the shape (not null) * @param parent */ private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { HullCollisionShape dynamicShape = new HullCollisionShape(mesh); dynamicShape.setScale(trans.getScale()); return dynamicShape; } else { return null; } }
/** * Create a hull collision shape from linked vertices to this bone. * * @param model the model on which to base the shape * @param boneIndices indices of relevant bones (not null, unaffected) * @param initialScale scale factors * @param initialPosition location * @param weightThreshold minimum weight for inclusion * @return a new shape */ public static HullCollisionShape makeShapeFromVerticeWeights(Spatial model, List<Integer> boneIndices, Vector3f initialScale, Vector3f initialPosition, float weightThreshold) { List<Float> points = new ArrayList<>(100); SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class); Mesh[] targetMeshes = skeletonCtrl.getTargets(); for (Mesh mesh : targetMeshes) { for (Integer index : boneIndices) { List<Float> bonePoints = getPoints(mesh, index, initialScale, initialPosition, weightThreshold); points.addAll(bonePoints); } } assert !points.isEmpty(); float[] p = new float[points.size()]; for (int i = 0; i < points.size(); i++) { p[i] = points.get(i); } return new HullCollisionShape(p); }
public HullCollisionShape(float[] points) { this.points = points; createShape(); }
@Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); // for backwards compatability Mesh mesh = (Mesh) capsule.readSavable("hullMesh", null); if (mesh != null) { this.points = getPoints(mesh); } else { this.points = capsule.readFloatArray("points", null); } createShape(this.points); }
protected void createShape() { // ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); // for (int i = 0; i < points.length; i += 3) { // pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); // } // objectId = new ConvexHullShape(pointList); // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); ByteBuffer bbuf=BufferUtils.createByteBuffer(points.length * 4); // fbuf = bbuf.asFloatBuffer(); // fbuf.rewind(); // fbuf.put(points); for (int i = 0; i < points.length; i++) { float f = points[i]; bbuf.putFloat(f); } bbuf.rewind(); objectId = createShape(bbuf); Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); }
/** * This method creates a hull collision shape for the given mesh.<br> */ private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { HullCollisionShape dynamicShape = new HullCollisionShape(mesh); dynamicShape.setScale(trans.getScale()); return dynamicShape; } else { return null; } }
/** * Create a hull collision shape from linked vertices to this bone. * * @param model the model on which to base the shape * @param boneIndices indices of relevant bones (not null, unaffected) * @param initialScale scale factors * @param initialPosition location * @param weightThreshold minimum weight for inclusion * @return a new shape */ public static HullCollisionShape makeShapeFromVerticeWeights(Spatial model, List<Integer> boneIndices, Vector3f initialScale, Vector3f initialPosition, float weightThreshold) { List<Float> points = new ArrayList<>(100); SkeletonControl skeletonCtrl = model.getControl(SkeletonControl.class); Mesh[] targetMeshes = skeletonCtrl.getTargets(); for (Mesh mesh : targetMeshes) { for (Integer index : boneIndices) { List<Float> bonePoints = getPoints(mesh, index, initialScale, initialPosition, weightThreshold); points.addAll(bonePoints); } } assert !points.isEmpty(); float[] p = new float[points.size()]; for (int i = 0; i < points.size(); i++) { p[i] = points.get(i); } return new HullCollisionShape(p); }
public HullCollisionShape(float[] points) { this.points = points; createShape(); }
/** * De-serialize this shape, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ @Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); // for backwards compatability Mesh mesh = (Mesh) capsule.readSavable("hullMesh", null); if (mesh != null) { this.points = getPoints(mesh); } else { this.points = capsule.readFloatArray("points", null); } // fbuf = ByteBuffer.allocateDirect(points.length * 4).asFloatBuffer(); // fbuf.put(points); // fbuf = FloatBuffer.wrap(points).order(ByteOrder.nativeOrder()).asFloatBuffer(); createShape(); }