use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MultiGL2Tester method addRenderObjects.
protected static void addRenderObjects(MultiViewer tester) {
addCube(tester);
addAxes(tester);
addTransRotator(tester);
addCylinder(tester);
PolygonalMesh bunny = loadStanfordBunny();
addStanfordBunnies(tester, bunny);
addSolidBunny(tester, bunny);
addHalfBunny(tester, bunny);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class ColouredSphereTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
PolygonalMesh mesh = MeshFactory.createOctahedralSphere(1, 4);
HueColorMap map = new HueColorMap();
mesh.setVertexColoringEnabled();
for (int i = 0; i < mesh.numVertices(); ++i) {
// hsv interpolation of colors based on height (-1 to 1)
Vertex3d vtx = mesh.getVertex(i);
double pos = vtx.getPosition().z;
Color c = map.getColor((pos + 1) / 2);
mesh.setColor(i, c);
}
RenderProps rprops = new RenderProps();
rprops.setShading(Shading.SMOOTH);
rprops.setShininess(128);
rprops.setSpecular(Color.WHITE);
mesh.setRenderProps(rprops);
// FixedMeshBody fm = new FixedMeshBody (mesh);
mv.addRenderable(mesh);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class Main method setDragger.
private void setDragger() {
translator3d.setVisible(false);
transrotator3d.setVisible(false);
scalar3d.setVisible(false);
rotator3d.setVisible(false);
constrainedTranslator3d.setVisible(false);
constrainedTranslator3d.setMesh(null);
currentDragger = null;
myDraggableComponents.clear();
if (mySelectionMode != SelectionMode.Select && mySelectionMode != SelectionMode.EllipticSelect && mySelectionMode != SelectionMode.Pull) {
Point3d pmin = new Point3d(inf, inf, inf);
Point3d pmax = new Point3d(-inf, -inf, -inf);
int n = 0;
for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
if (sel instanceof Renderable && sel instanceof TransformableGeometry && !ComponentUtils.isAncestorSelected(sel)) {
myDraggableComponents.add(sel);
((Renderable) sel).updateBounds(pmin, pmax);
n++;
}
}
if (n > 0) {
RigidTransform3d TDW = new RigidTransform3d();
double radius = computeDraggerToWorld(TDW, myDraggableComponents, null);
// set a minimum radius to about 1/6 of the viewer window width
radius = Math.max(radius, myViewer.distancePerPixel(myViewer.getCenter()) * myViewer.getScreenWidth() / 6);
if (mySelectionMode == SelectionMode.Translate) {
translator3d.setVisible(true);
translator3d.setDraggerToWorld(TDW);
translator3d.setSize(radius);
currentDragger = translator3d;
} else if (mySelectionMode == SelectionMode.Transrotate) {
transrotator3d.setVisible(true);
transrotator3d.setDraggerToWorld(TDW);
transrotator3d.setSize(radius);
currentDragger = transrotator3d;
} else if (mySelectionMode == SelectionMode.Scale) {
scalar3d.setVisible(true);
scalar3d.setDraggerToWorld(TDW);
scalar3d.setSize(radius);
currentDragger = scalar3d;
} else if (mySelectionMode == SelectionMode.Rotate) {
rotator3d.setVisible(true);
rotator3d.setDraggerToWorld(TDW);
rotator3d.setSize(radius);
currentDragger = rotator3d;
} else if (mySelectionMode == SelectionMode.ConstrainedTranslate) {
PolygonalMesh mesh = null;
for (Object sel : mySelectionManager.getCurrentSelection()) {
if (sel instanceof FrameMarker) {
FrameMarker frameMarker = (FrameMarker) sel;
Point3d p = new Point3d(frameMarker.getPosition());
constrainedTranslator3d.setLocation(p);
Frame frame = frameMarker.getFrame();
if (frame instanceof RigidBody) {
mesh = ((RigidBody) frame).getMesh();
}
break;
}
}
if (mesh != null) {
constrainedTranslator3d.setSize(radius);
constrainedTranslator3d.setMesh(mesh);
constrainedTranslator3d.setVisible(true);
currentDragger = constrainedTranslator3d;
}
}
}
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MeshComponent method getSurfaceMeshes.
public static PolygonalMesh[] getSurfaceMeshes(MeshComponentList<?> list) {
PolygonalMesh[] meshes = new PolygonalMesh[numSurfaceMeshes(list)];
int k = 0;
for (MeshComponent mc : list) {
MeshBase mesh = mc.getMesh();
if (mesh != null && mesh instanceof PolygonalMesh) {
meshes[k++] = (PolygonalMesh) mesh;
}
}
return meshes;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MultiPointSpring method computeDefaultMaxWrapDisplacement.
private double computeDefaultMaxWrapDisplacement() {
double mind = Double.POSITIVE_INFINITY;
CompositeComponent comp = ComponentUtils.nearestEncapsulatingAncestor(this);
if (comp instanceof Renderable) {
mind = RenderableUtils.getRadius((Renderable) comp) / 10;
}
for (Wrappable w : myWrappables) {
if (w instanceof HasSurfaceMesh) {
PolygonalMesh mesh = ((HasSurfaceMesh) w).getSurfaceMesh();
if (mesh != null) {
OBB obb = new OBB(mesh);
Vector3d widths = new Vector3d();
obb.getWidths(widths);
double hw = widths.minElement() / 2;
if (hw < mind) {
mind = hw / 2;
}
}
}
}
if (mind == Double.POSITIVE_INFINITY) {
mind = 1.0;
}
return mind;
}
Aggregations