Hey guys. So I’m attempting to do an implementation of an algorithm called “Speed Rock” that I found on the intarwebs and I’m debating between doing 1 of 2 things for the final step to finalizing the rock shape.
Let me quickly run over the steps in speed rock to better explain myself.
- Create a somewhat random assortment of boxes that are laid out in a grid fashion
- Collapse those boxes towards a center point to make a lumpy “Minecraft-like” shape.
- Using ray casting cast points from the outside to the center of the shape to create a sort of “dumb down” shape.
Step 3 is where I’m having a bit of a debate going on (Step 1 and 2 work fabulously and I’m quite proud of how it works so far). The debate is basically should I:
A) Move vertices on a sphere shape. (Sort of vacuum packing the blocky shape)
B) Create a new shape from scratch where I plot my ray casting sources in the same points as a sphere.
I’ve tried A but ended up with a weird assortment of triangles so I’m either doing something silly or this is totally not the way to go.
Thoughts anyone?
Just in case option A seems reasonable to what I’m doing here’s the code responsible for that
[java]
private void vacuumPackShape() {
Sphere saran = new Sphere(10, 10,boundingSize * 2);
Geometry geom = new Geometry("Saran", saran);
VertexBuffer verticesBuffer = geom.getMesh().getBuffer(VertexBuffer.Type.Position);
for(int i = 0; i < verticesBuffer.getNumElements(); i++) {
Vector3f tempVec = new Vector3f();
tempVec.setX((Float)verticesBuffer.getElementComponent(i, 0));
tempVec.setY((Float)verticesBuffer.getElementComponent(i, 1));
tempVec.setZ((Float)verticesBuffer.getElementComponent(i, 2));
CollisionResults results = new CollisionResults();
//Cast a ray from the sphere vertice to the opposite sphere vertice.
Ray ray = new Ray(tempVec, new Vector3f(-tempVec.x,-tempVec.y,-tempVec.z));
//The cubes node is where I store the cubes.
cubes.collideWith(ray, results);
System.out.println("Collisions:" + results.size());
Vector3f newVec = results.getClosestCollision().getContactPoint();
verticesBuffer.setElementComponent(i, 0, newVec.x);
verticesBuffer.setElementComponent(i, 1, newVec.y);
verticesBuffer.setElementComponent(i, 2, newVec.z);
}
Mesh newMesh = new Mesh();
newMesh.setBuffer(verticesBuffer);
geom.setMesh(newMesh);
geom.updateModelBound();
Material mat = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Orange);
mat.getAdditionalRenderState().setWireframe(false);
geom.setMaterial(mat);
node.attachChild(geom);
}
[/java]