I think I can create script that reads obj files.
Meanwhile, select some poly mesh(es) and run this script.
It will create stringToArray nodes on object 'polymsh' containing data for createTopo node. If there is no polymsh object and it doesn't have icetree, script will create one.
It also prints vertex positions and poly description in console so If you don't wanna ice nodes creation, set createIcetree variable to 0.
Code: Select all
from win32com.client import constants as c
# script will look for object "polymsh" (or create one if there is no polymsh in scene)
# and will add there two stringtoArray nodes containing poly data of selected object(s)
createIcetree = 1
createComments = 1
whereToAddStringNodes = "polymsh"
x = Application
sel = x.Selection
true = 1
false = 0
null = ""
def createICEpolymsh(object,vertPos,polyDesc, comments, commentAdditionalString):
oIcetrees = XSIFactory.CreateObject( "XSI.Collection" );
oIcetrees = object.ActivePrimitive.ICETrees
#check if there is icetree 'ICEtree' on object stack
if oIcetrees.Count == 0:
t = x.ApplyOp("ICETree", object.FullName, c.siNode)
oIceOp=t
else:
#if there is not, create one
for oIcetree in oIcetrees:
if oIcetree.Name =="ICETree":
oIceOp = oIcetree
#add stringtoarray nodes
stringArray = x.AddICENode("StringToArray",oIceOp)
stringArray2 = x.AddICENode("StringToArray",oIceOp)
stringArray.Value_string = vertPos
stringArray2.Value_string = polyDesc
#create comments if necessary
if comments == true:
strArrayCmt = x.CreateICENodeComment(stringArray.FullName)
strArrayCmt.Text = commentAdditionalString +" Vertex positions"
strArrayCmt = x.CreateICENodeComment(stringArray2.FullName)
strArrayCmt.Text = commentAdditionalString + " Polygon description"
selTxt = sel.GetAsText()
if createIcetree == 1:
obj = x.ActiveSceneRoot.FindChildren(whereToAddStringNodes, c.siPolyMeshType)
if obj.Count == 0:
opolymsh = x.GetPrim("EmptyPolygonMesh", "", "", "") #create empty polymsh if there is no whereToAddStringNodes named object in scene
else:
opolymsh = obj(0)
x.Selection.SetAsText(selTxt)
sel = x.Selection
for o in sel: #for every object in selection
if o.Type != "polymsh": #not polymesh
print "Object "+ o.FullName +" is not polymesh"
continue
oGeo = o.ActivePrimitive.Geometry
objFacets = oGeo.Polygons
objPoints = oGeo.Points
svertPos = ""
spolyDescription = ""
print "Object "+ o.FullName +" has " + str(oGeo.Points.Count) + " points and " + str(objFacets.Count) + " faces."
#build vertex position string
for v in objPoints:
svertPos += str(v.Position.X)+","+str(v.Position.Y)+","+str(v.Position.Z)+","
#build poly description string
for face in objFacets:
vert = face.Vertices
for v in vert:
spolyDescription += str(v.Index)+","
spolyDescription+="-2," #negative value ends single poly desc
#** print out values **
print "Vertex positions:"
print svertPos
print "Polygon description:"
print spolyDescription
if createIcetree == 1:
createICEpolymsh(opolymsh, svertPos, spolyDescription,createComments, o.FullName)