use of maspack.geometry.DistanceGrid in project artisynth_core by artisynth.
the class RigidBody method getDistanceGrid.
/**
* Returns a signed distance grid that can be used with a
* SignedDistanceCollider, or <code>null</code> if a grid is not available
* (i.e., if {@link #hasDistanceGrid} returns <code>false</code>).
* The number of divisons in the grid is controlled explicitly by the
* property <code>distanceGridRes</code>, or, that is 0, by the property
* <code>distanceGridMaxRes</code>. If both properties are 0, no grid is
* available and <code>null</code> will be returned.
*
* @return signed distance grid, or <code>null</code> if a grid is
* not available this RigidBody
* @see #getDistanceGridMaxRes
* @see #getDistanceGridRes
*/
public DistanceGrid getDistanceGrid() {
if (mySDGrid == null || !mySDGridValid) {
int maxRes = myDistanceGridMaxRes;
if (!myDistanceGridRes.equals(Vector3i.ZERO) || maxRes > 0) {
if (!myDistanceGridRes.equals(Vector3i.ZERO)) {
mySDGrid = new DistanceGrid(myDistanceGridRes);
maxRes = 0;
} else {
// resolution will be recomputed in computeFromFeatures
mySDGrid = new DistanceGrid(new Vector3i(1, 1, 1));
}
mySDGrid.setDrawEdges(true);
List<Face> faces = getMesh().getFaces();
if (myDistanceGridOBB) {
mySDGrid.computeFromFeaturesOBB(faces, myGridMargin, maxRes, /*signed=*/
true);
} else {
mySDGrid.computeFromFeatures(faces, myGridMargin, /*TGL=*/
null, maxRes, /*signed=*/
true);
}
mySDGrid.setLocalToWorld(getPose());
} else {
mySDGrid = null;
}
// mySDGrid.smooth (0.33, -0.34, 2);
mySDSurface = null;
mySDGridValid = true;
}
return mySDGrid;
}
use of maspack.geometry.DistanceGrid in project artisynth_core by artisynth.
the class MeshThicken method applyRemesh.
public void applyRemesh(PolygonalMesh mesh, Vector3i res) {
DistanceGrid grid = new DistanceGrid(res);
grid.computeFromFeatures(mesh.getFaces(), 0.1, null, 0, /*signed=*/
true);
grid.smooth(0.33, -0.2, 30);
mesh = grid.createQuadDistanceSurface(0, 5);
setMesh(mesh);
}
use of maspack.geometry.DistanceGrid in project artisynth_core by artisynth.
the class RigidBody method render.
public void render(Renderer renderer, int flags) {
if (myAxisLength > 0) {
int lineWidth = myRenderProps.getLineWidth();
renderer.drawAxes(myRenderFrame, myAxisLength, lineWidth, isSelected());
}
if (isSelected()) {
flags |= Renderer.HIGHLIGHT;
}
PolygonalMesh surf = null;
if (myRenderDistanceSurface != DistanceSurfaceRendering.NONE && (surf = mySDRenderSurface) != null) {
surf.render(renderer, myRenderProps, flags);
} else {
myMeshInfo.render(renderer, myRenderProps, flags);
}
DistanceGrid grid = null;
if (myRenderDistanceGrid && (grid = mySDRenderGrid) != null) {
grid.render(renderer, myRenderProps, flags);
}
}
use of maspack.geometry.DistanceGrid in project artisynth_core by artisynth.
the class RigidBody method setDistanceGridRenderRanges.
/**
* {@inheritDoc}
*/
public void setDistanceGridRenderRanges(String ranges) {
if (ranges.matches("\\s*\\*\\s*") || ranges.matches("\\s*\\*\\s+\\*\\s+\\*\\s*")) {
myDistanceGridRenderRanges = "* * *";
if (mySDGrid != null) {
mySDGrid.setRenderRanges(ranges);
}
} else {
DistanceGrid grid = getDistanceGrid();
StringHolder errMsg = new StringHolder();
if (grid.parseRenderRanges(ranges, errMsg) == null) {
throw new IllegalArgumentException("Illegal range spec: " + errMsg.value);
} else {
grid.setRenderRanges(ranges);
myDistanceGridRenderRanges = grid.getRenderRanges();
}
}
}
use of maspack.geometry.DistanceGrid in project artisynth_core by artisynth.
the class RigidBody method prerender.
public void prerender(RenderList list) {
myRenderFrame.set(myState.XFrameToWorld);
// list.addIfVisible (myMarkers);
PolygonalMesh surf = null;
if (myRenderDistanceSurface != DistanceSurfaceRendering.NONE && (surf = getDistanceSurface()) != null) {
surf.prerender(myRenderProps);
} else {
if (myRenderProps == null) {
throw new InternalErrorException("RigidBody has null RenderProps");
}
myMeshInfo.prerender(myRenderProps);
}
mySDRenderSurface = surf;
DistanceGrid grid = null;
if (myRenderDistanceGrid && (grid = getDistanceGrid()) != null) {
grid.prerender(myRenderProps);
}
mySDRenderGrid = grid;
}
Aggregations