It is currently 21 Apr 2014, 14:09

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: any scripts can generate curves along the normal ?
PostPosted: 25 May 2012, 05:29 
Offline

Joined: 26 Jun 2011, 06:42
Posts: 20
any scripts or plug-ins can generate curves along the normal ?(polygon face or vertices )
or ICE ?

thx~! :)


Attachments:
curves_eng.jpg
curves_eng.jpg [ 133.77 KiB | Viewed 1263 times ]
Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 25 May 2012, 09:33 
Offline
User avatar

Joined: 07 Jun 2009, 12:30
Posts: 172
Only thing I can tell you is that you can not generate curves with ICE at the moment.
You'd probably have to script that.


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 25 May 2012, 12:56 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
Good little exercise. Select object run script.

Code:
# Python
from win32com.client import constants as c
from win32com.client import Dispatch as d

xsi = Application
log = xsi.LogMessage
collSel = xsi.Selection

def xformFromDirection(vecBase, vecTgt, vecUpV):
    """Creates a transform for base object pointing to target with an upvector upV."""

    vecX = XSIMath.CreateVector3()
    vecY = XSIMath.CreateVector3()
    vecZ = XSIMath.CreateVector3()
    vecToTgt = XSIMath.CreateVector3()
    vecBaseToUpV = XSIMath.CreateVector3()

    vecX.Sub(vecBase,vecTgt)
    vecX.NormalizeInPlace()

    vecBaseToUpV.Sub(vecUpV,vecBase)
    vecBaseToUpV.NormalizeInPlace()

    vecZ.Cross(vecX,vecBaseToUpV)
    vecZ.NormalizeInPlace()

    vecY.Cross(vecZ,vecX)
    vecY.NormalizeInPlace()
   
    return vecX,vecY,vecZ
   

def createCurveNormals(oTgtObj):

    lNormalCurveData = [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [1.0, 1.0]]
   
    oTgtGeo = oTgtObj.ActivePrimitive.Geometry
    collPoints = oTgtGeo.Points
    aNormals = [[y for y in x] for x in list(oTgtGeo.Points.NormalArray)]
    aPositions = [[y for y in x] for x in list(oTgtGeo.Points.PositionArray)]
   
    xformUtil = XSIMath.CreateTransform()
    for i in xrange(collPoints.Count):
        oNormalCrv = oTgtObj.AddNurbsCurve(lNormalCurveData,None,True,1,c.siNonUniformParameterization,c.siSINurbs)
        oNormalCrv.Name = oTgtObj.Name + "_Normal" + str(i).zfill(len(str(collPoints.Count))) + "_Crv"
        xformUtil.SetTranslationFromValues(aPositions[0][i],aPositions[1][i],aPositions[2][i])
       
        if aNormals[1][i] >= 0.001:
            vecUpV = XSIMath.CreateVector3(0,1,0)
            rotUtil = XSIMath.CreateRotation()
            rotUtil.SetFromXYZAnglesValues(0,0,XSIMath.DegreesToRadians(-90))
        else:
            vecUpV = XSIMath.CreateVector3(0,-1,0)
            rotUtil = XSIMath.CreateRotation()
            rotUtil.SetFromXYZAnglesValues(0,XSIMath.DegreesToRadians(-180),XSIMath.DegreesToRadians(-90))
           
        vecX, vecY, vecZ = xformFromDirection(xformUtil.Translation, XSIMath.CreateVector3(aNormals[0][i],aNormals[1][i],aNormals[2][i]), vecUpV)
        xformUtil.SetRotationFromXYZAxes(vecX,vecY,vecZ)
        xformUtil.AddLocalRotation(rotUtil)
        xformUtil.MulInPlace(oTgtObj.Kinematics.Global.GetTransform2(None))
       
        oNormalCrv.Kinematics.Global.PutTransform2(None,xformUtil)
       
createCurveNormals(collSel(0))


_________________
===================
Eric Thivierge
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 25 May 2012, 19:28 
Offline

Joined: 26 Jun 2011, 06:42
Posts: 20
Thanks EricTRocks !
:D

any way to generate the curves along the polygon face normal ?


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 31 May 2012, 17:42 
Offline

Joined: 26 Jun 2011, 06:42
Posts: 20
EricTRocks wrote:
Good little exercise. Select object run script.

Code:
# Python
from win32com.client import constants as c
from win32com.client import Dispatch as d

xsi = Application
log = xsi.LogMessage
collSel = xsi.Selection

def xformFromDirection(vecBase, vecTgt, vecUpV):
    """Creates a transform for base object pointing to target with an upvector upV."""

    vecX = XSIMath.CreateVector3()
    vecY = XSIMath.CreateVector3()
    vecZ = XSIMath.CreateVector3()
    vecToTgt = XSIMath.CreateVector3()
    vecBaseToUpV = XSIMath.CreateVector3()

    vecX.Sub(vecBase,vecTgt)
    vecX.NormalizeInPlace()

    vecBaseToUpV.Sub(vecUpV,vecBase)
    vecBaseToUpV.NormalizeInPlace()

    vecZ.Cross(vecX,vecBaseToUpV)
    vecZ.NormalizeInPlace()

    vecY.Cross(vecZ,vecX)
    vecY.NormalizeInPlace()
   
    return vecX,vecY,vecZ
   

def createCurveNormals(oTgtObj):

    lNormalCurveData = [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [1.0, 1.0]]
   
    oTgtGeo = oTgtObj.ActivePrimitive.Geometry
    collPoints = oTgtGeo.Points
    aNormals = [[y for y in x] for x in list(oTgtGeo.Points.NormalArray)]
    aPositions = [[y for y in x] for x in list(oTgtGeo.Points.PositionArray)]
   
    xformUtil = XSIMath.CreateTransform()
    for i in xrange(collPoints.Count):
        oNormalCrv = oTgtObj.AddNurbsCurve(lNormalCurveData,None,True,1,c.siNonUniformParameterization,c.siSINurbs)
        oNormalCrv.Name = oTgtObj.Name + "_Normal" + str(i).zfill(len(str(collPoints.Count))) + "_Crv"
        xformUtil.SetTranslationFromValues(aPositions[0][i],aPositions[1][i],aPositions[2][i])
       
        if aNormals[1][i] >= 0.001:
            vecUpV = XSIMath.CreateVector3(0,1,0)
            rotUtil = XSIMath.CreateRotation()
            rotUtil.SetFromXYZAnglesValues(0,0,XSIMath.DegreesToRadians(-90))
        else:
            vecUpV = XSIMath.CreateVector3(0,-1,0)
            rotUtil = XSIMath.CreateRotation()
            rotUtil.SetFromXYZAnglesValues(0,XSIMath.DegreesToRadians(-180),XSIMath.DegreesToRadians(-90))
           
        vecX, vecY, vecZ = xformFromDirection(xformUtil.Translation, XSIMath.CreateVector3(aNormals[0][i],aNormals[1][i],aNormals[2][i]), vecUpV)
        xformUtil.SetRotationFromXYZAxes(vecX,vecY,vecZ)
        xformUtil.AddLocalRotation(rotUtil)
        xformUtil.MulInPlace(oTgtObj.Kinematics.Global.GetTransform2(None))
       
        oNormalCrv.Kinematics.Global.PutTransform2(None,xformUtil)
       
createCurveNormals(collSel(0))




i extract some polygon from a model , and run this script , it generate some curves , but the curves are not along the normal ~ :-o


Attachments:
curves_eng_2.jpg
curves_eng_2.jpg [ 125.26 KiB | Viewed 1136 times ]
Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 02 Jun 2012, 10:49 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
Not sure why that would happen. Do the normals look OK when displayed in the viewport? I tested on a sphere and it worked fine for me.

_________________
===================
Eric Thivierge
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 02 Jun 2012, 13:13 
Offline

Joined: 28 Sep 2011, 10:33
Posts: 192
I haven't read the code yet but I've tried it with a few primitives and it only worked with spheres.

_________________
M.Yara
Character Modeler | Softimage Generalist (sort of)


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 02 Jun 2012, 19:05 
Offline

Joined: 26 Jun 2011, 06:42
Posts: 20
EricTRocks wrote:
Not sure why that would happen. Do the normals look OK when displayed in the viewport? I tested on a sphere and it worked fine for me.



I tested on a sphere and it worked fine for me too . but it dosen't works fine on others objects , such as some polygons extract from objects.

here is the scene i test ...when you run the script on the object , it has some problem...


Attachments:
hair_curves_Test.rar [113.81 KiB]
Downloaded 70 times
Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 03 Jun 2012, 03:38 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
I see the issue now. easy to repro on a torus. Will have a go a little later today.

_________________
===================
Eric Thivierge
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
 Post subject: Re: any scripts can generate curves along the normal ?
PostPosted: 03 Jun 2012, 05:03 
Offline
Moderator
User avatar

Joined: 25 Nov 2009, 02:41
Posts: 666
Yeah my maths aren't compensating for certain things. I've built an ICE Tree to figure it out. Just need to translate it into scripting now. I'm going to take another shot using the intrinsic ICE attributes that come with all meshes now. Will post a bit later.

_________________
===================
Eric Thivierge
ethivierge@gmail.com
http://www.ethivierge.com
http://www.exocortex.com/products/species/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group