Attach meshes under nodes so that they can be used as parents.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4055 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2006-04-25 02:26:07 +00:00
parent 918d38a3b1
commit 60591a85ee
3 changed files with 50 additions and 21 deletions
+47 -11
View File
@@ -108,6 +108,11 @@ public class ModelDef
/** A rigid triangle mesh. */ /** A rigid triangle mesh. */
public static class TriMeshDef extends SpatialDef public static class TriMeshDef extends SpatialDef
{ {
/** The geometry offset transform. */
public float[] offsetTranslation;
public float[] offsetRotation;
public float[] offsetScale;
/** Whether or not the mesh allows back face culling. */ /** Whether or not the mesh allows back face culling. */
public boolean solid; public boolean solid;
@@ -141,14 +146,38 @@ public class ModelDef
// documentation inherited // documentation inherited
public Spatial createSpatial (Properties props) public Spatial createSpatial (Properties props)
{ {
return configure(new ModelMesh(name), props); _mesh = createMesh();
configureMesh(props);
ModelNode node = new ModelNode(name);
node.attachChild(_mesh);
return node;
} }
/** Configures the new mesh and returns it. */ /** Creates the mesh to attach to the node. */
protected ModelMesh configure (ModelMesh mmesh, Properties props) protected ModelMesh createMesh ()
{ {
return new ModelMesh("mesh");
}
/** Configures the mesh. */
protected void configureMesh (Properties props)
{
// set the geometry offset
if (offsetTranslation != null) {
_mesh.getLocalTranslation().set(offsetTranslation[0],
offsetTranslation[1], offsetTranslation[2]);
}
if (offsetRotation != null) {
_mesh.getLocalRotation().set(offsetRotation[0],
offsetRotation[1], offsetRotation[2], offsetRotation[3]);
}
if (offsetScale != null) {
_mesh.getLocalScale().set(offsetScale[0], offsetScale[1],
offsetScale[2]);
}
// configure using properties // configure using properties
mmesh.configure(solid, texture, transparent, props); _mesh.configure(solid, texture, transparent, props);
// set the various buffers // set the various buffers
int vsize = vertices.size(); int vsize = vertices.size();
@@ -168,18 +197,20 @@ public class ModelDef
for (int ii = 0, nn = indices.size(); ii < nn; ii++) { for (int ii = 0, nn = indices.size(); ii < nn; ii++) {
ibuf.put(indices.get(ii)); ibuf.put(indices.get(ii));
} }
mmesh.reconstruct(vbbuf, nbbuf, null, tbbuf, ibbuf); _mesh.reconstruct(vbbuf, nbbuf, null, tbbuf, ibbuf);
return mmesh;
} }
/** The mesh that contains the actual geometry. */
protected ModelMesh _mesh;
} }
/** A triangle mesh that deforms according to bone positions. */ /** A triangle mesh that deforms according to bone positions. */
public static class SkinMeshDef extends TriMeshDef public static class SkinMeshDef extends TriMeshDef
{ {
// documentation inherited @Override // documentation inherited
public Spatial createSpatial (Properties props) protected ModelMesh createMesh ()
{ {
return configure(new SkinMesh(name), props); return new SkinMesh("mesh");
} }
@Override // documentation inherited @Override // documentation inherited
@@ -216,7 +247,7 @@ public class ModelDef
wgroup.weights = toArray(entry.getValue().weights); wgroup.weights = toArray(entry.getValue().weights);
wgroups[ii++] = wgroup; wgroups[ii++] = wgroup;
} }
((SkinMesh)_spatial).setWeightGroups(wgroups); ((SkinMesh)_mesh).setWeightGroups(wgroups);
} }
} }
@@ -253,7 +284,12 @@ public class ModelDef
nbuf.put(normal); nbuf.put(normal);
if (tbuf != null) { if (tbuf != null) {
tbuf.put(tcoords); if (tcoords != null) {
tbuf.put(tcoords);
} else {
tbuf.put(0f);
tbuf.put(0f);
}
} }
} }
-5
View File
@@ -41,11 +41,6 @@ macroScript TRAnimationExporter category:"File" \
if node.parent != undefined do ( if node.parent != undefined do (
xform = xform * (inverse node.parent.transform) xform = xform * (inverse node.parent.transform)
) )
if isKindOf node Editable_Mesh do (
xform = preTranslate xform node.objectOffsetPos
xform = preRotate xform node.objectOffsetRot
xform = preScale xform node.objectOffsetScale
)
writePoint3Attr " translation" xform.translationPart outFile writePoint3Attr " translation" xform.translationPart outFile
writeQuatAttr " rotation" (inverse xform.rotationPart) outFile writeQuatAttr " rotation" (inverse xform.rotationPart) outFile
writePoint3Attr " scale" xform.scalePart outFile writePoint3Attr " scale" xform.scalePart outFile
+3 -5
View File
@@ -112,17 +112,15 @@ macroScript TRModelExporter category:"File" \
xform = xform * (inverse node.parent.transform) xform = xform * (inverse node.parent.transform)
format " parent=\"%\"" node.parent.name to:outFile format " parent=\"%\"" node.parent.name to:outFile
) )
if isMesh do (
xform = preTranslate xform node.objectOffsetPos
xform = preRotate xform node.objectOffsetRot
xform = preScale xform node.objectOffsetScale
)
writePoint3Attr " translation" xform.translationPart \ writePoint3Attr " translation" xform.translationPart \
outFile outFile
writeQuatAttr " rotation" (inverse xform.rotationPart) \ writeQuatAttr " rotation" (inverse xform.rotationPart) \
outFile outFile
writePoint3Attr " scale" xform.scalePart outFile writePoint3Attr " scale" xform.scalePart outFile
if isMesh then ( if isMesh then (
writePoint3Attr " offsetTranslation" node.objectOffsetPos outFile
writeQuatAttr " offsetRotation" node.objectOffsetRot outFile
writePoint3Attr " offsetScale" node.objectOffsetScale outFile
format " solid=\"%\"" node.backFaceCull to:outFile format " solid=\"%\"" node.backFaceCull to:outFile
if node.material != undefined and if node.material != undefined and
isKindOf node.material.diffuseMap BitmapTexture do ( isKindOf node.material.diffuseMap BitmapTexture do (