PDA

View Full Version : Simple Oject plugins : some questions (for the mighty bobo?)


reForm
07-30-2006, 10:26 PM
I'm trying to write a plugin that creates an array of instanced objects, but keeps the array items within the plugin mesh, ie like the scatter object.
To test the concept, I'm trying to simply create an array of box's using createinstance.

The approach I am taking is:

Create a struct containing the parameters of each object instance, ie

struct mObjectStr ( mObj, mInstance, mMesh, msizex, msizey, msizez, mposx, mposy, mposz, mRotx, mroty, mrotz, mScalex, mscaley, mscalez, mOffsetx, mOffsety, mOffxetz)

then in the meat of the plugin I have

on buildmesh do
(
--define arrays (maybe some defunct variable here)
obj_instance = #()
obj_location = #()
objMesh = #()
mobj = #()
local mymesh
objarray=trimesh()

-- make sure mOffset isn't undefined
if (mOffset == undefined) do
(
moffset = [mtx, mty, mtz]
)

-- Main function to create the mesh instances, and combine them into the single mesh object to return to the plugin

for a = 1 to mArrayCount do
(

--Define Instance parameters from UI Controls
mobj[a] = mObjectStr a
mobj[a].msizex = mIconSize
mobj[a].msizey = mIconSize
mobj[a].msizez = a*mIconSize
mobj[a].mposx = a*mTx

-- Create the object instance within the mObj struct
mobj[a].minstance = createInstance box length:mobj[a].msizex width:mobj[a].msizey height:mobj[a].msizez position:([mobj[a].mposx,a,a])
-- Create the trimesh version of the instance (again within the struct)
mobj[a].mmesh = mobj[a].minstance.mesh

-- add the current instance mesh to the main plugin mesh container
objarray = objarray + mobj[a].mmesh
)
-- Finally, return the entire mesh to the plugin, which then creates the objects
mesh = objarray
)




so in summary, the buildmesh has :-
for (a=1 to count) do
(
-- Create the object instance within the mObj struct
mobj[a].minstance = createInstance box length:mobj[a].msizex width:mobj[a].msizey height:mobj[a].msizez position:([mobj[a].mposx,a,a])
-- Create the trimesh version of the instance (again within the struct)
mobj[a].mmesh = mobj[a].minstance.mesh

-- add the current instance mesh to the main plugin mesh container
objarray = objarray + mobj[a].mmesh
)
-- Finally, return the entire mesh to the plugin, which then creates the objects
mesh = objarray


Questions/Problems:-




I've found that the position tag doesnt work for the instances. I assume to position each instance mesh, I either build the mesh vertice by vertice using the transforms to locate the instance properly, or translate the vertices after building the mesh. Any suggestions?
This method seems to be very slow when animating the parameters (ie size or count) : is there a quicker way to rebuild the mesh in realtime as you adjust the object parameters?
am I taking the right approach, ie building the mesh within the 'on buildmesh' ? or should I be using a more complex approach?
This post is massive.... thanks for reading this far!
I hope someone is able to help me out with this.... any help much appreciated!
(or please let me know that what I am trying to do is impossible if it is)

Cheers

reForm
08-14-2006, 07:43 PM
<bump>

Does anyone have any answers?

Bobo
08-14-2006, 11:17 PM
<bump>

Does anyone have any answers?

Thanks for bumping it, I was at Siggraph when you first posted this and completely missed it.
Will take a closer look later tonight when I find some time...

Bobo
08-15-2006, 12:01 AM
Regarding question 1., you will have to loop through all vertices of the TriMesh you took from the instance and offset its vertices based on the offset values in the UI using getVert() and setVert() calls.

Another thing - if ALL the instances are going to be the same, it does not make any sense to create them N times. I would create just one instance outside of the loop, then copy its trimesh multiple times, offset the vertices and add to the final mesh. Might not make a big difference in speed, but it sounds more efficient.

reForm
08-15-2006, 09:36 AM
Hi Bobo,
Thanks for taking a look at my questions!

I'm beginning to think that maxscript will be way too slow for dealing with the large arrays of objects that this plugin is likely to create. Especially if I am intending to have the meshes animating which would require the transforms to be applied every frame.

I'll try offsetting the vertices as you suggest and see how fast it runs.

Thanks again :)

CGTalk Moderation
08-15-2006, 09:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.