Problems rotating, and a material flaw

George,

I’ve now responded to you this via email.

Richard

Hiya all.

So it’s late at night again and I can’t see what I’m doing wrong.

So I’ll post a message in hope that someone can help. andnbsp;I don’t know if I can
even describe the problem well enough,but here goes. andnbsp;I don’t actually expect
help, but writing the problem might shine a light.

I’m writing a plugin that will copy an object onto the surface of another.
For example, many copies in a small area will make grass or hair. andnbsp;Less dense
copies could be used as billboards.

I can successfully copy so that the copies are aligned the same way as the original.
This is ok for grass or hair that would normally be perpendicular. andnbsp;I can also
rotate and scale the objects as I wish – either randomly or along a gradient. andnbsp;The
first two pictures show this working.

But I want to also align them to the normal of the face where they are being
copied, and this is what is shagged. andnbsp;the third picture shows that I get
extra rotations. andnbsp;Here is the code:

‘Before we make the points see if orientation should be to normal and adjust accordingly
andnbsp; if OrientToNormal=true then
andnbsp; andnbsp; TargetFace.GetFaceNormal FaceNormalX,FaceNormalY,FaceNormalZ
andnbsp; andnbsp; ‘Should only need two rotations…
andnbsp; andnbsp; andnbsp;if FaceNormalZ=0 then NormalYRotation=0 else NormalYRotation=atn(FaceNormalX/FaceNormalZ)
andnbsp; andnbsp; andnbsp;if FaceNormalX=0 then NormalZRotation=0 else NormalZRotation=atn(FaceNormalY/FaceNormalX)
andnbsp; end if

The NormalYRotation is added to the other rotations that are needed to align the object
groups and the variation in copy rotations. andnbsp;I’m sure there’s someone out there
deleriously happy to tackle this on a Sat night… anyway moving on.

Here’s another problem. andnbsp;the following code works except when the object has
been acted upon using the andquot;divideandquot; operation. andnbsp;It then crashes as the NewFace.SetMaterial
line (Object variable or with block variable not set 91??)

‘*******make the faces
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;For Xi=0 to OldFaceCount-1
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; set OldFace=OldObject.GetFace(Xi)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; set NewFace = NewObject.CreateFace andnbsp; ‘ the new face from the old to the new
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; OldNumFacePoints=OldFace.GetPointCount
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;For Yi=0 to (OldNumFacePoints-1)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;OldFacePointIndex=OldFace.GetPoint(Yi)
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;NewObjectPointIndex=OldFacePointIndex+OldPointCount*CopyNum andnbsp; andnbsp; andnbsp;
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;NewFace.AddPointandNormal andnbsp;NewObjectPointIndex,0
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;Next andnbsp; ‘Yi
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; andnbsp;NewFace.SetMaterial(OldFace.GetMaterial())
andnbsp; andnbsp; andnbsp; andnbsp; andnbsp; Next andnbsp; andnbsp; andnbsp;’Xi

That’s all for now. andnbsp;If anyone is interested I will make the plugin available – if
it ever works. andnbsp;There are a zillion possible refinements, but I think it will
be useful.

George

Hi George,

#1- Are you remembering to center your objects on 0,0,0 before rotating their points?

#2- I’d be happy to debug this if you can provide a script that fails.

Richard

George <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –>

____________________________________________________

andquot;I can also rotate and scale the objects as I wish – either randomly or along a gradient. The first two pictures show this workingandquot;
____________________________________________________

I’m interested in Grouping and Rotating Objects…would you/I be able to modify the code along these lines ? I think either way this Plugin would be very usefull to me <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –>

I’m sorry I cann’t help with your problem as I’m still learning VB6 at the moment…

George <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –>

Thank’s George…I can read the code, but will need to learn more to totally understand how it works !

I’ve found out that the more I read the more things make sense, so this code will be very usefull to me andnbsp;:)

Because you know Vb6 and can write this code for Rotation, It helps me more than trying to write the code from scratch and blindly going nowhere…

Probable, but let me get it working first <!– s:-) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile" /><!– s:-) –>

This may be useful. andnbsp;It’s how to get the rotation of the group, as given by the properties in the model design screen, by using the GetOrientation method. andnbsp;The answers are rotations around the axes in radians. andnbsp;It’s pasted all squashed by you may be able to read it.

George

set OldObjectGroup=OldObject.GetParentGroup
andnbsp; andnbsp;’Where is the old object group?
andnbsp; andnbsp;OldObjectGroup.GetPosition Nothing,OldGroupX,OldGroupY,OldGroupZ
andnbsp; andnbsp;OldObjectGroup.GetOrientation TargetObjectGroup,OldGroupRX,OldGroupRY,OldGroupRZ,OldGroupUpX,OldGroupUpY,OldGroupUpZ
andnbsp; andnbsp;’msgbox(andquot;rots andquot;andamp; OldGroupRX andamp;andquot; andquot;andamp; OldGroupRYandamp;andquot; andquot;andamp;OldGroupRZandamp;andquot; andquot;andamp;OldGroupUpXandamp;andquot; andquot;andamp;OldGroupUpYandamp;andquot; andquot;andamp;OldGroupUpZ)
andnbsp; andnbsp;’this igves us two vectors, but we need rotations around the axes
andnbsp; andnbsp;if OldGroupRZ=0 then OldOrientX=0 else OldOrientX=Atn(OldGroupRY/OldGroupRZ)
andnbsp; andnbsp;if OldGroupRZ=0 then OldOrientY=0 else OldOrientY=Atn(OldGroupRX/OldGroupRZ)
andnbsp; andnbsp;if OldGroupUpY=0 then OldOrientZ=0 else OldOrientZ=Atn(OldGroupUpX/OldGroupUpY)

You must be logged in to reply in this thread.