XSIforum.com
Foros 3D => Autodesk Softimage => Rigging y Scripting => Mensaje iniciado por: stewie en 12 Agosto 2007, 11:10:33
-
Holas a todos. Estoy trasteando con scripting y OM en XSI. Quiero hacer un ObjectToCluster Constraint utilizando el Object Model. En teoría sólo hay que especificar el tipo de constraint y el punto al que queremos hacer el constraint, ya que el primero objeto va implícito al estar trabajando dentro de sus kinematics. El problema está en que pase la información que pase, da error.
oPntsCube2 = oCube2.ActivePrimitive.Geometry.Points(4).SubComponent , con esto paso el pnt[4], en principio lo que necesita (al menos utilizando el comando en lugar del OM).
He probado con todos estos:
oPntsCube2 = oCube2.ActivePrimitive.Geometry.Points(4) (Vertex)
oPntsCube2 = oCube2.ActivePrimitive.Geometry.Points(4).SubComponent (cube5.pnt[4])
oPntsCube2 = oCube2.ActivePrimitive.Geometry.Points(4).SubComponent.ComponentCollection(0) (Vertex)
Código completo:
oRoot = Application.ActiveSceneRoot
oCube = oRoot.AddGeometry("sphere", "MeshSurface", "cube")
oCube2 = oRoot.AddGeometry("cube", "MeshSurface", "cube2")
oPntsCube2 = oCube2.ActivePrimitive.Geometry.Points(4).SubComponent
oCube.Kinematics.AddConstraint ("ObjectToCluster", oPntsCube2)
Gracias! (¿cuánta gente le da al scripting por aquí? ¿merece la pena meterse en este berenjenal?)
-
Estoy idiota... resulta que si haces un ObjectToCluster utilizando el comando ApplyCns, si el punto que seleccionas no tiene cluster, lo crea automáticamente, pero utilizando el método AddConstraint, es necesario especificar un cluster, ya que no lo crea automáticamente. Aquí sí funciona:
oRoot = Application.ActiveSceneRoot
oSphere = oRoot.AddGeometry("sphere","MeshSurface","sphere")
oCube = oRoot.AddGeometry("cube","MeshSurface","cube")
oGeom = oCube.ActivePrimitive.Geometry
oCluster = oGeom.Points(0).SubComponent.CreateCluster("pepe")
oSphere.Kinematics.AddConstraint ("ObjectToCluster", oCluster)
-
Sigo con mis experimentos. Ahora voy a hacer un script en OM y en comandos, para comparar la velocidad de ejecución. El script crea un grid de 30 x 30 divisiones, y en cada punto coloca un cubo con un Constraint a ese mismo punto. Menos el Duplicate (parece mentira que no exista un método en OM para duplicar o borrar) y los Log, en este script está todo en OM.
# INFO : Execution Time: 15.2189998627
import time
Tic = time.time()
oRoot = Application.ActiveSceneRoot
oGrid = oRoot.AddGeometry("grid","MeshSurface","grid")
oGrid.subdivu.value = 30
oGrid.subdivv.value = 30
oGrid.ulength.value = 15
oGrid.vlength.value = 15
oCube = oRoot.AddGeometry("cube","MeshSurface","cube")
oCube.length.value = 0.3
oGridGeom = oGrid.ActivePrimitive.Geometry
oGridPoints=oGridGeom.Points.Count
Application.LogMessage ("Total of grid points: "+(str(oGridPoints)))
oCubes = Application.Duplicate (oCube, oGridPoints)
for i in range (0,oGridPoints-1):
oGridCls = oGridGeom.Points(i).SubComponent.CreateCluster(i)
oCubes(i).Kinematics.AddConstraint ("ObjectToCluster", oGridCls)
Tac = time.time()
TotalTime = Tac - Tic
Application.LogMessage ("Execution Time: " + str(TotalTime))
Ahora voy a traducirlo a comandos para comparar tiempos...
-
Utilizando comandos:
# INFO : Execution Time: 16.4850001335
Creí que habría más diferencia la verdad... seguramente no sea buen ejemplo. Donde realmente se notará será en cálculos con muchos objetos, accediendo y cambiando parámetros, etc.
import time
Tic = time.time()
Application.CreatePrim("Grid", "MeshSurface", "grid", "")
Application.SetValue("grid.grid.ulength", 15, "")
Application.SetValue("grid.grid.vlength", 15, "")
Application.SetValue("grid.polymsh.geom.subdivu", 30, "")
Application.SetValue("grid.polymsh.geom.subdivv", 30, "")
Application.CreatePrim("Cube", "MeshSurface", "", "")
Application.SetValue("cube.cube.length", 0.3, "")
Application.Duplicate ("cube", 960)
for i in range (1,960):
cube = "cube"+str(i)
gridPnt = "grid.pnt[%d]"%(i)
Application.ApplyCns("ObjectToCluster", cube, gridPnt, "")
Tac = time.time()
TotalTime = Tac - Tic
Application.LogMessage ("Execution Time: " + str(TotalTime))
-
Vaya, que animado te veo con los scripts.
Si quieres te pido unos cuantos... ^-^
Conoces a agedito?
Es nuestro mega-super-guay hacedor de scripts (vaya publicidad gratuita que le estoy haciendo...XD)
http://www.agedito.com/
No te puedo decir si vas bien o no..porque esto no tengo ni idea. Pero entre tanta gente posteando siempre cosas dentro de lo mismo se agradece un poco de aire fresco.
O0 O0 O0
-
Gracias Epar, la verdad es que no "aspiro" a hacer cosillas tan complicadas como agedito, sino más bien tener una base para poder arreglar las chapucillas que surjan en los proyectos. Y si algo es demasiado complejo... tiro de Houdini ;D
-
Hola Stewie, que gusto ver a otro scripter... :) Llevo tiempo desconectado porque ando sin internet (ahora estoy conectado desde casa de mis suegros).. Me he copiado este hilo, para mirarlo en casa... Lo miro y hablamos, cualquier duda cuanta conmigo :)
-
Muchas gracias agedito, es un tema complicadillo donde es difícil encontrar información (aparte de la ingeniería inversa y la ayuda), así que cualquier ayuda será buena, seguramente te dé la lata bastante! :angel: O0