Node Utility Methods

isDeleted <MAXWrapper_object> 

This function yields the result true if the object has been deleted and false if it still exists in the scene. Using the function only makes sense in situations where references to 3ds Max objects are held in variables or arrays, or passed as parameters and you want to determine whether the object has been deleted from the scene. Performing an operation on a deleted 3ds Max object referenced in a variable or array otherwise generates an exception. Any kind of 3ds Max object can be tested in this way such as, scene objects, modifiers, controllers, materials, and others.

FOR EXAMPLE:

sel = selection as array-- snapshot selection
--...
-- <one or more objects in the selection are deleted,
-- by the user or other scripts>
--...
for obj in sel
where not isDeleted obj do
move obj [10,0,0]

When a node has been deleted,

== undefined returns false

!= undefined returns true

FOR EXAMPLE:

if mynode != undefined and not isdeleted myNode do...
distance <node> <node> 

Computes the distance between the pivot points of the two specified nodes.

intersectRay <node> <ray> 

Computes the closest intersection of the ray and the surface of the given node. Returns another Ray which defines the position of intersection in 3D space and the surface normal direction vector at that point. The intersection test respects the face normals of the node. If a face's normal points away from the ray's source, an intersection test is not performed on that face . intersectRay() works if the world state of the node (the state of the node at the top of the node's stack) has a surface such as, an editable mesh, a Standard, Extended, or Compound Primitive, a Patch, or a NURBS surface object. Splines and NURBS curves do not have a surface. Returns undefined if the ray does not intersect the node, the faces it does intersect point away from the ray's position, or the node does not have a surface.

intersectRayEx <node> <ray> 

Takes a ray and computes the closest intersection to the surface of the given node. It returns an array with the following three elements.

  1. A Ray defining the position of intersection in 3-space and the surface normal direction vector at the point.

  2. The index of the face the ray intersects with.

  3. The barycentric coordinates of the face that was hit.

This method only works if the world state of the node is a mesh, either because it started as an editable mesh or it has modifiers applied that convert the node to a mesh. Unlike intersectRay() , this method will not work if the node is a Standard or Extended Primitive; the node's stack must evaluate to a mesh. The intersection test respects the face normals of the node. If a face's normal points away from the ray's source, an intersection test is not performed on that face. Returns undefined if the ray does not intersect the node, the faces it intersects point away from the ray's position, or the node is not a mesh.

WHAT ARE BARYCENTRIC COORDINATES?

Barycentric coordinates are the coordinates relative to the triangular face. The barycentric coordinates of a point p relative to a triangle describe that point as a weighted sum of the vertices of the triangle.

If the barycentric coordinates are b0 , b1 , and b2 , then

p = b0*p0 + b1*p1 + b2*p2

where, p0 , p1 , and p2 are the positions of the vertices of the triangle.

The Point3 returned by this method has the barycentric coordinate stored in its three component values. The coordinate is relative to the triangular face that was intersected.

Barycentric coordinates can also be used to interpolate any quantity whose value is known at the vertices of the triangle.

Following is an example of finding the UV coordinates at the intersection point:

FOR EXAMPLE:

s = geosphere material:(standardMaterial diffuseMap:(checker()))
showTextureMap s.material s.material.diffuseMap on
--
-- Add a normal modifier to make the sphere into a mesh
addModifier s (normalModifier())
r = ray [-100,5,0] (s.center-[-100,5,0])
--
-- Get the Intersection details
arr = (intersectRayEx s r)
--
-- Create a dummy at the point of intersection
dummy pos:(arr[1]).pos
--
-- Get the texture face
tf = getTVFace s arr[2]
--
-- Get the UVW verts of the face
tv1 = getTVert s tf.x
tv2 = getTVert s tf.y
tv3 = getTVert s tf.z
--
-- Calculate the texture vertices at point of intersection from
-- the barycentric coordinates
tv = tv1*arr[3].x + tv2*arr[3].y + tv3*arr[3].z
--
-- Delete the modifier
deleteModifier s 1
intersectRayScene <ray> 

Performs intersectRay on all nodes in the scene.

Returns an array of results, one entry per node hit, where each entry is a 2 element array containing the node and the intersectRay result for that node.

The intersection is performed for all geometry objects including hidden ones.

Available in 3ds Max 2008 and higher. Previously, available in the Avguard Extensions.

FOR EXAMPLE

(
local r = ray [0,0,0] [1,0,0]--define a ray along X
for i = 0 to 4 do--loop 5 times
(
 box pos:[i * 30, 0,0]--create a box
)
local hits = intersectRayScene r--intersect withscene
print hits --Misses box 1 because ray originates inside the box
)

-- output

--> #($Box:Box02 @ [30.000000,0.000000,0.000000], (ray [17.5,0,0] [-1,0,0]))
--> #($Box:Box03 @ [60.000000,0.000000,0.000000], (ray [47.5,0,0] [-1,0,0]))
--> #($Box:Box04 @ [90.000000,0.000000,0.000000], (ray [77.5,0,0] [-1,0,0]))
--> #($Box:Box05 @ [120.000000,0.000000,0.000000], (ray [107.5,0,0] [-1,0,0]))
--> OK
intersects <node> <node> 

Returns true if the bounding boxes of the two specified nodes overlap, or false if they do not overlap.

printStack <node> 

Prints a representation of the current modifier stack for the given node.

getLastMergedNodes()

Returns an array of nodes loaded by the last merge operation, for example by mergeMAXFile().