Search in sources :

Example 1 with Group

use of artisynth.core.mechmodels.Collidable.Group in project artisynth_core by artisynth.

the class SetDefaultCollisionsCommand method execute.

public void execute() {
    for (CollidablePair pair : myNewBehaviors.keySet()) {
        Group g0 = (Group) pair.get(0);
        Group g1 = (Group) pair.get(1);
        CollisionBehavior oldBehav = myMechMod.getDefaultCollisionBehavior(g0, g1);
        myOldBehaviors.put(new CollidablePair(pair), new CollisionBehavior(oldBehav));
        CollisionBehavior newBehav = myNewBehaviors.get(pair);
        myMechMod.setDefaultCollisionBehavior(g0, g1, newBehav);
    }
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group) CollidablePair(artisynth.core.mechmodels.CollidablePair) CollisionBehavior(artisynth.core.mechmodels.CollisionBehavior)

Example 2 with Group

use of artisynth.core.mechmodels.Collidable.Group in project artisynth_core by artisynth.

the class CollisionHandlerTable method collectHandlers.

public void collectHandlers(ArrayList<CollisionHandler> handlers, CollidablePair pair) {
    Collidable c0 = pair.myComp0;
    Collidable c1 = pair.myComp1;
    if (c0 instanceof Group) {
        // swap so DefaultCollidable is last
        Collidable tmp = c0;
        c0 = c1;
        c1 = tmp;
    }
    if (c1 == c0) {
        c1 = Collidable.Self;
    }
    if (c1 instanceof Group) {
        Group g1 = (Group) c1;
        if (g1.includesSelf()) {
            // self collision case
            if (c0.isCompound()) {
                ArrayList<CollidableBody> internals = CollisionManager.getInternallyCollidableBodies(c0);
                for (int i = 0; i < internals.size(); i++) {
                    CollidableBody cbi = internals.get(i);
                    for (int j = i + 1; j < internals.size(); j++) {
                        CollidableBody cbj = internals.get(j);
                        CollisionHandler handler = get(cbi, cbj);
                        if (handler != null) {
                            handlers.add(handler);
                        }
                    }
                }
            }
        }
        if (g1.includesRigid() || g1.includesDeformable()) {
            ArrayList<CollidableBody> externals = CollisionManager.getExternallyCollidableBodies(c0);
            ArrayList<CollisionHandler> chlist = new ArrayList<CollisionHandler>();
            for (int i = 0; i < externals.size(); i++) {
                CollidableBody cbi = externals.get(i);
                Anchor anchor = myAnchors.get(cbi);
                chlist.clear();
                anchor.collectHandlers(chlist);
                for (CollisionHandler ch : chlist) {
                    CollidableBody cbj = ch.getOtherCollidable(cbi);
                    if (CollisionManager.nearestCommonCollidableAncestor(cbi, cbj) == null) {
                        if ((g1.includesRigid() && !cbj.isDeformable()) || (g1.includesDeformable() && cbj.isDeformable())) {
                            handlers.add(ch);
                        }
                    }
                }
            }
        }
    } else {
        if ((c0.getCollidableAncestor() == c1) || (c1.getCollidableAncestor() == c0)) {
            return;
        } else if (CollisionManager.isCollidableBody(c0) && CollisionManager.isCollidableBody(c1)) {
            // check for specific pair
            CollisionHandler handler = get((CollidableBody) c0, (CollidableBody) c1);
            if (handler != null) {
                handlers.add(handler);
            }
        } else {
            // check for external handlers
            ArrayList<CollidableBody> externals0 = CollisionManager.getExternallyCollidableBodies(c0);
            ArrayList<CollidableBody> externals1 = CollisionManager.getExternallyCollidableBodies(c1);
            for (int i = 0; i < externals0.size(); i++) {
                CollidableBody cbi = externals0.get(i);
                for (int j = 0; j < externals1.size(); j++) {
                    CollidableBody cbj = externals1.get(j);
                    CollisionHandler handler = get(cbi, cbj);
                    if (handler != null) {
                        handlers.add(handler);
                    }
                }
            }
        }
    }
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group)

Example 3 with Group

use of artisynth.core.mechmodels.Collidable.Group in project artisynth_core by artisynth.

the class CollisionManager method updateBehaviorStructures.

// void updateCollider() {
// switch (myColliderType) {
// case TRI_INTERSECTION: {
// if (!(myCollider instanceof MeshCollider)) {
// myCollider = new MeshCollider();
// }
// break;
// }
// case AJL_CONTOUR: {
// if (!(myCollider instanceof SurfaceMeshCollider)) {
// myCollider = new SurfaceMeshCollider();
// }
// break;
// }
// default: {
// throw new InternalErrorException (
// "Unimplemented collider type " + myColliderType);
// }
// }
// }
void updateBehaviorStructures() {
    if (!myBehaviorStructuresValid) {
        ArrayList<CollidableBody> bodies;
        myExplicitBehaviors.clear();
        myRigidExtBehaviors.clear();
        myDeformableExtBehaviors.clear();
        myDeformableIntBehaviors.clear();
        // reserved for default behaviors.
        for (int k = myBehaviors.size() - 1; k >= numDefaultPairs(); k--) {
            CollisionBehavior behav = myBehaviors.get(k);
            CollidablePair pair = behav.getCollidablePair();
            Collidable c0 = pair.get(0);
            Collidable c1 = pair.get(1);
            if (!(c0 instanceof Group) && (c1 instanceof Group)) {
                Group g1 = (Group) c1;
                if (g1.includesSelf()) {
                    if (myDeformableIntBehaviors.get(c0) == null) {
                        myDeformableIntBehaviors.put(c0, behav);
                    }
                }
                if (g1.includesRigid() || g1.includesDeformable()) {
                    bodies = getExternallyCollidableBodies(c0);
                    if (g1.includesRigid()) {
                        for (CollidableBody cb : bodies) {
                            if (myRigidExtBehaviors.get(cb) == null) {
                                myRigidExtBehaviors.put(cb, behav);
                            }
                        }
                    }
                    if (g1.includesDeformable()) {
                        for (CollidableBody cb : bodies) {
                            if (myDeformableExtBehaviors.get(cb) == null) {
                                myDeformableExtBehaviors.put(cb, behav);
                            }
                        }
                    }
                }
            } else {
                setExplicitBehavior(myExplicitBehaviors, pair, behav);
            }
        }
        // now update the lists of collidable bodies
        ArrayList<Collidable> collidables = new ArrayList<Collidable>();
        getTopCollidables(collidables);
        myRigidExts.clear();
        myDeformableExts.clear();
        myDeformableInts.clear();
        ArrayList<CollidableBody> list = new ArrayList<CollidableBody>();
        for (Collidable c : collidables) {
            if (c.isDeformable()) {
                if (isCollidableBody(c)) {
                    // NOT CALLED
                    myDeformableExts.add((CollidableBody) c);
                } else {
                    list.clear();
                    getExternallyCollidableBodies(list, c);
                    myDeformableExts.addAll(list);
                    list.clear();
                    getInternallyCollidableBodies(list, c);
                    myDeformableInts.addAll(list);
                }
            } else {
                if (isCollidableBody(c)) {
                    myRigidExts.add((CollidableBody) c);
                } else {
                    list.clear();
                    getExternallyCollidableBodies(list, c);
                    myRigidExts.addAll(list);
                }
            }
        }
        myBehaviorStructuresValid = true;
    }
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group) ArrayList(java.util.ArrayList)

Example 4 with Group

use of artisynth.core.mechmodels.Collidable.Group in project artisynth_core by artisynth.

the class CollisionManager method updateGroupResponses.

int updateGroupResponses(CollidableBody cb0, CollidableBody cb1, CollisionHandler ch) {
    int numr = 0;
    // String name0 = ComponentUtils.getPathName (cb0);
    // String name1 = ComponentUtils.getPathName (cb1);
    ArrayList<CollisionResponse> resps = myGroupResponses.get(cb0);
    if (resps != null) {
        for (CollisionResponse resp : resps) {
            Group g1 = (Group) resp.getCollidable(1);
            if (cb1.isDeformable()) {
                if (g1.includesDeformable()) {
                    resp.addHandler(ch);
                    numr++;
                }
            } else {
                if (g1.includesRigid()) {
                    resp.addHandler(ch);
                    numr++;
                }
            }
        }
    }
    return numr;
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group)

Example 5 with Group

use of artisynth.core.mechmodels.Collidable.Group in project artisynth_core by artisynth.

the class CollisionManager method updateResponseStructures.

void updateResponseStructures(CollisionResponse resp) {
    CollidablePair pair = resp.getCollidablePair();
    Collidable c0 = pair.get(0);
    Collidable c1 = pair.get(1);
    if (c1 instanceof Group) {
        // String name0 = ComponentUtils.getPathName (c0);
        Group g1 = (Group) c1;
        if (g1.includesSelf() && c0.isDeformable()) {
            if (c0.isCompound()) {
                ArrayList<CollidableBody> ints = getInternallyCollidableBodies(c0);
                for (int i = 0; i < ints.size(); i++) {
                    CollidableBody ci = ints.get(i);
                    for (int j = i + 1; j < ints.size(); j++) {
                        CollidableBody cj = ints.get(j);
                        addPairResponse(ci, cj, resp);
                    }
                }
            } else if (c0 instanceof CollidableBody) {
                CollidableBody cb0 = (CollidableBody) c0;
                Collidable a0 = c0.getCollidableAncestor();
                if (a0 != null && a0.isDeformable()) {
                    ArrayList<CollidableBody> ints = getInternallyCollidableBodies(a0);
                    for (int i = 0; i < ints.size(); i++) {
                        CollidableBody ci = ints.get(i);
                        if (ci != cb0) {
                            addPairResponse(cb0, ci, resp);
                        }
                    }
                }
            }
        }
        if (g1.includesRigid() || g1.includesDeformable()) {
            ArrayList<CollidableBody> exts0 = getExternallyCollidableBodies(c0);
            for (int i = 0; i < exts0.size(); i++) {
                CollidableBody ci = exts0.get(i);
                addGroupResponse(ci, resp);
            }
        }
    } else {
        Collidable ancestor = nearestCommonCollidableAncestor(c0, c1);
        if (ancestor != null) {
            addPairResponse((CollidableBody) c0, (CollidableBody) c1, resp);
        } else {
            ArrayList<CollidableBody> exts0 = getExternallyCollidableBodies(c0);
            ArrayList<CollidableBody> exts1 = getExternallyCollidableBodies(c1);
            for (int i = 0; i < exts0.size(); i++) {
                CollidableBody ci = exts0.get(i);
                for (int j = 0; j < exts1.size(); j++) {
                    CollidableBody cj = exts1.get(j);
                    addPairResponse(ci, cj, resp);
                }
            }
        }
    }
}
Also used : Group(artisynth.core.mechmodels.Collidable.Group) ArrayList(java.util.ArrayList)

Aggregations

Group (artisynth.core.mechmodels.Collidable.Group)9 ArrayList (java.util.ArrayList)2 CollidablePair (artisynth.core.mechmodels.CollidablePair)1 CollisionBehavior (artisynth.core.mechmodels.CollisionBehavior)1 Method (artisynth.core.mechmodels.CollisionBehavior.Method)1 ContactInfo (maspack.collision.ContactInfo)1 ContactPlane (maspack.collision.ContactPlane)1 EdgeEdgeContact (maspack.collision.EdgeEdgeContact)1 IntersectionContour (maspack.collision.IntersectionContour)1 IntersectionPoint (maspack.collision.IntersectionPoint)1 PenetratingPoint (maspack.collision.PenetratingPoint)1 PenetrationRegion (maspack.collision.PenetrationRegion)1 TriTriIntersection (maspack.geometry.TriTriIntersection)1 Point3d (maspack.matrix.Point3d)1 RenderObject (maspack.render.RenderObject)1