use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class DistanceGrid method buildRenderObject.
/**
* Creates a new render object for rendering the points and normals
* of this grid.
*
* @return new render object
*/
RenderObject buildRenderObject(RenderProps props) {
RenderObject rob = new RenderObject();
if (myDrawEdges) {
// create line groups for both normals and edges
rob.createLineGroup();
rob.createLineGroup();
} else {
// just one line group for normals
rob.createLineGroup();
}
Vector3d widths = getCellWidths();
double len = 0.66 * widths.minElement();
if (myColorMap != null) {
for (Color color : myColors) {
rob.addColor(color);
}
}
int vidx = 0;
Vector3d coords = new Vector3d();
int xlo = myRenderRanges[0];
int xhi = myRenderRanges[1];
int ylo = myRenderRanges[2];
int yhi = myRenderRanges[3];
int zlo = myRenderRanges[4];
int zhi = myRenderRanges[5];
rob.lineGroup(NORMAL_GROUP);
for (int xi = xlo; xi < xhi; xi++) {
for (int yj = ylo; yj < yhi; yj++) {
for (int zk = zlo; zk < zhi; zk++) {
coords.set(xi, yj, zk);
myGridToLocal.transformPnt(coords, coords);
int vi = xyzIndicesToVertex(xi, yj, zk);
int cidx = myColorMap != null ? myColorIndices[vi] : -1;
rob.addPosition(coords);
rob.addVertex(vidx, -1, cidx, -1);
coords.scaledAdd(len, getLocalVertexNormal(xi, yj, zk));
rob.addPosition(coords);
rob.addVertex(vidx + 1, -1, cidx, -1);
rob.addPoint(vidx);
rob.addLine(vidx, vidx + 1);
vidx += 2;
}
}
}
if (myDrawEdges) {
rob.lineGroup(EDGE_GROUP);
int nvx = xhi - xlo;
int nvy = yhi - ylo;
int nvz = zhi - zlo;
// lines parallel to x
if (nvx > 1) {
for (int j = 0; j < nvy; j++) {
for (int k = 0; k < nvz; k++) {
int vidx0 = 2 * (j * nvz + k);
int vidx1 = 2 * ((nvx - 1) * nvy * nvz + j * nvz + k);
rob.addLine(vidx0, vidx1);
}
}
}
// lines parallel to y
if (nvy > 1) {
for (int i = 0; i < nvx; i++) {
for (int k = 0; k < nvz; k++) {
int vidx0 = 2 * (i * nvy * nvz + k);
int vidx1 = 2 * (i * nvy * nvz + (nvy - 1) * nvz + k);
rob.addLine(vidx0, vidx1);
}
}
}
// lines parallel to z
if (nvz > 1) {
for (int i = 0; i < nvx; i++) {
for (int j = 0; j < nvy; j++) {
int vidx0 = 2 * (i * nvy * nvz + j * nvz);
int vidx1 = 2 * (i * nvy * nvz + j * nvz + (nvz - 1));
rob.addLine(vidx0, vidx1);
}
}
}
}
return rob;
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class DistanceGrid method render.
public void render(Renderer renderer, RenderProps props, int flags) {
if (myTLocalToWorld != null) {
renderer.pushModelMatrix();
renderer.mulModelMatrix(myTLocalToWorld);
}
Vector3d widths = getCellWidths();
double r = 0.05 * widths.minElement();
RenderObject rob = myRob;
if (rob != null) {
if (props.getPointStyle() == PointStyle.POINT) {
if (props.getPointSize() != 0) {
renderer.setColor(props.getPointColor());
renderer.drawPoints(rob, PointStyle.POINT, props.getPointSize());
}
} else {
if (props.getPointRadius() > 0) {
renderer.setColor(props.getPointColor());
renderer.drawPoints(rob, props.getPointStyle(), props.getPointRadius());
}
}
if (props.getLineStyle() == LineStyle.LINE) {
if (props.getLineWidth() != 0) {
rob.lineGroup(NORMAL_GROUP);
renderer.setColor(props.getLineColor());
renderer.drawLines(rob, LineStyle.LINE, props.getLineWidth());
}
} else {
if (props.getLineRadius() > 0) {
rob.lineGroup(NORMAL_GROUP);
renderer.setColor(props.getLineColor());
renderer.drawLines(rob, props.getLineStyle(), props.getLineRadius());
}
}
if (myDrawEdges && rob.numLineGroups() == 2) {
if (props.getEdgeWidth() > 0) {
rob.lineGroup(EDGE_GROUP);
renderer.setColor(props.getEdgeOrLineColorF());
renderer.drawLines(rob, LineStyle.LINE, props.getEdgeWidth());
}
}
}
if (myTLocalToWorld != null) {
renderer.popModelMatrix();
}
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class ConstrainedTranslator3d method createRenderable.
private RenderObject createRenderable() {
RenderObject ro = new RenderObject();
int xcolor = ro.addColor(1.0f, 0f, 0f, 1.0f);
int ycolor = ro.addColor(0f, 1.0f, 0f, 1.0f);
int zcolor = ro.addColor(0f, 0f, 1.0f, 1.0f);
int YELLOW = ro.addColor(1.0f, 1.0f, 0f, 1.0f);
ro.createLineGroup();
ro.createLineGroup();
ro.lineGroup(0);
ro.setCurrentColor(xcolor);
// x-axis
ro.addLine(new float[] { -1, 0, 0 }, new float[] { 1, 0, 0 });
ro.setCurrentColor(ycolor);
// y-axis
ro.addLine(new float[] { 0, -1, 0 }, new float[] { 0, 1, 0 });
ro.setCurrentColor(zcolor);
// z-axis
ro.addLine(new float[] { 0, 0, -1 }, new float[] { 0, 0, 1 });
ro.setCurrentColor(YELLOW);
ro.lineGroup(1);
// x-axis
ro.addLine(new float[] { -1, 0, 0 }, new float[] { 1, 0, 0 });
// y-axis
ro.addLine(new float[] { 0, -1, 0 }, new float[] { 0, 1, 0 });
// z-axis
ro.addLine(new float[] { 0, 0, -1 }, new float[] { 0, 0, 1 });
return ro;
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class MeshRendererBase method buildRenderObject.
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
RenderObject r = new RenderObject();
addPositions(r, mesh);
addNormals(r, mesh);
addColors(r, mesh);
addTextureCoords(r, mesh);
return r;
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class PointMeshRenderer method buildRenderObject.
@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
RenderObject r = super.buildRenderObject(mesh, props);
PointMesh pmesh = (PointMesh) mesh;
int[] nidxs = pmesh.hasNormals() ? pmesh.getNormalIndices() : null;
int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
int numv = pmesh.numVertices();
for (int i = 0; i < numv; i++) {
r.addVertex(i, nidxs != null ? nidxs[i] : -1, cidxs != null ? cidxs[i] : -1, tidxs != null ? tidxs[i] : -1);
r.addPoint(i);
}
Point3d tip = new Point3d();
double normalLen = pmesh.getNormalRenderLen();
if (normalLen > 0 && pmesh.hasNormals()) {
ArrayList<Vector3d> nrmls = pmesh.getNormals();
for (int i = 0; i < numv; i++) {
Point3d pnt = pmesh.getVertex(i).pnt;
tip.scaledAdd(normalLen, nrmls.get(nidxs[i]), pnt);
r.addPosition((float) tip.x, (float) tip.y, (float) tip.z);
r.addVertex(numv + i, nidxs[i], -1, -1);
r.addLine(i, numv + i);
}
}
return r;
}
Aggregations