Added object offsets to exporters, converted tabs to spaces, added
method to get model nodes anywhere in the hierarchy by name, update model bounds in SkinMesh after deforming mesh. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4038 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -64,6 +64,26 @@ public class ModelNode extends Node
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively searches the scene graph rooted at this node for a
|
||||||
|
* node with the provided name.
|
||||||
|
*/
|
||||||
|
public Spatial getDescendant (String name)
|
||||||
|
{
|
||||||
|
for (int ii = 0, nn = getQuantity(); ii < nn; ii++) {
|
||||||
|
Spatial child = getChild(ii);
|
||||||
|
if (child.getName().equals(name)) {
|
||||||
|
return child;
|
||||||
|
} else if (child instanceof ModelNode) {
|
||||||
|
child = ((ModelNode)child).getDescendant(name);
|
||||||
|
if (child != null) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reference to the model space transform of the node.
|
* Returns a reference to the model space transform of the node.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ public class SkinMesh extends ModelMesh
|
|||||||
BufferUtils.setInBuffer(_normal, nbuf, idx);
|
BufferUtils.setInBuffer(_normal, nbuf, idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateModelBound();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The groups of vertices influenced by different sets of bones. */
|
/** The groups of vertices influenced by different sets of bones. */
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ macroScript TRAnimationExporter category:"File" \
|
|||||||
buttonText:"Export Animation as XML..." toolTip:"Export Animation as XML" (
|
buttonText:"Export Animation as XML..." toolTip:"Export Animation as XML" (
|
||||||
|
|
||||||
-- Writes a point3-valued attribute to the file
|
-- Writes a point3-valued attribute to the file
|
||||||
fn writePoint3Attr attr p outFile =
|
fn writePoint3Attr attr p outFile =
|
||||||
(
|
(
|
||||||
format "%=\"%, %, %\"" attr p.x p.y p.z to:outFile
|
format "%=\"%, %, %\"" attr p.x p.y p.z to:outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a quat-valued attribute to the file
|
-- Writes a quat-valued attribute to the file
|
||||||
fn writeQuatAttr attr q outFile =
|
fn writeQuatAttr attr q outFile =
|
||||||
(
|
(
|
||||||
format "%=\"%, %, %, %\"" attr q.x q.y q.z q.w to:outFile
|
format "%=\"%, %, %, %\"" attr q.x q.y q.z q.w to:outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a single node transform
|
-- Writes a single node transform
|
||||||
fn writeTransform node outFile = (
|
fn writeTransform node outFile = (
|
||||||
format " <transform name=\"%\"" node.name to:outFile
|
format " <transform name=\"%\"" node.name to:outFile
|
||||||
@@ -41,6 +41,11 @@ 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
|
||||||
@@ -53,44 +58,44 @@ macroScript TRAnimationExporter category:"File" \
|
|||||||
for node in nodes do (
|
for node in nodes do (
|
||||||
writeTransform node outFile
|
writeTransform node outFile
|
||||||
)
|
)
|
||||||
format " </frame>\n\n" to:outFile
|
format " </frame>\n\n" to:outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes animation to the named file
|
-- Writes animation to the named file
|
||||||
fn writeAnimation fileName =
|
fn writeAnimation fileName =
|
||||||
(
|
(
|
||||||
outFile = createfile fileName
|
outFile = createfile fileName
|
||||||
format "<?xml version=\"1.0\" standalone=\"yes\"?>\n\n" to:outFile
|
format "<?xml version=\"1.0\" standalone=\"yes\"?>\n\n" to:outFile
|
||||||
format "<animation frameRate=\"%\">\n\n" frameRate to:outFile
|
format "<animation frameRate=\"%\">\n\n" frameRate to:outFile
|
||||||
local nodes
|
local nodes
|
||||||
if selection.count > 0 then (
|
if selection.count > 0 then (
|
||||||
nodes = selection
|
nodes = selection
|
||||||
) else (
|
) else (
|
||||||
nodes = objects
|
nodes = objects
|
||||||
)
|
)
|
||||||
for i = animationRange.start to animationRange.end do at time i (
|
for i = animationRange.start to animationRange.end do at time i (
|
||||||
writeFrame nodes outFile
|
writeFrame nodes outFile
|
||||||
)
|
)
|
||||||
format "</animation>\n" to:outFile
|
format "</animation>\n" to:outFile
|
||||||
close outFile
|
close outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Main entry point
|
-- Main entry point
|
||||||
--
|
--
|
||||||
|
|
||||||
-- Get the target filename
|
-- Get the target filename
|
||||||
persistent global xmlAnimFileName
|
persistent global xmlAnimFileName
|
||||||
local fileName
|
local fileName
|
||||||
if (xmlAnimFileName == undefined) then (
|
if (xmlAnimFileName == undefined) then (
|
||||||
fileName = maxFilePath + (getFilenameFile maxFileName) + ".xml"
|
fileName = maxFilePath + (getFilenameFile maxFileName) + ".xml"
|
||||||
) else (
|
) else (
|
||||||
fileName = xmlAnimFileName
|
fileName = xmlAnimFileName
|
||||||
)
|
)
|
||||||
fileName = getSaveFileName caption:"Select File to Export" \
|
fileName = getSaveFileName caption:"Select File to Export" \
|
||||||
filename:fileName types:"XML Animations (*.XML)|*.xml|All|*.*"
|
filename:fileName types:"XML Animations (*.XML)|*.xml|All|*.*"
|
||||||
if fileName != undefined do (
|
if fileName != undefined do (
|
||||||
xmlAnimFileName = fileName
|
xmlAnimFileName = fileName
|
||||||
writeAnimation fileName
|
writeAnimation fileName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
+106
-101
@@ -21,33 +21,33 @@
|
|||||||
|
|
||||||
macroScript TRModelExporter category:"File" \
|
macroScript TRModelExporter category:"File" \
|
||||||
buttonText:"Export Model as XML..." toolTip:"Export Model as XML" (
|
buttonText:"Export Model as XML..." toolTip:"Export Model as XML" (
|
||||||
|
|
||||||
-- Writes a point3-valued attribute to the file
|
-- Writes a point3-valued attribute to the file
|
||||||
fn writePoint3Attr attr p outFile =
|
fn writePoint3Attr attr p outFile =
|
||||||
(
|
(
|
||||||
format "%=\"%, %, %\"" attr p.x p.y p.z to:outFile
|
format "%=\"%, %, %\"" attr p.x p.y p.z to:outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a quat-valued attribute to the file
|
-- Writes a quat-valued attribute to the file
|
||||||
fn writeQuatAttr attr q outFile =
|
fn writeQuatAttr attr q outFile =
|
||||||
(
|
(
|
||||||
format "%=\"%, %, %, %\"" attr q.x q.y q.z q.w to:outFile
|
format "%=\"%, %, %, %\"" attr q.x q.y q.z q.w to:outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a skinned vertex's bone weights to the file
|
-- Writes a skinned vertex's bone weights to the file
|
||||||
fn writeSkinBoneWeights skin vidx outFile =
|
fn writeSkinBoneWeights skin vidx outFile =
|
||||||
(
|
(
|
||||||
weightCount = skinOps.getVertexWeightCount skin vidx
|
weightCount = skinOps.getVertexWeightCount skin vidx
|
||||||
for i = 1 to weightCount do (
|
for i = 1 to weightCount do (
|
||||||
bone = skinOps.getBoneName skin (skinOps.getVertexWeightBoneID \
|
bone = skinOps.getBoneName skin (skinOps.getVertexWeightBoneID \
|
||||||
skin vidx i) 0
|
skin vidx i) 0
|
||||||
weight = skinOps.getVertexWeight skin vidx i
|
weight = skinOps.getVertexWeight skin vidx i
|
||||||
format " <boneWeight bone=\"%\" weight=\"%\"/>\n" bone \
|
format " <boneWeight bone=\"%\" weight=\"%\"/>\n" bone \
|
||||||
weight to:outFile
|
weight to:outFile
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a physiqued vertex's bone weights to the file
|
-- Writes a physiqued vertex's bone weights to the file
|
||||||
fn writePhysiqueBoneWeights node vidx outFile =
|
fn writePhysiqueBoneWeights node vidx outFile =
|
||||||
(
|
(
|
||||||
boneCount = physiqueOps.getVertexBoneCount node vidx
|
boneCount = physiqueOps.getVertexBoneCount node vidx
|
||||||
@@ -57,40 +57,40 @@ macroScript TRModelExporter category:"File" \
|
|||||||
format " <boneWeight bone=\"%\" weight=\"%\"/>\n" bone.name \
|
format " <boneWeight bone=\"%\" weight=\"%\"/>\n" bone.name \
|
||||||
weight to:outFile
|
weight to:outFile
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a mesh's vertices to the file
|
-- Writes a mesh's vertices to the file
|
||||||
fn writeVertices mesh outFile =
|
fn writeVertices mesh outFile =
|
||||||
(
|
(
|
||||||
for i = 1 to mesh.numfaces do (
|
for i = 1 to mesh.numfaces do (
|
||||||
face = getFace mesh i
|
face = getFace mesh i
|
||||||
local tvface
|
local tvface
|
||||||
if mesh.numtverts > 0 do (
|
if mesh.numtverts > 0 do (
|
||||||
tvface = getTVFace mesh i
|
tvface = getTVFace mesh i
|
||||||
)
|
)
|
||||||
for i = 1 to 3 do in coordsys local (
|
for i = 1 to 3 do in coordsys local (
|
||||||
format " <vertex" to:outFile
|
format " <vertex" to:outFile
|
||||||
writePoint3Attr " location" (getVert mesh face[i]) outFile
|
writePoint3Attr " location" (getVert mesh face[i]) outFile
|
||||||
writePoint3Attr " normal" (getNormal mesh face[i]) outFile
|
writePoint3Attr " normal" (getNormal mesh face[i]) outFile
|
||||||
if tvface != undefined do (
|
if tvface != undefined do (
|
||||||
tvert = getTVert mesh tvface[i]
|
tvert = getTVert mesh tvface[i]
|
||||||
format " tcoords=\"%, %\"" tvert[1] tvert[2] to:outFile
|
format " tcoords=\"%, %\"" tvert[1] tvert[2] to:outFile
|
||||||
)
|
)
|
||||||
if isProperty mesh #skin or isProperty mesh #physique then (
|
if isProperty mesh #skin or isProperty mesh #physique then (
|
||||||
format ">\n" to:outFile
|
format ">\n" to:outFile
|
||||||
if isProperty mesh #skin then (
|
if isProperty mesh #skin then (
|
||||||
writeSkinBoneWeights mesh.skin face[i] outFile
|
writeSkinBoneWeights mesh.skin face[i] outFile
|
||||||
) else (
|
) else (
|
||||||
writePhysiqueBoneWeights mesh face[i] outFile
|
writePhysiqueBoneWeights mesh face[i] outFile
|
||||||
)
|
)
|
||||||
format " </vertex>\n" to:outFile
|
format " </vertex>\n" to:outFile
|
||||||
) else (
|
) else (
|
||||||
format "/>\n" to:outFile
|
format "/>\n" to:outFile
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes a node to the file
|
-- Writes a node to the file
|
||||||
fn writeNode node outFile =
|
fn writeNode node outFile =
|
||||||
(
|
(
|
||||||
@@ -112,62 +112,67 @@ 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
|
||||||
)
|
)
|
||||||
writePoint3Attr " translation" xform.translationPart \
|
if isMesh do (
|
||||||
|
xform = preTranslate xform node.objectOffsetPos
|
||||||
|
xform = preRotate xform node.objectOffsetRot
|
||||||
|
xform = preScale xform node.objectOffsetScale
|
||||||
|
)
|
||||||
|
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 (
|
||||||
format ">\n" to:outFile
|
format ">\n" to:outFile
|
||||||
if isProperty node #skin do (
|
if isProperty node #skin do (
|
||||||
setCommandPanelTaskMode mode:#modify
|
setCommandPanelTaskMode mode:#modify
|
||||||
modPanel.setCurrentObject node.skin node:node
|
modPanel.setCurrentObject node.skin node:node
|
||||||
)
|
)
|
||||||
writeVertices node outFile
|
writeVertices node outFile
|
||||||
format " </%>\n\n" kind to:outFile
|
format " </%>\n\n" kind to:outFile
|
||||||
|
|
||||||
) else (
|
) else (
|
||||||
format "/>\n\n" to:outFile
|
format "/>\n\n" to:outFile
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Writes the model to the named file
|
-- Writes the model to the named file
|
||||||
fn writeModel fileName =
|
fn writeModel fileName =
|
||||||
(
|
(
|
||||||
outFile = createfile fileName
|
outFile = createfile fileName
|
||||||
format "<?xml version=\"1.0\" standalone=\"yes\"?>\n\n" to:outFile
|
format "<?xml version=\"1.0\" standalone=\"yes\"?>\n\n" to:outFile
|
||||||
format "<model>\n\n" to:outFile
|
format "<model>\n\n" to:outFile
|
||||||
local nodes
|
local nodes
|
||||||
oldsel = selection as array
|
oldsel = selection as array
|
||||||
if selection.count > 0 then (
|
if selection.count > 0 then (
|
||||||
nodes = selection
|
nodes = selection
|
||||||
) else (
|
) else (
|
||||||
nodes = objects
|
nodes = objects
|
||||||
)
|
)
|
||||||
for node in nodes do (
|
for node in nodes do (
|
||||||
writeNode node outFile
|
writeNode node outFile
|
||||||
)
|
)
|
||||||
select oldsel
|
select oldsel
|
||||||
format "</model>\n" to:outFile
|
format "</model>\n" to:outFile
|
||||||
close outFile
|
close outFile
|
||||||
)
|
)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Main entry point
|
-- Main entry point
|
||||||
--
|
--
|
||||||
|
|
||||||
-- Get the target filename
|
-- Get the target filename
|
||||||
persistent global xmlModelFileName
|
persistent global xmlModelFileName
|
||||||
local fileName
|
local fileName
|
||||||
if (xmlModelFileName == undefined) then (
|
if (xmlModelFileName == undefined) then (
|
||||||
fileName = maxFilePath + (getFilenameFile maxFileName) + ".xml"
|
fileName = maxFilePath + (getFilenameFile maxFileName) + ".xml"
|
||||||
) else (
|
) else (
|
||||||
fileName = xmlModelFileName
|
fileName = xmlModelFileName
|
||||||
)
|
)
|
||||||
fileName = getSaveFileName caption:"Select File to Export" \
|
fileName = getSaveFileName caption:"Select File to Export" \
|
||||||
filename:fileName types:"XML Models (*.XML)|*.xml|All|*.*"
|
filename:fileName types:"XML Models (*.XML)|*.xml|All|*.*"
|
||||||
if fileName != undefined do (
|
if fileName != undefined do (
|
||||||
xmlModelFileName = fileName
|
xmlModelFileName = fileName
|
||||||
writeModel fileName
|
writeModel fileName
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user