NaughtyNathan
10-08-2008, 09:00 AM
what is the difference between a polygon and a face...? do you mean mesh? do you want to know if a given mesh is intersecting another mesh? what if the given mesh is intersecting something else (i.e. a nurb surface)?
one hacky way you could maybe do it is by trying to boolean intersect the two objects together... if the resulting mesh has no faces they don't intersect...
of course you'd have to restore your objects back to normal.. you could do an undo, or instead of booleaning your real objects, copy them both first, then just delete the whole copied boolean mess when you're done.
This is a pretty nasty method but it'd probably be easier and quicker than a scripted maths solution...
:nathaN
Phlok
10-08-2008, 02:36 PM
Hi rem,
Well, I do not know the script you've mentioned. But if you have a script that's checking for intersecting faces, you could easily alter it in order to check for mesh injections.
First, put all the faces in the mesh you wanna test on intersections into a list or array, then perform the check for face intersection for each of the faces.
If one of the faces intersects with something, the mesh does so, too.
@NaughtyNathan
yes, I meant meshes. I did think about the boolean option but it just seemed wayyy to messy, I'm gonna have to test on over 200 objects, so it will probably be really slow as well.
Anyways. After reading some API documentation from Gould's books and understanding it better I decided to see if I could do my own script. The one I came up is a modified version of his meshInfo.cpp. I just translated it from the C++ API to the Python API and then added what I needed. It might not be the neatest way and there might be other more effecient ways, but as my first API script I'm quite satisfied. It only works with two meshes.
The script will return True or False to see if two meshs intersect based on a BoundingBox (both meshes have to be selected). This is enought for me, but having a boundingbox has some drawbacks. For example, say you have a torus and a cylinder is going through it. The script will return True because the cylinder will be going through the torus' bounding box, although the mesh itself might not even be touching the other mesh. Another drawback is that spheres' bounding boxes are ... boxes... Anyways, I just thought I would share it, it might be helpful for some. Please feel free to modify it any way to make it better.
edit: by the way, If you want to get a visual aid of what the bounding box looks like. All you gotta do is set your camera Shading mode to "Bounding Box" Thats pretty much the same bounding box.
# bbIntersect
# Created by rem7 on 10/08/2008
# select two meshes and run
# returns True or False to see if two meshs intersect based on a BoundingBox.
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
intersects = False
stat = OpenMaya.MStatus.kSuccess
selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selection )
dagPath = OpenMaya.MDagPath()
component = OpenMaya.MObject()
vertIndex = 0
def goThroughMesh(iter):
lix =[]
liz =[]
liy = []
while(meshIter.isDone() == 0):
pt = OpenMaya.MPoint()
pt = meshIter.position(OpenMaya.MSpace.kWorld)
vertIndex = meshIter.index()
lix.append(pt.x)
liy.append(pt.y)
liz.append(pt.z)
meshIter.next()
return lix, liy, liz
def maxMin(lix, liy, liz):
maxpt = OpenMaya.MPoint()
minpt = OpenMaya.MPoint()
maxx = max(lix)
maxy = max(liy)
maxz = max(liz)
minx = min(lix)
miny = min(liy)
minz = min(liz)
maxpt.x = maxx
maxpt.y = maxy
maxpt.z = maxz
minpt.x = minx
minpt.y = miny
minpt.z = minz
return maxpt, minpt
iter = OpenMaya.MItSelectionList(selection)
while(iter.isDone() == 0):
iter.getDagPath(dagPath,component)
meshIter = OpenMaya.MItMeshVertex(dagPath, component)
if stat == OpenMaya.MStatus.kSuccess:
lix, liy, liz = goThroughMesh(iter)
maxpt1, minpt1 = maxMin(lix, liy, liz)
bbox1 = OpenMaya.MBoundingBox(maxpt1, minpt1)
iter.next()
iter.getDagPath(dagPath,component)
meshIter = OpenMaya.MItMeshVertex(dagPath, component)
lix, liy, liz = goThroughMesh(iter)
maxpt2, minpt2 = maxMin(lix, liy, liz)
bbox2 = OpenMaya.MBoundingBox(maxpt2, minpt2)
iter.next()
intersects = OpenMaya.MBoundingBox.intersects(bbox1, bbox2)
print intersects
CGTalk Moderation
10-08-2008, 07:47 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.