PDA

View Full Version : 3D Grid Effect


Furball89
06-26-2011, 10:41 AM
Hey!
i am trying to recreate THIS! (http://www.youtube.com/watch?v=9Ykt0FADk7E) grid effect in max. At first i thought i could do this with some sort of a world space deformer, or maybe a soft selection volume select, but i couldn't figure it out :( . So i decided to use particles by pushing them outward with an sdeflector, but did not please me either, it did not look right! Then i started to play with refractive material in vray to get this effect but that doesn't offer much control either! so i ended up writing this script :-
but the problem with this approach is
a) its very slow! creating a 11x11x11 grid takes half an hour!
b) it still doesn't feel right! i think its because the way the curve is smoothing! i will try bezier
c) its not easy to control! for example, every time i need to change the positions of the helper i need to run the scriptB, which is slow too!

scriptA - Grid Creation:

(
try(
delete $*
)catch()

/*
*Functions
*/

/*Prerequisite : "Passing SplineShape Knot Selections Up The Stack" - in the maxscript help file
The function basiclly takes an array of point helpers and creates a spline with knotpoint at each helpers position
then links each knot point to the helper with a linked xform modifier*/
fn createLine i j k = (
theLine = splineShape()
theLine.optimize = false
theLine.adaptive = true
addNewSpline theLine
if (i == -1) do (
for i = 1 to gridSize do (
addKnot theLine 1 #smooth #curve gridArray[i][j][k].pos
)
updateShape theLine
for i = 1 to gridSize do (
es = edit_spline name:("Edit_Spline_" + (i as string))
addmodifier theLine es before:theLine.modifiers.count
modPanel.setCurrentObject es
max modify mode
subobjectlevel = 1
setknotselection theline 1 #(i)
lxf = linked_xform name:("LinkedXform_"+(i as string))
modPanel.addModToSelection lxf
lxf.control = gridArray[i][j][k]
if i != gridSize do (
ss = splineselect name:"Blocker"
addmodifier theLine ss before:theLine.modifiers.count
)
)
)
if (j == -1) do (
for j = 1 to gridSize do (
addKnot theLine 1 #smooth #curve gridArray[i][j][k].pos
)
updateShape theLine
for j = 1 to gridSize do (
es = edit_spline name:("Edit_Spline_" + (j as string))
addmodifier theLine es before:theLine.modifiers.count
modPanel.setCurrentObject es
max modify mode
subobjectlevel = 1
setknotselection theline 1 #(j)
lxf = linked_xform name:("LinkedXform_"+(j as string))
modPanel.addModToSelection lxf
lxf.control = gridArray[i][j][k]
if j != gridSize do (
ss = splineselect name:"Blocker"
addmodifier theLine ss before:theLine.modifiers.count
)
)
)
if (k == -1) do (
for k = 1 to gridSize do (
addKnot theLine 1 #smooth #curve gridArray[i][j][k].pos
)
updateShape theLine
for k = 1 to gridSize do (
es = edit_spline name:("Edit_Spline_" + (k as string))
addmodifier theLine es before:theLine.modifiers.count
modPanel.setCurrentObject es
max modify mode
subobjectlevel = 1
setknotselection theline 1 #(k)
lxf = linked_xform name:("LinkedXform_"+(k as string))
modPanel.addModToSelection lxf
lxf.control = gridArray[i][j][k]
if k != gridSize do (
ss = splineselect name:"Blocker"
addmodifier theLine ss before:theLine.modifiers.count
)
)
)
)

/*
*Main : Create the grid
*/
global gridSize = 9
global gridSpacing = 35
global gridArray = #()

for z = 1 to gridSize do (
gridArray[z] = #()
for y = 1 to gridSize do (
gridArray[z][y] = #()
for x =1 to gridSize do (
gridArray[z][y][x] = point pos:([x,y,z] * [gridSpacing,gridSpacing,gridSpacing]) name:((x as string) + "," + (y as string) + "," + (z as string))
)
)
)

/*Center the grid*/
for h in helpers do (
h.pos = h.pos + ([gridSpacing,gridSpacing,gridSpacing] * -1 * ((gridSize - 1)/2 + 1))
)

/*Create the mesh of lines*/
for i = 1 to gridArray.count do (
for j = 1 to gridArray[i].count do (
createLine i j -1
)
)

for i = 1 to gridArray.count do (
for k = 1 to gridArray[i].count do (
createLine i -1 k
)
)

for j = 1 to gridArray.count do (
for k = 1 to gridArray[j].count do (
createLine -1 j k
)
)

forcecompleteredraw()
)


scriptB - Radial Grid Expansion:

if (storeInitialPositions == undefined) do (
global gridSize = 9
global gridArray = #()
global initialPositions = #()
global storeInitialPositions = true
for i = 1 to gridSize do (
initialPositions[i] = #()
gridArray[i] = #()
for j = 1 to gridSize do (
initialPositions[i][j] = #()
gridArray[i][j] = #()
)
)
for h in helpers do (
theIndices = filterstring h.name ","
gridArray [theIndices[1] as number][theIndices[2] as number][theIndices[3] as number] = h
)
)
for h in helpers do (
theIndices = filterstring h.name ","
thePoint = (gridArray [theIndices[1] as number][theIndices[2] as number][theIndices[3] as number])
if (storeInitialPositions == true) do
initialPositions[theIndices[1] as number][theIndices[2] as number][theIndices[3] as number] = thePoint.pos
if (thePoint.pos != [0,0,0]) then (
--if ((length thePoint.pos) < $ball.radius) do(
--thePoint.pos = initialPositions[theIndices[1] as number][theIndices[2] as number][theIndices[3] as number]
thePoint.pos = ((length thePoint.pos) + (140/(length thePoint.pos)) ) * (normalize thePoint.pos)
--)
)
)
storeInitialPositions = false


is there any easier way to create this effect, thanks a lot for help :)

[HERE (http://hotfile.com/dl/122237278/25efcce/Grid.zip.html)is the max file, scrub the slide to see it expand, maybe you will see some error message if you do not have vray :shrug: just ignore those]

denisT
06-26-2011, 12:47 PM
i would use a script to create the spline geometry, and skin or ffd modifier to animate its deformation.

Furball89
06-26-2011, 01:06 PM
Thanks for the reply!
yea I am using splines! the script creates splines and then uses linked xform modifier to link the splines knot points to point helpers (i got the idea from maxscript help file topic "Passing SplineShape Knot Selections Up The Stack" but this method takes lot of time to create the stack for multiple knot points, isn't there any fast way to link a knot point to a point helper?)! i tried using spline ik modifier but the problem with it is, you have to create separate point helpers for each spline!... Will give animating the FDD vertices a shot! i think the "animate vertex" or something method is used for that (have to check mx help!).

elT
06-26-2011, 01:39 PM
Not that i want to discourage you from scripting it, by all means, go ahead and have fun!

But, have you tried using box primitives and adding lattice modifier?

I've just tested it, the trick is to use symmetry modifier wisely and position the mirror precisely.

Try it on a simple 2x2x2 grid and if you like the result, expand as needed.

Create a box dimensions: h:10, w: 20, l: 10, segments: h:1, w: 2, l:1
position x:0, y: 5, z: 0
add modifier lattice: adjust radius and segments, turn of joints
collapse the stack
add symmetry modifer, use Y axis, positon the mirror to [0,0,0] in world space
add another symetry, use Z axis, positon the miror to [0,0,5] in world space.
collapse stack.

And you've got your 2x2x2 grid.

For larger grids and more segments simply create a wider box primitve with more segments and use additional symmetry modifier to reach the full volume.

just my 2 cents.

Cheers!

elT
06-26-2011, 01:51 PM
Even better, you can use a plane, extrude it by polygon and add lattice on top. Collapse stack and it's done. :)

Furball89
06-26-2011, 01:54 PM
Thanks for the reply!

please watch the link i posted in my first post, i want to animate the grid expanding radially as well, lattice modifier will only give me the grid! i tried using the "spherify" modifier, it obviously din't work, heh i have tried so many methods for this simple effect lol! been playing with fdd now, some problems i am facing, the control points are offset! i.e they are not centered to the origin (and they are normalized too!!) by default even though the object and the lattice transforms are set to (matrix3 1, or identity matrix) :S (no big deal can perform my computation and re transform the fdd points back, i guess!) also how can i loop through each control point !?! i am using the execute method like so:

fddSize = 3
for i = 1 to (fddSize*fddSize*fddSize) do (
cp = execute ("$.modifiers[1].control_point_" + (i as string))
point pos:(cp * [140,140,140])
)

but there is an easier, more elegant, way right!? (i am modifying the control points directly for testing, i will write the positions to there controllers later, oh or better still, just use the animate context)

thanks for the help :)

elT
06-26-2011, 02:23 PM
After modeling the grid, you should reset x form, center the pivot, align to world and definitely collapse the stack. You can then easily use ffd to expand it any way you want it.

This was done in 5 minutes.

http://imageshack.us/photo/my-images/215/gridy.png/

A 20x20x20 grid.

Created a plane 200x200, segments 20x20. Selected all edged and clicked split. Selected all polygons, and extruded by polygon, 10 units, clicked apply 20 times. Selected all vertices, click weld. Collapse stack. Add Lattice, use Struts only, radius 0.1. Collapse stack, reset x form, collapse again, apply 3x3x3 FFD and deform. Works like a charm.

Just saying.

Furball89
06-26-2011, 02:54 PM
Thanks for the reply!

Created a plane 200x200, segments 20x20. Selected all edged and clicked split. Selected all polygons, and extruded by polygon, 10 units, clicked apply 20 times. Selected all vertices, click weld. Collapse stack. Add Lattice, use Struts only, radius 0.1. Collapse stack, reset x form, collapse again, apply 3x3x3 FFD and deform. Works like a charm.

Thanks for this! you the best! :thumbsup:.

elT
06-26-2011, 03:03 PM
Glad I could help. :)

MatanH
06-26-2011, 05:34 PM
You could use a displace object with sphere mapping and decay

CGTalk Moderation
06-26-2011, 05:34 PM
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.