Mailing List
Home
Forum Home
Softimage
Carrara
trueSpace
Dir3d-l
Maya - a powerful 3D animation and visual effects software
Macromedia Flash Development
Subjects
Cameras
scaleDown command
black out solved
Aircraft Tutorial
Mathematical XYZ ?
Its done This vs That
Its done first week
recommendations for screen video captures?
3DExplorer "Oddity "
New Director
ProTeam renewals
Fuel 's new websites (X post)
Blue peter create a make toy
targeting groups question
XPost: Shockwave 3D game ( sort of )
RES: RES: RES: Fish Modeling
Emitting particles from object intersection
Fuel 's new websites (X post)
Texturing
Big Break Contest Videos
New Plugins
Models and Texture on my updated site
Error Installing Patch tS6 6
Plasma?
Looking for Inspiration
Weird EMail Q
It 's done first week ?
Cherry not cranberry
New game
Camera Animation Problem
Particle plugins?
 
Running scripts are slow - newbie

Running scripts are slow - newbie

2005-05-24       - By Rafe Sacks

 Back
Reply:     <<     11     12     13     14     15     16     17     18  

In general...Avoid selecting anything or running XSI Commands more times
then you have to.

   1) CreateImageClip should either return the image clip for use so
   you don't have to use SelectObj(), or there should be another
   version which does. For instance (just removing this one SelectObj()
   should yield a sizable improvement)

for each oCube in oColl    
  selectObj oCube

    oCube is already an object. Why select it?



   2) If you are adding the same material to 100+ objects, you should
   be able to do it to all objects at once rather then for each object.
   Most commands take a collection or object list. It takes a LOT less
   precessing time to manipulate strings then to run an XSI Command.
   Instead of...

           CreateImageClip "...\Mosaic_test_mdb\Pictures\keith.pic"
           SelectObj "Clips.keith_pic"
           set oImageClip = Selection(0)

n Can you do?...
 

           set oImageClip = CreateImageClip
           "...\Mosaic_test_mdb\Pictures\keith.pic"






These 2 ideals will increase the speed of your code /dramatically/.

Good luck!

--

__ ____ ____ ____ ____ ____ ____
R A F E   S A C K S
Lead Character TD - Technical
Animal Logic Film
+612  9383 - 4800




Jeff McFall wrote:

>Well it took a bit longer than an evening ;) but I think Ive mostly made the
transition to the object model for at least parts of this.
>This is my first real XSI script let alone something using the OM so Im pretty
happy with the results - that it even works)
>Ive learned a ton - thanks to Kim and Bernard for their tips.
>
>In researching this I am prety sure there are some additional ways to
streamline this.
>Still takes about 4 minutes on my machine to do the 1500 odd objects.
>
>Much thanks
>
>Jeff
>
>
>
>CreateImageClip "...\Mosaic_test_mdb\Pictures\keith.pic"
>
>SelectObj "Clips.keith_pic"
>
>
>set oImageClip = Selection(0)
>
>set oImage = oImageClip.GetImage
>
>' set the keyframe #
>Tframe = 31
>
>set oColl = createobject( "XSI.Collection" )
>
>' wild card select of everything cube!!!
>oColl.Items = "Cube*"
>
>for each oCube in oColl
>    
>   selectObj oCube
>
>
>xPos = oCube.posX.Value
>yPos = oCube.posZ.Value
>  
>
>' objects X and Z positions must be within the bounds of the resolution of the
image being used
>' my example uses an image of 720 x 540
>
>     xImagepos = CInt(720 - (xPos*100))
>     yImagepos = CInt(540 - (yPos*100))
>    
>
>' read the texture and apply the material
>    
>
>       set oPixelColor = oImage.GetPixel (xImagepos , yImagepos)  
>      
>       oCube.AddMaterial( "Phong")
>
>       Set oPhong = oCube.Material.Shaders( "Phong" )
>
>       set MatDifRed = oPhong.diffuse.red.AddFCurve()
>       set MatDifgreen = oPhong.diffuse.green.AddFCurve()
>       set MatDifblue = oPhong.diffuse.blue.AddFCurve()
>
>       MatDifRed.AddKey Tframe, oPixelColor.Red
>       MatDifRed.AddKey Tframe, oPixelColor.Green
>       MatDifRed.AddKey Tframe, oPixelColor.Blue
>
>       set MatAmbRed = oPhong.ambient.red.AddFCurve()
>       set MatAmbgreen = oPhong.ambient.green.AddFCurve()
>       set MatAmbblue = oPhong.ambient.blue.AddFCurve()
>
>       MatDifRed.AddKey Tframe, oPixelColor.Red
>       MatDifGreen.AddKey Tframe, oPixelColor.Green
>       MatDifBlue.AddKey Tframe, oPixelColor.Blue
>
>      
>      
>' lift them  
>  
>       height = ((oPixelColor.Red + oPixelColor.blue + oPixelColor.green) * 1.5)
>      
>       set lift = oCube.posY.AddFCurve()
>       lift.Addkey Tframe, height
>      
>' size them    * I bet there is a way to do this with 1 command
>
>
>       size = (oPixelColor.Red + oPixelColor.blue + oPixelColor.green)
>      
>       set bigness = oCube.sclx.AddFCurve()
>       bigness.Addkey Tframe, size
>      
>       set bigness = oCube.scly.AddFCurve()
>       bigness.Addkey Tframe, size  
>      
>       set bigness = oCube.sclz.AddFCurve()
>       bigness.Addkey Tframe, size
>
>next
>
>
>
>
>
>
>
>
>
>
>
>
>
>-- --Original Message-- --
>From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of
kim aldis
>Sent: Monday, May 23, 2005 5:11 PM
>To: XSI@(protected)
>Subject: RE: Running scripts are slow - newbie
>
>Here's another tip:
>
>For I = 1 to 1567
>
>Is a bit specific and you probably had to go to work on the scene to figure
that number out. Try something like this instead, which should ease you into
the OM gently by relieving you of a selectobj at the same time:-
>
>
>
>set oColl = createobject( "XSI.Collection" )
>
>' wild card select of everything cube!!!
>oColl.Items = "Cube*"
>
>for each oCube in oColl
>  
>     logmessage oCube
>  
>next
>
>-- --Original Message-- --
>From: owner-xsi@(protected) [mailto:owner-xsi@(protected)] On Behalf Of
Bernard Lebel
>Sent: 23 May 2005 20:55
>To: XSI@(protected)
>Subject: Re: Running scripts are slow - newbie
>
>First of all, I you have 1500 objects, you may not want to print their name.
>Each time you log a message it ads to the execution time. On a small bunch of
object it doesn't matter that much, but on longer lists it may affect execution
time significantly. If you really want a log message to show progress you may
print such message only once every 10 or 100 objects. Only when the script is
giving you troubles you will force it to print every object.
>
>Now Kim is 100% right, using the object model instead of the command model
will make your scripts enormously faster. In fact, do not pretend you know
scripting until you use the object model (or at least know how to use it!)
>;-)
>
>So lets's look at the various of your script... (see [Bernard] below)
>
>
>Jeff McFall wrote:
>
>  
>
>>CreateImageClip " .... \VIDEO_ELEMENTS\Mosaic_test_mdb\Pictures\relief.pic"
>>    
>>
>
>  
>
>>SelectObj "Clips.relief_pic"
>>
>>set oImageClip = Selection(0)
>>set oImage = oImageClip.GetImage
>>
>>
>>for i = 1 to 1567
>>
>>
>>SelectObj("cube" & i)
>>
>>'   show where we are
>>logmessage i
>>
>>
>>    
>>
>[Bernard] Remove this logmessage, as explained above.
>
>  
>
>>xPos = Selection(0).posX.Value
>>yPos = Selection(0).posZ.Value
>>
>>
>>     xImagepos = CInt(720 - (xPos*100))
>>     yImagepos = CInt(540 - (yPos*100))
>>    
>>
>>       set oPixelColor = oImage.GetPixel (xImagepos ,
>>    
>>
>yImagepos)  
>  
>
>>      
>>       ApplyShader "Phong"
>>      
>>    
>>       SetKey obj & ".Material.Phong.Diffuse.red", 91 ,
>>    
>>
>oPixelColor.Red
>  
>
>>       SetKey obj & ".Material.Phong.Diffuse.green", 91 ,
>>    
>>
>oPixelColor.Green
>  
>
>>       SetKey obj & ".Material.Phong.Diffuse.blue",  91 ,
>>    
>>
>oPixelColor.Blue
>  
>
>>      
>>       SetKey obj & ".Material.Phong.Ambient.red",  91 ,
>>    
>>
>oPixelColor.Blue
>  
>
>>       SetKey obj & ".Material.Phong.Ambient.green", 91 ,
>>    
>>
>oPixelColor.Blue
>  
>
>>       SetKey obj & ".Material.Phong.Ambient.blue", 91 ,
>>    
>>
>oPixelColor.Blue
>  
>
>>
>>
>>    
>>
>[Bernard] There is a way to replace the set key commands. First, apply an
fcurve to the parameters you wish to keyframe. The AddFCurve() method will
return a FCurve object. Now use that object to add keyframes, with the AddKey()
method.
>The AddKey() entry in the docs have a good example of how to do these two
things.
>
>  
>
>>      
>>            
>>       height = ((oPixelColor.Red + oPixelColor.blue +
>>    
>>
>oPixelColor.green) * 1.5)
>  
>
>>       size = (oPixelColor.Red + oPixelColor.blue +
>>    
>>
>oPixelColor.green)
>  
>
>>      
>>    
>>       SetKey  obj & ".kine.local.posy", 91, height
>>        
>>      
>>       SetKey  obj & ".kine.local.sclx", 91 , size
>>       SetKey  obj & ".kine.local.scly", 91 , size
>>       SetKey  obj & ".kine.local.sclz", 91 , size
>>
>>      
>>next
>>
>>
>>    
>>
>[Bernard] The same applies. Instead of setting keys onto the transformation of
the object, you should add fcurves and use addkey().
>
>
>Cheers
>Bernard
>
>---
>Unsubscribe? Mail Majordomo@(protected) with the following text in body:
>unsubscribe xsi
>
>
>---
>Unsubscribe? Mail Majordomo@(protected) with the following text in body:
>unsubscribe xsi
>
>---
>Unsubscribe? Mail Majordomo@(protected) with the following text in body:
>unsubscribe xsi
>  
>






<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1">
 <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<font color="#000099">In general...Avoid selecting anything or running
XSI Commands more times then you have to.<br>
</font>
<blockquote><font color="#000099">1) CreateImageClip should either
return the image clip for use so you don't have to use SelectObj(), or
there should be another version which does. For instance (just removing
this one </font><font color="#000099">SelectObj() should yield a
sizable improvement</font><font color="#000099">)</font><br>
 <blockquote>
   <blockquote>
     <pre wrap=""><font color="#000000">for each oCube in oColl    
  selectObj oCube</font></pre>
   </blockquote>
 </blockquote>
 <font color="#000099">&nbsp;oCube is already an object. Why select it?</font>
<br>
 <br>
 <br>
 <br>
 <font color="#000099">2) If you are adding the same material to 100+
objects, you should be able to do it to all objects at once rather then
for each object. Most commands take a collection or object list. It
takes a LOT less precessing time to manipulate strings then to run an
XSI Command. Instead of...<br>
 </font>
 <blockquote>
   <blockquote>CreateImageClip
"...\Mosaic_test_mdb\Pictures\keith.pic" <br>
SelectObj "Clips.keith_pic" <br>
set oImageClip = Selection(0) <br>
   </blockquote>
 </blockquote>
 <pre wrap="">
<font color="#000099">n Can you do?...</font>
 </pre>
 <blockquote>
   <blockquote>set oImageClip = CreateImageClip
"...\Mosaic_test_mdb\Pictures\keith.pic"</blockquote>
 </blockquote>
 <br>
</blockquote>
<font color="#000099"><br>
<br>
<br>
<br>
These 2 ideals will increase the speed of your code <i>dramatically</i>.
<br>
<br>
Good luck!</font><br>
<br>
-- <br>
<div class="moz-signature">
<meta http-equiv="content-type" content="text/html; ">
<title>RafeSignature</title>
<meta name="author" content="Rafe Sacks">
<pre wrap=""><small><font face="Century Gothic"><font color="#000066"><font
color="#000066"><font color="#c0c0c0"
style="color: rgb(192, 192, 192);"><span
style="font-family: helvetica,arial,sans-serif;"></span></font></font></font><
/font></small><span
style="font-family: helvetica,arial,sans-serif; color: rgb(204, 204, 204);">
<small><big><small><font
face="Century Gothic"><small><span
style="font-family: helvetica,arial,sans-serif;"></span></small></font></small
></big></small></span><span
style="color: rgb(102, 102, 102); font-family: helvetica,arial,sans-serif;">
<span
style="color: rgb(153, 153, 153);"><span
style="font-family: helvetica,arial,sans-serif;"><span
style="color: rgb(102, 102, 102); font-family: helvetica,arial,sans-serif;">
<small><font
color="#000066"><font color="#000066"><font color="#c0c0c0"
style="color: rgb(204, 204, 204);">__ ____ ____ ____ ____ ____ ____</font>
</font></font><font style="font-family: helvetica,arial,sans-serif;"><font
color="#000066"><small><small><font color="#666666"><big><font
color="#000066"><big><big><small style="font-weight: bold;">R A F E   S A C K
S</small><span
style="font-weight: bold;"></span></big>
</big></font></big></font></small></small></font></font></small><small
style="color: rgb(153, 153, 153);"><big><small><small><span
style="color: rgb(192, 192, 192);">Lead Character TD - Technical</span>
<span style="color: rgb(192, 192, 192);">Animal Logic Film</span>
<span style="color: rgb(192, 192, 192);">+612  9383 - 4800</span>

</small></small></big></small></span></span></span></span></pre>
</div>
<br>
<br>
<br>
Jeff McFall wrote:<br>
<blockquote type="cite"
cite="midE88D3DBFB70A0848BD568E95ED5CDB9704EBBEB2@(protected)">
 <pre wrap="">Well it took a bit longer than an evening ;) but I think Ive
mostly made the transition to the object model for at least parts of this.
This is my first real XSI script let alone something using the OM so Im pretty
happy with the results - that it even works)
Ive learned a ton - thanks to Kim and Bernard for their tips.

In researching this I am prety sure there are some additional ways to
streamline this.
Still takes about 4 minutes on my machine to do the 1500 odd objects.

Much thanks

Jeff



CreateImageClip "...\Mosaic_test_mdb\Pictures\keith.pic"

SelectObj "Clips.keith_pic"


set oImageClip = Selection(0)

set oImage = oImageClip.GetImage

' set the keyframe #
Tframe = 31

set oColl = createobject( "XSI.Collection" )

' wild card select of everything cube!!!
oColl.Items = "Cube*"

for each oCube in oColl
   
  selectObj oCube


xPos = oCube.posX.Value
yPos = oCube.posZ.Value
 

' objects X and Z positions must be within the bounds of the resolution of the
image being used
' my example uses an image of 720 x 540

    xImagepos = CInt(720 - (xPos*100))
    yImagepos = CInt(540 - (yPos*100))
   

' read the texture and apply the material
   

      set oPixelColor = oImage.GetPixel (xImagepos , yImagepos)  
     
      oCube.AddMaterial( "Phong")

      Set oPhong = oCube.Material.Shaders( "Phong" )

      set MatDifRed = oPhong.diffuse.red.AddFCurve()
      set MatDifgreen = oPhong.diffuse.green.AddFCurve()
      set MatDifblue = oPhong.diffuse.blue.AddFCurve()

      MatDifRed.AddKey Tframe, oPixelColor.Red
      MatDifRed.AddKey Tframe, oPixelColor.Green
      MatDifRed.AddKey Tframe, oPixelColor.Blue

      set MatAmbRed = oPhong.ambient.red.AddFCurve()
      set MatAmbgreen = oPhong.ambient.green.AddFCurve()
      set MatAmbblue = oPhong.ambient.blue.AddFCurve()

      MatDifRed.AddKey Tframe, oPixelColor.Red
      MatDifGreen.AddKey Tframe, oPixelColor.Green
      MatDifBlue.AddKey Tframe, oPixelColor.Blue

     
     
' lift them  
 
      height = ((oPixelColor.Red + oPixelColor.blue + oPixelColor.green) * 1.5)
     
      set lift = oCube.posY.AddFCurve()
      lift.Addkey Tframe, height
     
' size them    * I bet there is a way to do this with 1 command


      size = (oPixelColor.Red + oPixelColor.blue + oPixelColor.green)
     
      set bigness = oCube.sclx.AddFCurve()
      bigness.Addkey Tframe, size
     
      set bigness = oCube.scly.AddFCurve()
      bigness.Addkey Tframe, size  
     
      set bigness = oCube.sclz.AddFCurve()
      bigness.Addkey Tframe, size

next













-- --Original Message-- --
From: <a class="moz-txt-link-abbreviated" href="mailto:owner-xsi@(protected)"
>owner-xsi@(protected)</a> [<a class="moz-txt-link-freetext" href="mailto
:owner-xsi@(protected)">mailto:owner-xsi@(protected)</a>] On Behalf Of kim
aldis
Sent: Monday, May 23, 2005 5:11 PM
To: <a class="moz-txt-link-abbreviated" href="mailto:XSI@(protected)">XSI
@(protected)</a>
Subject: RE: Running scripts are slow - newbie

Here's another tip:

For I = 1 to 1567

Is a bit specific and you probably had to go to work on the scene to figure
that number out. Try something like this instead, which should ease you into
the OM gently by relieving you of a selectobj at the same time:-



set oColl = createobject( "XSI.Collection" )

' wild card select of everything cube!!!
oColl.Items = "Cube*"

for each oCube in oColl
 
    logmessage oCube
 
next

-- --Original Message-- --
From: <a class="moz-txt-link-abbreviated" href="mailto:owner-xsi@(protected)"
>owner-xsi@(protected)</a> [<a class="moz-txt-link-freetext" href="mailto
:owner-xsi@(protected)">mailto:owner-xsi@(protected)</a>] On Behalf Of
Bernard Lebel
Sent: 23 May 2005 20:55
To: <a class="moz-txt-link-abbreviated" href="mailto:XSI@(protected)">XSI
@(protected)</a>
Subject: Re: Running scripts are slow - newbie

First of all, I you have 1500 objects, you may not want to print their name.
Each time you log a message it ads to the execution time. On a small bunch of
object it doesn't matter that much, but on longer lists it may affect execution
time significantly. If you really want a log message to show progress you may
print such message only once every 10 or 100 objects. Only when the script is
giving you troubles you will force it to print every object.

Now Kim is 100% right, using the object model instead of the command model will
make your scripts enormously faster. In fact, do not pretend you know scripting
until you use the object model (or at least know how to use it!)
;-)

So lets's look at the various of your script... (see [Bernard] below)


Jeff McFall wrote:

 </pre>
 <blockquote type="cite">
   <pre wrap="">CreateImageClip " .... \VIDEO_ELEMENTS\Mosaic_test_mdb
\Pictures\relief.pic"
   </pre>
 </blockquote>
 <pre wrap=""><!---->
 </pre>
 <blockquote type="cite">
   <pre wrap="">SelectObj "Clips.relief_pic"

set oImageClip = Selection(0)
set oImage = oImageClip.GetImage


for i = 1 to 1567


SelectObj("cube" &amp; i)

'   show where we are
logmessage i


   </pre>
 </blockquote>
 <pre wrap=""><!---->[Bernard] Remove this logmessage, as explained above.

 </pre>
 <blockquote type="cite">
   <pre wrap="">xPos = Selection(0).posX.Value
yPos = Selection(0).posZ.Value


    xImagepos = CInt(720 - (xPos*100))
    yImagepos = CInt(540 - (yPos*100))
   

      set oPixelColor = oImage.GetPixel (xImagepos ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->yImagepos)  
 </pre>
 <blockquote type="cite">
   <pre wrap="">      
      ApplyShader "Phong"
     
   
      SetKey obj &amp; ".Material.Phong.Diffuse.red", 91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Red
 </pre>
 <blockquote type="cite">
   <pre wrap="">       SetKey obj &amp; ".Material.Phong.Diffuse.green", 91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Green
 </pre>
 <blockquote type="cite">
   <pre wrap="">       SetKey obj &amp; ".Material.Phong.Diffuse.blue",  91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Blue
 </pre>
 <blockquote type="cite">
   <pre wrap="">      
      SetKey obj &amp; ".Material.Phong.Ambient.red",  91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Blue
 </pre>
 <blockquote type="cite">
   <pre wrap="">       SetKey obj &amp; ".Material.Phong.Ambient.green", 91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Blue
 </pre>
 <blockquote type="cite">
   <pre wrap="">       SetKey obj &amp; ".Material.Phong.Ambient.blue", 91 ,
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.Blue
 </pre>
 <blockquote type="cite">
   <pre wrap="">

   </pre>
 </blockquote>
 <pre wrap=""><!---->[Bernard] There is a way to replace the set key commands.
First, apply an fcurve to the parameters you wish to keyframe. The AddFCurve()
method will return a FCurve object. Now use that object to add keyframes, with
the AddKey() method.
The AddKey() entry in the docs have a good example of how to do these two
things.

 </pre>
 <blockquote type="cite">
   <pre wrap="">      
           
      height = ((oPixelColor.Red + oPixelColor.blue +
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.green) * 1.5)
 </pre>
 <blockquote type="cite">
   <pre wrap="">       size = (oPixelColor.Red + oPixelColor.blue +
   </pre>
 </blockquote>
 <pre wrap=""><!---->oPixelColor.green)
 </pre>
 <blockquote type="cite">
   <pre wrap="">      
   
      SetKey  obj &amp; ".kine.local.posy", 91, height
       
     
      SetKey  obj &amp; ".kine.local.sclx", 91 , size
      SetKey  obj &amp; ".kine.local.scly", 91 , size
      SetKey  obj &amp; ".kine.local.sclz", 91 , size

     
next


   </pre>
 </blockquote>
 <pre wrap=""><!---->[Bernard] The same applies. Instead of setting keys onto
the transformation of the object, you should add fcurves and use addkey().


Cheers
Bernard

---
Unsubscribe? Mail <a class="moz-txt-link-abbreviated" href="mailto:Majordomo
@(protected)">Majordomo@(protected)</a> with the following text in body:
unsubscribe xsi


---
Unsubscribe? Mail <a class="moz-txt-link-abbreviated" href="mailto:Majordomo
@(protected)">Majordomo@(protected)</a> with the following text in body:
unsubscribe xsi

---
Unsubscribe? Mail <a class="moz-txt-link-abbreviated" href="mailto:Majordomo
@(protected)">Majordomo@(protected)</a> with the following text in body:
unsubscribe xsi
 </pre>
</blockquote>
<br>
<br>
<div class="moz-signature">
<pre wrap=""><span
style="color: rgb(102, 102, 102); font-family: helvetica,arial,sans-serif;">
<span
style="color: rgb(153, 153, 153);"><span
style="font-family: helvetica,arial,sans-serif;"><span
style="color: rgb(102, 102, 102); font-family: helvetica,arial,sans-serif;">
<small
style="color: rgb(153, 153, 153);"><big><small><small>

</small></small></big></small></span></span></span></span><span
style="color: rgb(102, 102, 102); font-family: helvetica,arial,sans-serif;">
<small
style="color: rgb(153, 153, 153);"><big><small><font
face="Century Gothic"><small><span
style="font-family: helvetica,arial,sans-serif;">
</span></small></font></small></big></small></span></pre>
</div>
</body>
</html>