Skip to content

Commit

Permalink
Added MOI 3D support
Browse files Browse the repository at this point in the history
  • Loading branch information
heimlich1024 committed Jul 2, 2017
1 parent 7e7556b commit 65852ae
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Moi3D/ODCopyToExternal.js
@@ -0,0 +1,6 @@
var comPath = moi.filesystem.getCommandsDir();
var obj = comPath + "1.obj";
//Export
moi.geometryDatabase.fileExport( obj, 'NoUI=true' ); //also try: Output=ngons | quads | triangles
//use external app to convert to vertdata
moi.filesystem.shellExecute( comPath + "objToVertData.exe");
5 changes: 5 additions & 0 deletions Moi3D/ODPasteFromExternal.htm
@@ -0,0 +1,5 @@
<html xmlns:moi>
<body class="commandbody">
<div id="progressinfo" class="commandoptions" style="text-align:center; font-size:75%;"></div>
</body>
</html>
121 changes: 121 additions & 0 deletions Moi3D/ODPasteFromExternal.js
@@ -0,0 +1,121 @@
var vertices=[], faces=[], max={ x:-100000, y:-100000, z:-100000 }, min={ x:100000, y:100000, z:100000 }, objName, errors=0, scale, normalize, faceobj = moi.geometryDatabase.createObjectList();
function cleanSpaces(str) { return str.replace(/^\s+|\s+$/g, '').replace(/ +(?= )/g,'')};
function loadObj( objPath )
{
var objFile = moi.filesystem.openFileStream( objPath, 'r' ), x, y, z;
while ( !objFile.AtEOF )
{
var nextLine = cleanSpaces(objFile.readLine()).split(' ');
if ( nextLine[0] === "v" )
{
x = nextLine[1]*1; y = -nextLine[3]*1; z = nextLine[2]*1;
if (x<min.x) { min.x=x; } if (y<min.y) { min.y=y; } if (z<min.z) { min.z=z; }
if (x>max.x){ max.x=x; } if (y>max.y){ max.y=y; } if (z>max.z) { max.z=z; }
vertices.push({x:x, y:y, z:z});
}
if ( nextLine[0] === "f" ) faces.push(nextLine);
}
objFile.close();
objName = moi.filesystem.getFileNameFromPath(objPath);
objName = objName.substr(0, objName.lastIndexOf('.'));
}

function normalizeObj (norm)
{
normalize = norm;
scale = 200/(max.x-min.x+max.y-min.y+max.z-min.z)/3
var scalelog = Math.pow(10, Math.round(Math.log(scale)/Math.log(10)));
if (scalelog>1) { scalelog /=10 }
scale = Math.round(scale/scalelog)*scalelog;
if (scale == 0) scale = scalelog;
if ( !normalize && scale<1 ) scale=1;
scale *=100;
if ( !normalize ) for ( v in vertices ) vertices[v] = moi.VectorMath.createPoint(vertices[v].x*scale, vertices[v].y*scale, vertices[v].z*scale);
if ( normalize ) for ( v in vertices ) vertices[v] = moi.VectorMath.createPoint((vertices[v].x-max.x/2-min.x/2)*scale, (vertices[v].y-max.y/2-min.y/2)*scale, (vertices[v].z-min.z)*scale);
scale /=100;
}

function processObj(startPos, endPos)
{
var lineF = moi.command.createFactory( 'line' ), lineV;
var loftF = moi.command.createFactory( 'loft' ), loftV;
var planarF = moi.command.createFactory( 'planarsrf' ), planarV;
for ( var f=startPos; f<endPos; f++ )
{
var face = [], edges = moi.geometryDatabase.createObjectList();
for (var i=1; i < faces[f].length; i++) face.push(faces[f][i].split("/",1)-1);
var flen = face.length;
if ( flen > 4 )
{
for (var i=0; i < flen; i++)
{
lineF.setInput( 0, vertices[face[i]]);
lineF.setInput( 1, vertices[face[(i+1)%flen]]);
lineV=lineF.calculate();
edges.addObject(lineV.item(0));
}
planarF.setInput( 0, edges );
planarV=planarF.calculate();
if ( planarV.length > 0 ) { faceobj.addObject(planarV.item(0)) } else { errors++ }
}
else if ( flen ==3 || flen == 4 )
{
var sPt = 0, maxLength = 0, cLength=0, nPt;
for (var i = 0; i<flen; i++)
{
nPt=(i+1)%flen;
cLength = Math.sqrt((vertices[face[nPt]].x-vertices[face[i]].x)*(vertices[face[nPt]].x-vertices[face[i]].x)+(vertices[face[nPt]].y-vertices[face[i]].y)*(vertices[face[nPt]].y-vertices[face[i]].y)+(vertices[face[nPt]].z-vertices[face[i]].z)*(vertices[face[nPt]].z-vertices[face[i]].z));
if ( cLength > maxLength ) { maxLength = cLength; sPt = i; }
}
lineF.setInput( 0, vertices[face[sPt]]); lineF.setInput( 1, vertices[face[(sPt+1)%flen]]); lineV=lineF.calculate(); edges.addObject(lineV.item(0));
lineF.setInput( 0, vertices[face[(sPt+3)%flen]]); lineF.setInput( 1, vertices[face[(sPt+2)%flen]]); lineV=lineF.calculate(); edges.addObject(lineV.item(0));
loftF.setInput( 0, edges);
loftV = loftF.calculate();
if (loftV.length>0) { faceobj.addObject(loftV.item(0)) } else { errors++ }
} else { errors++ }
}
}

function showObj()
{
var scale3d = moi.command.createFactory( 'scale' );
scale3d.setInput( 0, faceobj );
scale3d.setInput( 1, moi.VectorMath.createPoint(0,0,0) );
scale3d.setInput( 2, (normalize)?1/100:0.01/scale );
faceobj=scale3d.calculate();

moi.geometryDatabase.addObjects(faceobj);
if ( normalize ) if (scale > 1) { objName = objName + " ["+scale+":1]" } else if (scale < 1) { objName = objName + " [1:"+Math.round(100/scale)/100+"]" }
if (errors>0) objName = objName + " err:"+errors;
faceobj.setProperty( 'name', objName);
}
function joinObj(joinmax)
{
if (faceobj.length>joinmax) return;
var joinF=moi.command.createFactory( 'join' );
joinF.setInput(0, faceobj);
joinF.commit();
}

var comPath = moi.filesystem.getCommandsDir();
var obj = comPath + "1.obj";
//Export
moi.filesystem.shellExecute( comPath + "vertDataToObj.exe");
moi.ui.commandUI.progressinfo.innerHTML="Loading";
loadObj( obj );
moi.ui.commandUI.progressinfo.innerHTML="Normalizing";
var facesnum = faces.length;
if ( moi.command.getCommandLineParams() ==='exact' ) { normalizeObj( false ) } else { normalizeObj( true ) }
var cstart = 0, cend=0, cstep = 2000;
do { cend = (cend+cstep>facesnum)?facesnum:cend+cstep;
moi.ui.commandUI.progressinfo.innerHTML="Processing ("+cstart+"/"+facesnum+")<br/>Press ESC to abort";
processObj(cstart, cend);
cstart +=cstep;
} while (cend<facesnum);

if ( moi.command.getCommandLineParams() ==='exact' ) { normalizeObj( false ) } else { normalizeObj( true ) }
moi.ui.commandUI.progressinfo.innerHTML="Resizing";
showObj();
moi.ui.commandUI.progressinfo.innerHTML="Joining<br/>Press ESC to skip";
joinObj(20000);
moi.ui.commandUI.progressinfo.innerHTML="";
Binary file added Moi3D/objToVertData.exe
Binary file not shown.
Binary file added Moi3D/vertDataToObj.exe
Binary file not shown.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -34,6 +34,7 @@ The following applications are supported:
* Sketchup : Vertices / Polygons (Paste only for now - Initial implementation provided as starting point)
* 3DsMax : Vertices / Poyygons (Initial implementation provided as a starting point)
* XSI : Vertices / Polygons / WeightMaps / Morphs
* Moi3D : Vertices / Polygons
* ZBrush : Vertices / Polygons / UVs
* Substance Painter : Vertices / Polygons / UVs
* Mari : Vertices / Polygons / UVs (in beta)
Expand Down Expand Up @@ -107,6 +108,16 @@ might have to manually run them the first time. This current implementation is
until the proper C4D C implementation can be finished. It currently only supports Points,
Polygons and UV's and brings up the OBJ requester on "PasteFromExternal"

### Moi 3D

Copy the contents of the Moi3D folder into the commands folder of your Moi Installation.
You can then call the scripts via hotkeys, or the external script manager if you have it.

### XSI

Open the script editor within XSI and load the script, make a new shelf, and then drag the
script to the shelf, and setup a button. Do that for both copy/paste scripts

# FAQ
* How do I report an issue ?

Expand Down Expand Up @@ -156,7 +167,7 @@ alt="3DSMax-Blender Usage" width="240" height="180" border="10" /></a>

* Houdini: figure out how to get Morphs/Blendshapes integrated
* Maya: figure out how to get Morphs/Blendshapes integrated
* Cinema4d: Implementation
* Cinema4d: C Implementation (currently only python (vertices,polys,uvs supported))
* 3DsMax: Initial Implementation as sample is complete
* Sketchup: Add Copy To and finesse Paste implementation
* Unreal: R&D to see if its possible to implement
Expand Down

0 comments on commit 65852ae

Please sign in to comment.