-- this code is for editable mesh, if you work with editable poly, you'll have to change couple of lines. -- you can always mail me. keep me up! ( local theMesh, theBitmap, theBitmapWidth, theBitmapHeight fn filterMesh obj = classof obj == Editable_Mesh rollout IntersectWithMesh "Intersect With Mesh" ( timer timerControl interval:50 active:false pickbutton pickMesh ">>Pick Mesh To Explore" width: 380 filter:filterMesh edittext faceHit "Face:" edittext normalHit "Normal:" edittext worldHit "World:" edittext baryCoords "Barycentric:" colorpicker pixelColor "Pixel Color:" on pickMesh picked obj do ( if obj != undefined do ( theMesh = obj pickMesh.caption = obj.name timerControl.active = true if theMesh.material != undefined and classof theMesh.material.diffusemap == BitmapTexture do ( theBitmap = openBitmap theMesh.material.diffusemap.filename theBitmapWidth = theBitmap.width-1 theBitmapHeight = theBitmap.Height-1 ) ) ) -- this code will be execute every 50 ticks on timerControl tick do ( -- fire a ray from the screen into the scene. you'll have to change this to a ray from the light. theRay = mapScreenToWorldRay mouse.pos -- get the intersection with the mesh /* IntersectRayEx = Takes a ray and computes the closest intersection to the surface of the given node. It returns an array with the following three elements. A Ray defining the position of intersection in 3-space and the surface normal direction vector at the point. The index of the face the ray intersects with The barycentric coordinates of the face that was hit. */ theInt = IntersectRayEx theMesh theRay if theInt != undefined then ( faceHit.text = theInt[2] as string normalHit.text = theInt[1].dir as string worldHit.text = theInt[1].pos as string baryCoords.text = theInt[3] as string if theBitmap != undefined do ( theMapFace = meshop.getMapFace theMesh 1 theInt[2] theMapVert1 = meshop.getMapVert theMesh 1 theMapFace.x theMapVert2 = meshop.getMapVert theMesh 1 theMapFace.y theMapVert3 = meshop.getMapVert theMesh 1 theMapFace.z theUVCoords = theMapVert1 * theInt[3].x + theMapVert2 * theInt[3].y + theMapVert3 * theInt[3].z theUVCoords.x = mod theUVCoords.x 1.0 theUVCoords.y = mod theUVCoords.y 1.0 thePixels = getPixels theBitmap [theUVCoords.x*theBitmapWidth, theBitmapHeight - theUVCoords.y*theBitmapHeight] 1 if thePixels[1] != undefined then pixelColor.color = thePixels[1] else pixelColor.color = red ) ) else faceHit.text = normalHit.text = worldHit.text = baryCoords.text = "?" ) ) createDialog IntersectWithMesh width:400 )