Isotropix Forums

Help with particle creation normals math? :)

Clarisse Scripting related topics

Help with particle creation normals math? :)

Unread postby atnreg » Mon Apr 29, 2019 2:38 pm

Hi!

As Clarisse has no radial point array, I thought it should be easy to make one with ParticleContainer.
And it is, basically but the normals are problem for me :shock:

Please load the attached project to see the problem :)
But for ideal result I would like to get the rotation and scale as properties, I tried to adapt the code from bake_scatterer.py but the rotation did not have any effect :o So that would very pleasant bonus but the main thing is how to get the normals correct :)

Here is the code that kind of works:
Code: Select all
import math
particlecontainer=ix.get_item("project://scene/container") # note the path here :)
numpts=10
radius=5

locarr=ix.api.GMathVec3dArray(numpts)
normarr=ix.api.GMathVec3dArray(numpts)
step=360/numpts
cx=0
cy=0
cz=0
pidx=0
ix.cmds.ClearParticle([particlecontainer])
for pt in range(numpts):
    ang=pt*step
    px=cx+math.cos(math.radians(ang))*radius
    pz=cx+math.sin(math.radians(ang))*radius
    py=0
    locarr[pidx]=ix.api.GMathVec3d(px, py, pz)
    normarr[pidx] = ix.api.GMathVec3d(-px, -py, -pz)
    pidx+=1

ix.cmds.AddParticle(particlecontainer, locarr, normarr)


The problem is that the items rotate around their y axis nicely but unintentionally and I cannot get rid of that.
I have tried to understand how to use Clarisse math classes but so far no luck...

Thank you very much!

Antti
Attachments
particleradialarray.project
(47.73 KiB) Downloaded 39 times
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Help with particle creation normals math? :)

Unread postby dboude » Mon Apr 29, 2019 4:36 pm

Hi,

Your problem is not the normals. Normals are vectors and you can't define a rotation with just one vector. You have to create a property for each point and drive the rotation input to set the correct rotation on the Y-axis.

Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1026
Joined: Mon Jul 03, 2017 10:51 am

Re: Help with particle creation normals math? :)

Unread postby atnreg » Mon Apr 29, 2019 5:40 pm

Hi!
Thanks, I though the rotation would be better way and tried to adapt the bake_scatterer particle properties code here but I could not get it to work.
The particle container has the property and it has correct counts etc. but it has no effect on rotation :o

Could you please check and tell what I did wrong? :)

BTW, is there any way to see the property data i.e. print it out to log?

Thank you !

Antti
Attachments
particleradialarray_v001.project
(48.95 KiB) Downloaded 43 times
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Help with particle creation normals math? :)

Unread postby atnreg » Tue Apr 30, 2019 9:48 am

Hi!
I noticed I had no extract property in the previous version, this one has but still it does not work :(
Please help, what I do wrong? Everything SEEMS similar to baked painted particles and the objects rotate if I adjust the Color of the extract property so to me it seems that the rotations are not saved to particles but they are (code below prints them out) :?
Just copy/paste this to new project script editor, the code creates all needed items :)

Thank you!

Code: Select all
import math
particlecontainer=ix.cmds.CreateObject("gen_container","GeometryParticleContainer")
extr_rot=ix.cmds.CreateObject("gen_extr_rotation", "TextureExtractProperty")
scat=ix.cmds.CreateObject("gen_scatterer", "SceneObjectScatterer")
scatgeo=ix.cmds.CreateObject("gen_proxy","GeometryBox")

numpts=8
radius=5

pos = ix.api.GMathVec3f()
positions = ix.api.GMathVec3fVector()

rotation = ix.api.ResourceProperty("rotation")
rotation.init(ix.api.ResourceProperty.TYPE_FLOAT_32, 3, numpts)

step=360//numpts
cx=0
cy=0
cz=0
pidx=0
ix.cmds.ClearParticle([particlecontainer])
for ang in range(0,360,step):
    px=cx+math.sin(math.radians(ang))*radius
    pz=cx+math.cos(math.radians(ang))*radius
    py=0
    pos[0]=px
    pos[1]=py
    pos[2]=pz
    positions.add(pos)
    rotation.set_float(pidx, 0, 0)
    rotation.set_float(pidx, float(ang), 1)
    rotation.set_float(pidx, 0, 2)
    pidx+=1

ix.api.IOHelpers.set_particles(particlecontainer, positions)
properties = ix.api.ResourcePropertyArray(1)
# check that the rotations are correct
print "rotations:"
for i in range(pidx):
    rot=rotation.get_float(i)
    print i,rot[0],rot[1],rot[2]
properties[0] = rotation
ix.api.IOHelpers.set_particles_properties(particlecontainer, properties)
scat.attrs.geometry_support = particlecontainer
scat.attrs.scatter_rotation.attr.set_texture(extr_rot)
scat.attrs.scatter_rotation[0] = 360
scat.attrs.scatter_rotation[1] = 360
scat.attrs.scatter_rotation[2] = 360
extr_rot.attrs.property_name = "rotation"
scat.attrs.use_support_normals=1
ix.cmds.SetValueCount([str(scat)+".geometry", str(scat)+".collision_object"], [1, 1])
ix.cmds.SetValues([str(scat)+".geometry[0]", str(scat)+".probability[0]"], [str(scatgeo), "1.0"])
print "particle property rotation:"
for i in range(pidx):
    rot=ix.api.IOHelpers.get_particles_property(particlecontainer, "rotation", i)
    print i,rot
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Help with particle creation normals math? :)

Unread postby dboude » Tue Apr 30, 2019 9:57 am

First, you have to use extract property node that is missing in your scene. I guess you saved/upload the wrong project.

As the input texture of the scatterer rotation attribute acts like a multiplier you have to divide the properties by 360 in your case (see the attached project) when reading the properties or when writing the properties. This last case is better and avoids to use a divide node after.

You'll find script snippets on the forum to read and display points property values in the log, just have a quick search.

particleradialarray_fixed.project
(42.47 KiB) Downloaded 44 times


Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1026
Joined: Mon Jul 03, 2017 10:51 am

Re: Help with particle creation normals math? :)

Unread postby atnreg » Tue Apr 30, 2019 10:05 am

(sorry I missed your next post before posting this so I 'removed' this post, forget this)
Last edited by atnreg on Tue Apr 30, 2019 10:45 am, edited 2 times in total.
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Help with particle creation normals math? :)

Unread postby dboude » Tue Apr 30, 2019 10:34 am

Like I said, you have to divide the rotation by 360 :

rotation.set_float(pidx, 0, 0)
rotation.set_float(pidx, (float(ang))/360, 1)
rotation.set_float(pidx, 0, 2)

And then you can remove the whole commented line.

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1026
Joined: Mon Jul 03, 2017 10:51 am

Re: Help with particle creation normals math? :)

Unread postby atnreg » Tue Apr 30, 2019 10:44 am

I didn't notice your previous post before my previous post so I emptied that because the extra color setting is indeed not needed (and it didn't even work after all) :)
Thank you VERY much, now it works and what is best, I UNDERSTAND how and why it works :mrgreen:
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Help with particle creation normals math? :)

Unread postby dboude » Tue Apr 30, 2019 10:59 am

By the way, you can achieve the same result with expressions and a little setup. You keep it procedural this way.

Here have a look. Select "Control" and play with sliders.

Image

Points_Circle.project
(44.68 KiB) Downloaded 44 times


Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1026
Joined: Mon Jul 03, 2017 10:51 am

Re: Help with particle creation normals math? :)

Unread postby atnreg » Tue Apr 30, 2019 12:03 pm

WOW cool :)
I even think I understand how it works :shock:
But why it stops working totally if I remove the limit from the control.radius? The project version only allows radius up to 1.0 and if I remove the limit, the whole things breaks :O So I cannot get it to work like on your video above :?

But one more challenge for you :D, try to make it arc i.e. with start and end angles, is that possible? :mrgreen:

I knew expressions are cool but obviously they are even cooler, thank you!
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0SP3,Blender2.80,Fusion360,ZBrush,Onyx,Houdini,SubstPnt...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 502
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Next

Return to Scripting