Scene.GetActiveEdge

It looks like I have to actually rebuild and modify the hierarchy and copy the objects over every time I want to re-parent an object.

Yuck. I was hoping for a more elegant solution than leaving it up to the user to manually delete all the old ‘junk’ objects. Never mind the performance hit of script-cloning a lot of objects just so you can move *one* object group to another object group as a child…

-Mel

Exactly how is this used?

I’m writing a script, and I need to be able to select an edge and then derive the two points that make up the edge.

According to my understanding of the documentation, GetActiveEdge returns the object and the face the edge belongs to, and then the index of the first point on the edge as the third parameter.

The trouble I’m having is in finding the second point on the edge-if I simply add one to the index of the first point, it doesn’t always return the correct point.

It would be really nice if GetActiveEdge returned *both* points, since an edge requires two points to exist anyway. So, anyone have any ideas on how I can get the second point of the selected edge?

The ultimate purpose of this script is to create a hinge pivot, for which the selected edge defines the X rotational axis. To do this, I need to shift the object’s pivot to the midpoint of the selected edge and orient it correctly so that the edge runs through the X rotational axis of the pivot.

So this brings me to another question…it looks like I could use surface normals as parameter values for Get/SetOrientation. If I use the surface normals for both the directional and Up vectors, would this orient the pivot so that its Y axis is parallel to the surface normal and its X axis is aligned with the selected edge?

The basic idea I have is to properly relocate the object’s pivot along the hinge edge first, and then pass the surface normals to SetOrientation to reorient the pivot properly. Does this sound sensible?

(The reason for writing this script is because I want to later write a script which converts individual faces into separate objects and then hinges them properly so that when assembled into an IK chain, I can animate the unfolding of a 3D object into a flattened 2D pattern. I plan to render this animation frame by frame to create step-by-step instructions for building paper models that I create in 3DC.)

-Mel

Well, I can’t realy help you on this one but it sure sounds interesting. And who knows maybe this will be usefull for lots of thing <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –>

James

Yeah, probably…although I’m doing this for a really specific task that probably isn’t going to be useful to very many other people.

Richard, problem: my script bombs out with an error message when I try to use SetOrientation. What does ‘Automation Error (-20055331882)’ mean?

This is the offending line in the script

PanelGroup.SetOrientation Nothing, 0, OrientationX, OrientationY, OrientationZ, OrientationX, OrientationY, OrientationZ

The values for OrientationX, OrientationY, and OrientationZ were grabbed from the face normals of each face of the original object that I’m unfolding. The values are correct, but the script still bombs when I try to set group orientations with SetOrientation.

-Mel

Update-SetOrientation only seems to crash when I pass named variables instead of explicit numbers.

That is, if I pass VariableX, VariableY, and VariableZ, it bombs out, but if I pass 0, 1, 0, it works. The weird thing is, I know the VariableX, VariableY, and VariableZ values are correct…

-Mel

Another update…I converted the script to a plugin so I could strictly type the variables, but the same behavior happens on SetOrientation.

Has anyone ever gotten SetOrientation to work with named variables as opposed to hardcoded numbers? I’m beginning to think the problem is with 3DC and not my code.

-Mel

Okay…I couldn’t find much in the way of online documentation for automation errors, so I’d like people to test this script and let me know if they receive the same automation error.

[pre class=’ip-ubbcode-code-pre’]
Language = VBScript

Option Explicit

‘***********************************************
‘Tests the SetOrientation command
‘***********************************************

Dim Scene
Dim SceneGroup
Dim ActiveObjectCount

Dim OriginalMesh
Dim OriginalMeshName
Dim OriginalGroup

Dim ox
Dim oy
Dim oz

Sub Main (3DCApp)

‘get the scene
Set Scene = 3DCApp.GetActiveScene

‘get the active object count
ActiveObjectCount = Scene.GetActiveObjectCount

‘only proceed if there is an active object
If ActiveObjectCount = 0 Then
MsgBox ‘Please select an object.’
Else

Set OriginalMesh = Scene.GetActiveObject(0)

Set OriginalGroup = OriginalMesh.GetParentGroup

ox = InputBox(‘Select X orientation (must be between -1 and 1)’, ‘SetOrientation Test’, ‘0’)
oy = InputBox(‘Select Y orientation (must be between -1 and 1)’, ‘SetOrientation Test’, ‘1’)
oz = InputBox(‘Select Z orientation (must be between -1 and 1)’, ‘SetOrientation Test’, ‘0’)

OriginalGroup.SetOrientation Nothing, 0, ox, oy, oz, ox, oy, oz

End If ‘end checking for active objects

End Sub

[/pre]

If it fails for me but works for others, then odds are it’s a problem with my system. But if it fails for everyone else, chances are it’s either a problem with the script or a problem with 3DC itself.

Let me know if it works for you.

Instructions: First select an object, then run this script on it, following the prompts. If the values aren’t changed, nothing different should happen. But if you enter different values, then the object and its group bounding box should be rotated appropriately.

-Mel

Here’s some eye candy…I animated a box being unfolded after I applied my unfolder script to it.

I first converted a standard cube primitive into a Net object using my script, with each face being a Panel object in its own group.

I then relocated their rotation points to selected edges, which creates the fold lines. This way, I can rotate the individual Panel objects and still maintain the correct relationships. After establishing the proper parent-child hierarchy, I animated the unfold process.

I can’t unfold anything more complicated than a box-like volume until the SetOrientation issue is resolved, but at least I’m making some progress. <!– s:D –><img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" /><!– s:D –>

-Mel

Okay, it doesn’t seem to be named variables causing the problem, after all…it was the combination of vectors that I fed it. It doesn’t like the direction and Up vectors being the same, and it doesn’t like certain combinations of direction and Up vectors.

I think I need to brush up on matrix math, since I’m having trouble understanding why passing the face normal XYZ vector to SetOrientation doesn’t seem to work with any Up vector I provide. It either bombs out with an Automation error or rotates the groups strangely…

-Mel

Sorry I missed this one Mel…

Edges are always a single face point index, the next point is always the index +1 MODULUS the number of points in the face i.e. if your edge starts at the last point on a face, the next point is 0.

With set orientation, just imagine one arrow pointing along the Z axis and another pointing along the Y – the parameters for SetOrientation are the normalised vectors when you make the rotations you require.

Ah! That would solve the edge selection issue very nicely. I don’t know why I didn’t realize that…thanks for that tip!

I’m still kind of stupid when it comes to vectors. Okay, make that REALLY stupid.

Most of my 3D programming experience was in languages like DarkBasic, where rotations were handled in degrees, so I didn’t have any real experience with them before Saturday afternoon. (Needless to say, my experience with them since then consists primarily of the coding equivalent of beating my head against a brick wall, LOL…)

I can visualize the right-hand rule and I have a pretty good mental picture of what you’re describing, but for some reason when I try to translate that into code I suffer the mental equivalent of a blue screen of death.

What I was trying to do, after splitting the original object into individual groups containing one face each, and before building the new face geometry in those groups, was to orient the group in the general direction of the face normal, with the Y axis pointing along the face normal. I thought pulling the face normal XYZ values from the original mesh would do the trick, but that didn’t work.

I’m assuming plugging the face normal XYZ values into the Up vector for SetOrientation would make the group’s Y axis point along the the face’s normal…but where I’m lost is what to use for the direction vector. If I’m supposed to do it the other way around, then it’s the Up vector that I don’t know how to figure out, LOL…

-Mel

To get your hinge group orientation you are on the right track …

The ‘up’ vector is the face normal, but the ‘forward’ vector is the cross product of the normalised vector of the selected edge (point 2 minus point 1, normalised) and the face normal.

This should give you a vector pointing away from the hinge at right angles across the face.

(However, it could also point in the opposite direction)

Okay, that sounds a LOT clearer than the explanations in the 1000-page book I have sitting on the desk. Much obliged…I’m gonna try that out and see how it goes.

Thanks again!

-Mel

Works perfectly so far!

I really appreciate the help…telling me what I had to do made it a lot easier to look in the right places for the specific information I needed to write the code. I’ve got stacks of books dealing with this stuff, but they might as well be written in hieroglyphics for all the sense they make to me. So when you gave me the pointers on vectors and cross products, that part of the book finally made sense to me and I could actually write the code to make it work.

Debugging it and the original mesh-to-net conversion script was rather entertaining, but it finally works!

I’ve attached a shot that shows the results of unfolding a 6-sided cylinder in Object Coordinates mode, using just the X rotation axis to fold/unfold along joined edges.

-Mel

I’ve started on some helper scripts, and my latest attack of stupiditis involves this:

I’m writing an one-click unfolder to work with models that have already been processed by the mesh-to-net converter and the hinge pivot script…I have the hinges all set up properly, with the face’s normal as the ‘Up’ vector and the X axis running through the edge. It works great, as the screenshot in the last post shows.

However-the one-click unfolder needs to flatten the faces so that their normals are coincident with the world 0,1,0 up vector, while maintaining the hinge relationships. But just putting 0,1,0 as the ‘up’ vector in the hinge equation doesn’t yield the correct results.

So if I want to rotate a face around its hinge X axis so that the face’s normal points along the 0,1,0 vector in world space, is there something more that I need to do to make them align properly?

-Mel

You must be logged in to reply in this thread.

19 posts