Notifications
Clear all

[Closed] Looping through geometry to evaluate modifiers?

Hi all,

I’m creating a script to export to a flight simulator model format. The specifications for that format involves multiple properties specific to the flight simulator that must be applied to specific pieces of geometry.

What I’ve done is created a series of scripted simplemods that I can apply to the geometry. For example I have a simplemod that designates cockpit panel geometry:


 plugin SimpleMod XPlaneObj8cockpit
 name:"X-Plane Cockpit" 
 classID:#(0x74276553, 0x6be4bab0)  
 version:1
 (
 	rollout XPlaneObj8cockpitParams "X-Plane Cockpit" width:162 height:319
 	(
 	label lab1 "This mesh will be"
 	label lab2 "designated as"
 	label lab3 "ATTR_Cockpit."
 	)
 	on map i p do
 	(
 		-- We do nothing here
 	)
 )
 

that works…I can apply the modifier just fine.

What I need to do is A) Loop through all my geometry when processing and B) Evaluate whether or not the geometry has specific modifiers.


 	allObj = for i in objects where classOf i == Editable_Poly collect i
 	numObj = allObj.count
     
 	-- Loop through all scene objects
 	for i = 1 to numObj do
 	(
 			tmesh = snapshotAsMesh allobj[i]
 
 

The above code is my loop…but it ONLY works on Editable_Poly’s and appears to ignore them if they have a modifier… I think I need some sort of superclass check. I’d like to loop through “selected” geometry if possible instead of ALL geometry in the scene.

As for evaluating modifiers…in my loop I tried:


cockpitMod = allObj[i].modifiers["XPlaneObj8cockpit"]
if (cockpitMod != undefined) then
(
)
 

But that didn’t work.

Any ideas? Thanks in advance guys!!

11 Replies

This will create an array with all the selected objects that are editable polys are have edit poly applied. I think…

local objs=for x in selection where classOf x==Editable_Poly or classOf x==PolyMeshObject collect x

theCockpits = for o in selection where superclassof o == GeometryClass AND (for m in o.modifiers where classof m == XPlaneObj8Cockpit collect m).count > 0 collect o

Or, to avoid certain problems superclassof could cause when in a scene with heavy Particle Flow systems or similar 3rd party objects that require a lot of time to refresh,

theCockpits = for o in selection where findItem GeometryClass.classes (classof o) > 0 AND (for m in o.modifiers where classof m == XPlaneObj8Cockpit collect m).count > 0 collect o

Thats getting somewhere…only thing is, I need to evaluate whether or not specific modifiers are applied inside the loop, because I do a lot of common stuff for each geometry object…I export vertices and normals and UV coords first, then a list of indexes for thos vertices, and then I evaluate the modifiers for that specific object that the loop is on…then I go to the next object and evaluate its modifiers.

So if you could give me a good if statement that shows whether or not that modifier is applied by itself, that would be perfect…

And then a good loop through all geometry objects that are currently selected whether they’re poly’s or meshes and despite any modifiers, that would be perfect too

EDIT: Duh…I just noticed the selection part there…you’ve already given me the selection part…I just need the separated modifier if statement…thats bugging me…

Yup…I’ve got a good loop goin now…


 	allObj = for o in selection where findItem GeometryClass.classes (classof o) > 0 collect o
 	numObj = allObj.count
 	for i = 1 to numObj do
 	(
 			tmesh = snapshotAsMesh allobj[i]
 

Now I need to evaluate whether or not allObj[i] has the modifier.


 if classof allObj[i].modifiers == XPlaneObj8cockpit then
 

doesn’t work

And in the case of getting that if statement working…the modifier posted previsouly has no parameters to it…but some of them will…is it difficult to retrieve those properties from a modifier once I have evaluated that the modifier exists on the current allObj[i]?

 eek
 
if classof allObj[i].modifiers == XPlaneObj8cockpit then

doesn’t work

oh oh, you need to specify the modifier, like modifiers[1] etc etc…

classOf selection[i].modifiers[1] == XPlaneObj8cockpit

Sweet! That worked…but what if the modifier I’m looking for isn’t in the first slot?

And how can I grab parameters from that modifier?

 JHN

Another for loop it is.


allMods = #()
for o in allObj do 
  for m in o.modifiers where m.name == "XPlaneObj8cockpit" do append allMods m


Leaves you with an array with all modifiers… My guess is that Xplane…etc is the modifier name…!?

Now you can loop over the array and change values of all mods at once if you want.


for m in allMods do m.somevar = somefoo

-Johan

*code has not been tested principles should work though…

Thats grouping all the mods together for all the objects…which isn’t gonna help me…basically my loop is thus:


 for each piece of selected geometry
     for each face in current geometry from selection loop
         get coords, normals, and UVs for all three vertices
         add three vertex entrys to vertex array
     for each vertex in current geometry from selection loop
         create vertex index entries in index array (stupid way x-plane handles vertices)
     if xplaneobj8cockpit modifier then
         write cockpit attribute to constructor array
         write constructor to constructor array
         write no cockpit attribute to constructor array
     if xplaneobj8animrotate modifier then
         write anim begin attribute to constructor array
         write animrotate attribute (with parameters from modifier) to constructor array
         write constructor to constructor array
         write anim end attribute to constructor array
     --process other similar modifiers
     go back to top of first loop
 open text file
 write default x-plane stuff
 write vertex entries from vertex array
 write index entries from index array
 write all constructors from constructor array
 close text file
 

so given the order in which things have to happen, during the loop through each object, as I evaluate one of the selected objects (allObj[i]) I need to check to see if it has the cockpit modifier and put the constructor for it…then check to see if it has the anim rotate modifier and put the constructor in for that, then check to see if it has the blah blah blah modifiers and put in whatever constructors go for them…thats pretty much it.

so given allobj[i] how can I say “if allobj[i] has the blahblahblah modifier then do the following” and on a separate if statement I say “if allobj[i] has the blahdeblah modifier then get parameters from that modifier and so the following” and so on?

Here’s a better view of what I’ve got


-- Draw Triangles
if classof allObj[i].modifiers[1] == XPlaneObj8cockpit then
(
   append AryTRIS "ATTR_cockpit
"
   append AryTRIS ("TRIS " + (startIDX as string) + " " + (num_faceverts as string) + "
")
   append AryTRIS "ATTR_no_cockpit
"
) else (
	append AryTRIS ("TRIS " + (startIDX as string) + " " + (num_faceverts as string) + "
")
)

Instead of doing the else, what I would rather do is evaluate other modifiers, and insert their attributes if they’re present…setting booleans for the ones that will require on and offs, and gathering any parameters that will be necessary during the process, and then writing the TRIS attribute (which is the constructor)

Sorry if I’m bouncing around on this.

Page 1 / 2