Strip path information from textures in model files, recenter meshes
about their bounding volume centers. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4061 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -50,6 +50,7 @@ import com.jme.scene.state.CullState;
|
||||
import com.jme.scene.state.TextureState;
|
||||
import com.jme.scene.state.ZBufferState;
|
||||
import com.jme.system.DisplaySystem;
|
||||
import com.jme.util.geom.BufferUtils;
|
||||
|
||||
import com.threerings.jme.Log;
|
||||
|
||||
@@ -138,6 +139,22 @@ public class ModelMesh extends TriMesh
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the vertices and the transform of the mesh so that the mesh's
|
||||
* position lies at the center of its bounding volume.
|
||||
*/
|
||||
public void centerVertices ()
|
||||
{
|
||||
Vector3f offset = getLocalTranslation().subtract(
|
||||
getModelBound().getCenter());
|
||||
FloatBuffer vbuf = getVertexBuffer();
|
||||
for (int ii = 0, nn = getVertexCount(); ii < nn; ii++) {
|
||||
BufferUtils.addInBuffer(offset, vbuf, ii);
|
||||
}
|
||||
getLocalTranslation().subtractLocal(offset);
|
||||
getModelBound().getCenter().zero();
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void reconstruct (
|
||||
FloatBuffer vertices, FloatBuffer normals, FloatBuffer colors,
|
||||
@@ -164,7 +181,7 @@ public class ModelMesh extends TriMesh
|
||||
_colorBufferSize = (colors == null) ? 0 : colors.capacity();
|
||||
_textureBufferSize = (textures == null) ? 0 : textures.capacity();
|
||||
}
|
||||
|
||||
|
||||
@Override // documentation inherited
|
||||
public Spatial putClone (Spatial store, CloneCreator properties)
|
||||
{
|
||||
|
||||
@@ -131,6 +131,15 @@ public class SkinMesh extends ModelMesh
|
||||
setNormalBuffer(BufferUtils.clone(_onbuf = getNormalBuffer()));
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void centerVertices ()
|
||||
{
|
||||
super.centerVertices();
|
||||
_ovbuf.rewind();
|
||||
getVertexBuffer().rewind();
|
||||
_ovbuf.put(getVertexBuffer());
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public Spatial putClone (Spatial store, CloneCreator properties)
|
||||
{
|
||||
|
||||
@@ -176,6 +176,13 @@ public class ModelDef
|
||||
offsetScale[2]);
|
||||
}
|
||||
|
||||
// make sure texture is just a filename
|
||||
int sidx = (texture == null) ? -1 :
|
||||
Math.max(texture.lastIndexOf('/'), texture.lastIndexOf('\\'));
|
||||
if (sidx != -1) {
|
||||
texture = texture.substring(sidx + 1);
|
||||
}
|
||||
|
||||
// configure using properties
|
||||
_mesh.configure(solid, texture, transparent, props);
|
||||
|
||||
@@ -198,6 +205,9 @@ public class ModelDef
|
||||
ibuf.put(indices.get(ii));
|
||||
}
|
||||
_mesh.reconstruct(vbbuf, nbbuf, null, tbbuf, ibbuf);
|
||||
|
||||
// set the mesh's origin to the center of its bounding box
|
||||
_mesh.centerVertices();
|
||||
}
|
||||
|
||||
/** The mesh that contains the actual geometry. */
|
||||
|
||||
Reference in New Issue
Block a user