Re: [script] Particle RotationArray

Date : Fri, 17 Mar 2006 15:25:36 -0500
To : XSI(at)Softimage.COM
From : "Bernard Lebel" <3dbernard(at)gmail.com>
Subject : Re: [script] Particle RotationArray
Thanks Guillaume, I'll check it out.

In the meantime, I don't have the slightest clue why it fixed it, but
it did: I extracted the rotations from the Transform and dumped into a
vector. No modification, nothing special, just extract and dump, and
it works. If someone knows why, don't hesitate!


vRotation = xsimath.createvector3()
oTransform.getrotationxyzangles( vRotation )

aRotationArray[0][i] = vRotation.x
aRotationArray[1][i] = vRotation.y
aRotationArray[2][i] = vRotation.z


Thanks!
Bernard


On 3/17/06, guillaume laforge <guillaume.laforge.3d(at)gmail.com> wrote:
>
> Salut Bernard,
>
> I never deal with "rotationarray" but I made a little script playing with
> particle instances, position and rotation last days :-) :
> http://www.vol2nuit.fr/guillaume/script_simulate.htm
> It use ".rotation" without problem. Maybe you should try to loop on each
> particles and use something like oParticle.rotation ?
>
> Cheers
>
>
> Guillaume Laforge
>
>
>
> On 3/17/06, Bernard Lebel <3dbernard(at)gmail.com> wrote:
> >
> Hello,
>
> I'm writing a script that will hopefully allow me to replace model
> instances by particle instances.
>
> The script creates a particle cloud.
> Then, a model with few objects under it, is used as the particle instance.
> Now the goal is to get a position array and rotation array that will
> match the particle instance to the model instance.
>
> For purpose of testing, there is a only one particle in the cloud, and
> am trying to position and rotate the particle instance exactly like
> the model instance.
>
> The position works like a charm. But the rotation does not, despite
> having identical rotation values.
>
>
>
> #INFO : [[-2.3534693041407944], [59.723917215703089], [2.3083682676149269]]
> Application.CreateParticleType("siBillboardType", "")
> Application.SetParTypeInstanceGroup
> ("ParTypes.PType_mt_prop_bigbush_clear_txt_low1",
> "mt_prop_bigbush_clear_txt_low_group1")
> #INFO : ((-2.3534693717956543,), (59.723918914794922,),
> (2.3083682060241699,))
>
>
>
> If I match the rotations of a cube (using Match Transforms) to the
> model instance, it works....
>
>
>
> Below is the code that I'm using. Am I doing something wrong?
>
> Thanks
> Bernard
>
>
>
>
> # -----------------------------------------------------
> # Import block
>
> import win32com
> from bb_scripting.bb_xsiHandler import xsiHandler
> import random
>
> # -----------------------------------------------------
> # Instantiation block
>
> c = win32com.client.constants
>  xsi = Application
> xsifactory = win32com.client.Dispatch( 'XSI.Factory' )
> xsimath = win32com.client.Dispatch( 'XSI.Math' )
>
> # -----------------------------------------------------
> # Functions block
>
>
>  def getTransformArrays( oSource, oObjects ):
>
>        """
>        Extract the positions of references objects,
>        and organize them in a position array.
>
>        ARGUMENTS:
>        oSource (X3DObject): object to be particle-instantiated
>        oObjects (XSICollection): the object(s) to record the position and
> rotation of
>
>        RETURN VALUE: list of lists (position and rotation arrays)
>        """
>
>        # Create neutral position array
>        aPositionArray = [ [ 0.0 ] * oObjects.count, [ 0.0 ] *
> oObjects.count, [ 0.0 ] * oObjects.count ]
>        aRotationArray = [ [ 0.0 ] * oObjects.count, [ 0.0 ] *
> oObjects.count, [ 0.0 ] * oObjects.count ]
>
>        # Iterate reference objects
>        for i in range( oObjects.count ):
>
>                oObject = oObjects(i)
>
>                # Position
>                aPositionArray[0][i] =
> oObject.Kinematics.Global.Parameters ( 'posx' ).value
>                aPositionArray[1][i] =
> oObject.Kinematics.Global.Parameters( 'posy' ).value
>                aPositionArray[2][i] =
> oObject.Kinematics.Global.Parameters( 'posz' ).value
>
>                aRotationArray[0][i] = oObject.rotx.value
>                aRotationArray[1][i] = oObject.roty.value
>                aRotationArray[2][i] = oObject.rotz.value
>
>
>        return aPositionArray, aRotationArray
>
>
>
>
> # -----------------------------------------------------
> # Script block
>
>
> # Get model to instantiate from selection
> oModel = xsi.selection(0)
>
> # Get a model instance to replace by a particle instance
> oInstances = xsifactory.createobject( 'XSI.Collection ' )
> oInstances.add( xsi.selection(1) )
>
> # Get transform arrays
> tTransformArrays = getTransformArrays( oModel, oInstances )
> aPositionArray = tTransformArrays[0]
> aRotationArray = tTransformArrays[1]
> xsi.logmessage ( str( aRotationArray ) )
>
>
> # Create empty collection to store PType
> # Strictly speaking, this collection will contain only one PType
> oPTypes = xsifactory.createobject( 'XSI.Collection' )
>
> # Create group for particle instantiation
> oGroup = xsi.activesceneroot.addgroup( oModel, '%s_group' % (
> oModel.name ), True )
>
> # Create PType, returns collection
> oPTypeColl = xsi.createparticletype( c.siBillboardType )
>
> # Get PType from collection
> oPType = oPTypeColl(0)
> oPType.name = "PType_%s" % oModel.name
> oPType.parameters( 'LiveForever' ).value = True
> oPType.parameters( 'Inst_Enable' ).value = True
> oPType.parameters( 'Inst_RotationType' ).value = 1
> oPType.parameters( 'Inst_ScalingType' ).value = 3
> oPType.parameters( 'Inst_OGLDisplayType' ).value = 1
>
> # Add PType to main collection
> oPTypes.add( oPType )
>
> # Pick a group, use that as particle instance
> xsi.setpartypeinstancegroup( oPType, oGroup )
>
>
> # Determine how many particle instances we need
> iParticlesCount = oInstances.count
>
> # Extract count value for this PType
> oCloud = xsi.activesceneroot.addparticlecloud ( oPTypes )
> oCloud.name = '%s_ptc' % oModel.name
> oCloudPrim = oCloud.activeprimitive
>
> oCloudPrim.addparticles( iParticlesCount, oPTypes(0) )
>
> oCloud.particles.positionarray = aPositionArray
> oCloud.particles.rotationarray = aRotationArray
>
> xsi.logmessage( str( oCloud.particles.rotationarray ) )
>
> ---
> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
> unsubscribe xsi
>
>

---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.