Notifications
Clear all

[Closed] Random position on surface

forget my last post, I found the error I was doing in my script, a more appropriate question is what’s the
use of the “copy <array> [#noMap]”, it supposed to create a copy but where ?

because I through it may help me with this :


ax = #() ;ax[100] = 0
for f in 1 to 100 do ax[f] = random 1 100

bx = #() ;bx[100] = 0
for f in 1 to 100 do bx[f] = random 1 100

cx = #() ;cx[100] = 0
for f in 1 to 100 do 
(
	case (random 0 1) of 
	(
		0:(cx[f] = &ax[f])
		1:(cx[f] = &bx[f])
	)
)

what I wanted was to retrive the array the value belong to without using struct or sub array…
if I do cx[1] it return me (Global:bx[Local:f]) which is fine since it give me the array name…
but if I do *cx[1] it give me system exception, so I’ve got no clue how to get the value out of this!!

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

If I remember correctly, the copy() was initially implemented for the array value just because every value must implement one, but it didn’t do anything useful because it was returning OK. So it was there for language consistency, but wasn’t very practical.

The #nomap option was added to allow “shallow” copies of the top level value.
So if you have an array containing a nested array value, you get this:


a = #(1,#(10,20,30),3)
#(1, #(10, 20, 30), 3)
b = copy a #nomap
#(1, #(10, 20, 30), 3)
a[2][2] = 42 --set the second element of the nested array to 42
42
a --check out array a
#(1, #(10, 42, 30), 3)
b --check out array b - it is the SAME as a, because element 2 is shared by-reference
#(1, #(10, 42, 30), 3)
a[1] = 11 --this does not affect static values though
11
a
#(11, #(10, 42, 30), 3)
b --the first element of b remains 1
#(1, #(10, 42, 30), 3)

Thus, the deepCopy() method was introduced in Max 9. It works properly and makes a new array with the same content copied recursively, regardless of depth.

a = #(1,#(10,20,30),3)
#(1, #(10, 20, 30), 3)
b = deepcopy a 
#(1, #(10, 20, 30), 3)
a[2][2] = 42 --setting element 2 of the subarray does NOT affect the copy
42
a
#(1, #(10, 42, 30), 3)
b
#(1, #(10, 20, 30), 3)

Bobo thankyou for all this examples and explanation, that really help me a lot understanding maxscript… and big big thanks again. Just ordered your DVD .

Seems to be all my sadism demands bring me to PFlow... 

But first i'll try to use surface vertex position, after tessellation. For example to use the Sudivision modificator that  in result i will get a uniform tessellated surface. But how i collect vert.pos ... 

CollectedPos=#()

collectedpos=for i in 1 to themesh.numVerts.count collect (
 i=themesh.vert.pos
)

And how i can delete or extract an item from array … for example
Array #(Node 200,100,10 , Node1 205,150,0… )
and i need or to delete from all items the POS and DIR and leave only the node list, or to extract in other array just the nodes name

And how can i hide from 3dsmax created objects (example) as proxy for vray of XRef and just send them to render plugin straight… because when i have them hided from viewport and press render 3dsmax is loading them long time and some times crashes at 10k instances.

edit: I’m just comparing with other scatters and maybe is there a solution, why i need this if i could use the same vrayscatter – they allow me to use only proxy, but i need to scatter random objects from array not just on proxy or Xref and not necesary mesh object… it could be lights, shapes or atmospheric gizmos… everything that have a pivot point…
BOBO done an impresive script.

I through copy returned ok in the two case …hopefully you lighten me on this, as for the problem itself
I think it because it store the local var f instead of the real integer , so I tried cx[f] = &ax[execute (f as string)] but well no such luck!

anyway thank for your help

You don’t have to intialize collectedPos if you will be collecting into it.
So you can just say

theMesh = snapshotasmesh yourObject --we snapshot a copy of the mesh in memory
collectedPos = for i in 1 to theMesh.numverts collect (getVert theMesh i)
delete theMesh --this is a copy of the mesh in memory, so we release it

And how i can delete or extract an item from array … for example
Array #(Node 200,100,10 , Node1 205,150,0… )
and i need or to delete from all items the POS and DIR and leave only the node list, or to extract in other array just the nodes name

Not sure what the above array shows, but in general, you can collect multiple arrays, each with the data you want, or one array with all values you need stored in sub-arrays.

I think I am missing something here, please try to explain again.

And how can i hide from 3dsmax created objects (example) as proxy for vray of XRef and just send them to render plugin straight… because when i have them hided from viewport and press render 3dsmax is loading them long time and some times crashes at 10k instances.

You cannot “hide” created objects from Max. You can hide them from the viewports, but they still exist. You cannot send them “straight” to the renderer, they have to exist in the scene first. (Except for cases like VRay and mental ray proxies where the renderer pulls the data directly from disk, but this is not something you can do with MAXScript).

Nice! How’d you go about if you want to guarantee a minimum distance between all the random positions? So, say you have that irregularly tesselated plane, and you want to place twenty teapots, with no teapot closer than 1.5*(max of teapot radius) to any other teapot?

Cheers
– MartinB

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Instead of performing the intersection test which I was using the the last script above, you could just use the currently generated position, compare to all (or the closest) positions already generated and if the distance is less than the sum of the two radii, continue trying.
I had a similar test here using (distance obj.center obj.max) but never posted it because using the bounding radius creates larger distances for teapots than the intersects() which takes into account the bbox and allows adjacent teapots.

martinB
– well the point was to subdivide the mesh by sampleSize that will be the same as boundingBox size, and collecting the vertexes position once. If to spread objects by collected should be full covered surface… and will look symetric… may be in this case to make an random offset by object or by line of objects, random rotations and random scaling if needed…
As we collected once in memory all vertex position we could regenerate the objects faster (I think) and to make a low covered surface we will need just to lower the count of objects and looping them randomly thru CollectedVertexPos Array… well i don’t know how will work in pratice.

BOBO
– for example i have ObjectsArray that contains for each item (theNodeName [theNodePosition] (theNodeNormal.dir)) and when i’m trying to” select ObjetsArray ” gives me an error” could not convert (0.5668,2.588,0) to node type ” that i think is TheNodeNormal.dir stored in item array…and i want to collect another array with NodesName only, or PositionOnly.

Q/ Is posible to randomize not objects but vertex of an object or instance of one ELEMENT from object as in result to get one object. And when render is started to replace Vertexes or Element of that object with instances of Houses,Trees,grass… ? or it doesn’t make sense

Page 3 / 3