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
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
