ive made a very basic 3ds loader.. (made/taken from others)
-- Variable Definitions
global currentFile -- name of currently open file
global numNodes
fn getFileName val =
(
fname = filterString val ": \\"
fname = fname[fname.count]
return fname
)
rollout main "Level Exporter"
(
label comments "Comments:"
editText noteList text:"Comments:" height:100
button writeFile "Export Level" across:1
on writeFile pressed do
(
currentIn = getSaveFileName caption:"Export File" types:"XML(*.xml)|*.xml|All|*.*|"
if currentIn != undefined do
(
currentFile = openFile currentIn mode: "wt"
-- Comments --
format "<!-- " to:currentFile
for a = 1 to Main.noteList.text.count do
(
if Main.noteList.text[a] == "\n" then format "\n" to:currentFile
else format "%" Main.noteList.text[a] to:currentFile
)
format " -->\n" to:currentFile
format "<SCENE>\n" to:currentFile
for numNodes = 1 to objects.count do
(
if( objects[numNodes] == undefined) do continue
body = objects[numNodes] -- collision body to export
shape = classOf body
if(shape == dummy) then
(
if( getUserProp body "Particle" != undefined)do
(
format "\t<Particle>" to: currentFile
--format getUserProp body "Particle" to:currentFile
format "\t\t\t<position value =\"%\" />\n" body.position to:currentFile
format "\t</Particle>" to:currentFile
)
if(getUserProp body "Constraint" != undefined) then
(
format "\t<Constraint " to:currentFile
--local coord of distance from a to b
if(getUserProp body "BodyA" != undefined) do
(
s = getUserProp body "BodyA"
format "\t\tBodyA=\"%\"\n" s to:currentFile
bodyA = execute ("instance $"+s)
centerpivot bodyA
pivotA = in coordsys world(length (body.pos - bodyA.pos)) * (normalize (in coordsys bodyA.transform body.pos) )
format "\t\tPivotA=\"% % %\"\n" pivotA[1] pivotA[3] -pivotA[2] to:currentFile
if(getUserProp body "Constraint" == "Hinge") do
(
axisA = normalize (in coordsys bodyA.transform body.dir)
format "\t\tAxisA=\"% % %\"\n" axisA[1] axisA[3] -axisA[2] to:currentFile
)
delete bodyA
)
if(getUserProp body "BodyB" != undefined) do
(
s = getUserProp body "BodyB"
format "\t\tBodyB=\"%\"\n" s to:currentFile
bodyB = execute ("instance $"+s)
centerpivot bodyB
pivotB = in coordsys world(length (body.pos - bodyB.pos)) * (normalize (in coordsys bodyB.transform body.pos) )
format "\t\tPivotB=\"% % %\"\n" pivotB[1] pivotB[3] -pivotB[2] to:currentFile
if(getUserProp body "Constraint" == "Hinge") do
(
axisB = normalize (in coordsys bodyB.transform body.dir)
format "\t\tAxisB=\"% % %\"\n" AxisB[1] AxisB[3] -AxisB[2] to:currentFile
)
delete bodyB
)
format "\t\t/>" to:currentFile
)
else
(
format "\t\t<dummy name=\"%\">\n" body.name to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t</dummy>\n" to:currentFile
)
)
else if(shape == Omnilight) then
(
rgb = body.rgb
multiplier = body.multiplier
decay = body.farAttenEnd
format "\t\t<pointlight name=\"%\">\n" body.name to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t\t<color>\n" to:currentFile
format "\t\t\t<x> % </x>\n" rgb.red to:currentFile
format "\t\t\t<y> % </y>\n" rgb.green to:currentFile
format "\t\t\t<z> % </z>\n" rgb.blue to:currentFile
format "\t\t</color>\n" to:currentFile
format "\t\t\t<multiplier amount=\"%\" />\n" multiplier to:currentFile
format "\t\t\t<decay value =\"%\" />\n" decay to:currentFile
format "\t</pointlight>\n" to:currentFile
)
else if(shape == TargetCamera) then
(
format "\t\t<camera name=\"%\">\n" body.name to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t\t</camera>\n" to:currentFile
)
else if(shape == Targetobject) then
(
format "\t\t<target name=\"%\">\n" body.name to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t\t</target>\n" to:currentFile
)
else if(shape == Spray) then
(
format "\t<particle name=\"%\">\n" body.name to:currentFile
--format getUserProp body "Particle" to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t\t\t<width value =\"%\" />\n" body.emitterwidth to:currentFile
format "\t\t\t<height value =\"%\" />\n" body.emitterheight to:currentFile
format "\t</particle>" to:currentFile
)
else if(shape == targetSpot) then
(
rgb = body.rgb
multiplier = body.multiplier
decay = body.decayRadius
format "\t\t<spotlight name=\"%\">\n" body.name to:currentFile
format "\t\t<enabled>%</enabled>\n" body.enabled to:currentFile
format "\t\t<fallof>%</fallof>\n" body.falloff to:currentFile
format "\t\t<castShadows>%</castShadows>\n" body.castShadows to:currentFile
format "\t\t<position>\n" to:currentFile
format "\t\t\t<x> % </x>\n" body.position[1] to:currentFile
format "\t\t\t<y> % </y>\n" -body.position[3] to:currentFile
format "\t\t\t<z> % </z>\n" body.position[2] to:currentFile
format "\t\t</position>\n" to:currentFile
format "\t\t<color>\n" to:currentFile
format "\t\t\t<x> % </x>\n" rgb.red to:currentFile
format "\t\t\t<y> % </y>\n" rgb.green to:currentFile
format "\t\t\t<z> % </z>\n" rgb.blue to:currentFile
format "\t\t</color>\n" to:currentFile
format "\t\t\t<multiplier amount=\"%\" />\n" multiplier to:currentFile
format "\t\t\t<decay value =\"%\" />\n" decay to:currentFile
format "\t</spotlight>\n" to:currentFile
)
else
(
format "i:% body: % \n\n " l body
format "\t<body " to:currentFile
-- Bone and CLass and Name --
format "\t name=\"%\" >\n" body.name to:currentFile
format "\t\t<collision type=\"%\"/>\n" shape to:currentFile
if(classOf body.material == Standardmaterial) do
(
format "\t\t<material>\n" to:currentFile
format "\t\t\t<SpecularIntensity>\n" to:currentFile
format "\t\t\t%\n" body.material.Glossiness to:currentFile
format "\t\t\t</SpecularIntensity>\n" to:currentFile
format "\t\t\t<SpecularPower>\n" to:currentFile
format "\t\t\t%\n" body.material.specularLevel to:currentFile
format "\t\t\t</SpecularPower>\n" to:currentFile
if(body.material.diffusemap != undefined) do
(
a = getFileName body.material.diffusemap.filename
format "\t\t\t<diffuse name =\"%\" />\n" a to:currentFile
)
if(body.material.bumpmap != undefined) do
(
a =getFileName body.material.bumpmap.filename
format "\t\t\t<bump name =\"%\" />\n" a to:currentFile
)
if(body.material.specularlevelmap != undefined) do
(
a = getFileName body.material.specularlevelmap.filename
format "\t\t\t<specular name =\"%\" />\n" a to:currentFile
)
if(body.material.selfillummap != undefined) do
(
a = getFileName body.material.selfillummap.filename
format "\t\t\t<glow name =\"%\" />\n" a to:currentFile
)
format "\t\t</material>\n" to:currentFile
)
format "\t</body> \n"to:currentFile
)
)
format "</SCENE>\n" to:currentFile
close currentFile
)
)
)-- create the rollout window and add the rollout
if MoCapFloater != undefined do
(
closerolloutfloater MoCapFloater
)
MoCapFloater = newRolloutFloater "PloobsLevel Exporter" 500 200 100 100
addRollout Main MoCapFloater
then add a dummy to the base off all the objects you wish to export (please DO NOT use names with numbers on the end, e.g testDummy0 == BAD
testDummyYay = good.. if you make an instance of your object, 3DS will name it testDummyYay 001, testDummyYay 002, etc.. my code removes the numbers at the end, that's why
using System;
using System.Collections.Generic;
using System.Xml;
namespace DoTs
{
public class loadXMLDummies
{
public static void removeNumsEnd(List<xyzDummy> dummyList)
{
string tmpStr;
int size;
int newSize;
int i;
int ii = 0;
bool charFound = false;
foreach (xyzDummy itt in dummyList)
{
tmpStr = itt.ToString();
size = tmpStr.Length;
newSize = size;
charFound = false;
while (!charFound)
{
for (i = size - 1; i >= 0; i--)
{
charFound = false;
if (!int.TryParse(tmpStr[i].ToString(), out ii)) // if not an int
{
charFound = true;
break;
}
else
{
newSize--;
}
}
}
tmpStr = tmpStr.Substring(0, newSize);
itt.setName(tmpStr);
}
}
// throws System.Xml.XmlException
public static List<xyzDummy> load(string fileLoc)
{
List<xyzDummy> retList = new List<xyzDummy>();
//MessageBox.Show(fileLoc);
double x = 0, y = 0, z = 0;
string name;
string edit;
bool breakIt = false;
bool endRead = false;
using (XmlReader reader = XmlReader.Create(fileLoc))
{
endRead = !reader.Read();
while (!endRead)
{
// Only detect start elements.
if (reader.IsStartElement())
{
// Get element name and switch on it.
switch (reader.Name)
{
case "dummy":
// Detect this element.
name = reader["name"];
while (!breakIt && !endRead)
{
endRead = !reader.Read();
// Only detect start elements.
if (!endRead)
{
if (reader.IsStartElement())
{
// Get element name and switch on it.
switch (reader.Name)
{
case "dummy":
breakIt = true;
break;
case "x":
endRead = !reader.Read();
edit = reader.Value.Trim();
x = Convert.ToDouble(edit);
break;
case "y":
endRead = !reader.Read();
edit = reader.Value.Trim();
y = Convert.ToDouble(edit);
break;
case "z":
endRead = !reader.Read();
edit = reader.Value.Trim();
z = Convert.ToDouble(edit);
break;
default:
break;
}
}
}
}
breakIt = false;
retList.Add(new xyzDummy(name, x, y, z));
break;
default:
endRead = !reader.Read();
break;
}
}
}
}
return (retList);
}
}
public class xyzDummy
{
private String m_name;
private double m_x;
private double m_y;
private double m_z;
public double getX()
{
return (m_x);
}
public double getY()
{
return (m_y);
}
public double getZ()
{
return (m_z);
}
public xyzDummy(string name, double x, double y, double z)
{
m_name = name;
m_x = x;
m_y = y;
m_z = z;
}
public void setName(string name)
{
m_name = name;
}
public override string ToString()
{
// Generates the text shown in the combo box
return m_name;
}
}
}
then just make a switch statement and itterate through. using data.getName() as the statement to switch, then inside the switch add a case
for every object that you wish to extract, then call it's constructor passing x,y,z useing getX(), getY(), getZ().. unfortunately I can't find out how to extract the vector with facing.. but yeah, it was a patching project, so can't give everything, a demo project which will extract all dummies from an .xml is provided here:
http://www.2shared.com/file/7pqW95oF/WindowsFormsApplication1.html
it contains alota useless data in the extractor, that just because I never have maxscript codded and don't really feel like learning. Maybe somone can make maxscript only extract dummies, or grab spec from file!.. I didn't bother.