use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class MultiViewerTesterBase method addHalfBunny.
protected static void addHalfBunny(MultiViewer tester, PolygonalMesh bunny) {
RenderProps rprops = new RenderProps();
rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
rprops.setShading(Shading.SMOOTH);
rprops.setBackColor(Color.MAGENTA.darker());
rprops.setSpecular(Color.WHITE);
rprops.setShininess(1000);
if (bunny != null) {
RenderObject r = new RenderObject();
// add all appropriate info
for (Vertex3d vtx : bunny.getVertices()) {
Point3d pos = vtx.getPosition();
r.addPosition((float) pos.x, (float) pos.y, (float) pos.z);
}
for (Vector3d nrm : bunny.getNormals()) {
r.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
}
int[] nidxs = bunny.getNormalIndices();
// left
r.createTriangleGroup();
// right
r.createTriangleGroup();
// build faces
List<Face> faces = bunny.getFaces();
int[] indexOffs = bunny.getFeatureIndexOffsets();
Vector3d centroid = new Vector3d();
for (int i = 0; i < faces.size(); i++) {
Face f = faces.get(i);
int foff = indexOffs[f.idx];
int[] pidxs = f.getVertexIndices();
// vertex indices
int[] vidxs = new int[pidxs.length];
for (int j = 0; j < pidxs.length; j++) {
// only add if unique combination
vidxs[j] = r.addVertex(pidxs[j], nidxs[foff + j], -1, -1);
}
// triangle fan for faces
f.computeCentroid(centroid);
if (centroid.x < centroid.y) {
r.triangleGroup(0);
} else {
r.triangleGroup(1);
}
r.addTriangleFan(vidxs);
}
MultiTriangleGroupWrapper rbunny = new MultiTriangleGroupWrapper(r);
rbunny.setTransform(new RigidTransform3d(new Vector3d(1.3, 1.3, 0.5), AxisAngle.IDENTITY));
rbunny.setRenderProps(rprops);
rbunny.setFaceColors(Color.RED, Color.BLUE);
tester.addRenderable(rbunny);
}
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class MultiPointSpring method prerender.
public void prerender(RenderList list) {
// can't currently tell the latter, just rebuild every time:
if (true || !myRenderObjValidP) {
RenderObject robj = buildRenderObject();
myRenderObj = robj;
myRenderObjValidP = true;
} else {
updateRenderObject(myRenderObj);
}
if (myDrawABPointsP) {
// for each wrappable segment, update the current list of AB points to
// be rendered:
updateABRenderProps();
for (int i = 0; i < numSegments(); i++) {
Segment seg = mySegments.get(i);
if (seg instanceof WrapSegment) {
WrapSegment wrapSeg = (WrapSegment) seg;
ArrayList<float[]> renderPoints = null;
SubSegment sg = wrapSeg.firstSubSegment();
if (sg != null) {
renderPoints = new ArrayList<float[]>(10);
while (sg != null) {
if (sg.myAttachmentB != null) {
renderPoints.add(getRenderCoords(sg.myPntB));
}
if (sg.myAttachmentA != null) {
renderPoints.add(getRenderCoords(sg.myPntA));
}
sg = sg.myNext;
}
}
wrapSeg.myRenderABPoints = renderPoints;
}
}
}
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class MultiPointSpring method dorender.
void dorender(Renderer renderer, RenderProps props) {
RenderObject robj = myRenderObj;
if (myDrawABPointsP) {
// draw AB points
for (int i = 0; i < numSegments(); i++) {
Segment seg = mySegments.get(i);
if (seg instanceof WrapSegment) {
WrapSegment wrapSeg = (WrapSegment) seg;
ArrayList<float[]> renderPoints = wrapSeg.myRenderABPoints;
if (renderPoints != null) {
for (int k = 0; k < renderPoints.size(); k++) {
renderer.drawPoint(myABRenderProps, renderPoints.get(k), isSelected());
}
}
}
}
}
if (robj != null) {
double size;
// draw the strands
LineStyle lineStyle = props.getLineStyle();
if (lineStyle == LineStyle.LINE) {
size = props.getLineWidth();
} else {
size = props.getLineRadius();
}
if (getRenderColor() != null) {
renderer.setColor(getRenderColor(), isSelected());
} else {
renderer.setLineColoring(props, isSelected());
}
renderer.drawLines(robj, lineStyle, size);
if (myDrawKnotsP) {
// draw the knots, if any
PointStyle pointStyle = props.getPointStyle();
if (pointStyle == PointStyle.POINT) {
size = props.getPointSize();
} else {
size = props.getPointRadius();
}
renderer.setPointColoring(props, isSelected());
robj.pointGroup(FREE_KNOTS);
renderer.drawPoints(robj, pointStyle, size);
robj.pointGroup(CONTACTING_KNOTS);
if (myContactingKnotsColor != null) {
renderer.setColor(myContactingKnotsColor);
}
renderer.drawPoints(robj, pointStyle, size);
}
}
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class MultiPointSpring method buildRenderObject.
protected RenderObject buildRenderObject() {
RenderObject robj = new RenderObject();
robj.createPointGroup();
robj.createPointGroup();
// explicitly create a line group, in case the state of the spring
// causes lines to not be added - in which case, drawLines() would fail
robj.createLineGroup();
for (int i = 0; i < numSegments(); i++) {
Segment seg = mySegments.get(i);
addRenderPos(robj, seg.myPntB.getRenderCoords(), null);
if (seg instanceof WrapSegment) {
WrapSegment wrapSeg = (WrapSegment) seg;
for (int k = 0; k < wrapSeg.myNumKnots; k++) {
WrapKnot knot = wrapSeg.myKnots[k];
addRenderPos(robj, knot.updateRenderPos(), knot);
}
}
if (i == numSegments() - 1) {
addRenderPos(robj, seg.myPntA.getRenderCoords(), null);
}
}
return robj;
}
use of maspack.render.RenderObject in project artisynth_core by artisynth.
the class PolygonalMeshRenderer method buildRenderObject.
@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
PolygonalMesh pmesh = (PolygonalMesh) mesh;
boolean useVertexNormals = props.getShading() != Shading.FLAT;
RenderObject r = new RenderObject();
addPositions(r, pmesh);
if (useVertexNormals) {
addNormals(r, pmesh);
} else {
addFaceNormals(r, pmesh);
}
addColors(r, pmesh);
addTextureCoords(r, pmesh);
int[] nidxs = useVertexNormals ? pmesh.getNormalIndices() : null;
int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
int[] indexOffs = pmesh.getFeatureIndexOffsets();
int[] pidxs = pmesh.createVertexIndices();
// FINISH Merge Quad Triangles
// Shading shadingModel = props.getShading();
// boolean mergeQuadTriangles = (shadingModel != Shading.FLAT);
// ensure capacity assume all faces are triangles
r.ensureVertexCapacity(pmesh.getFaces().size() * 3);
ArrayList<Face> faces = pmesh.getFaces();
for (int i = 0; i < faces.size(); i++) {
// Face f = faces.get(i); // XXX required?
int foff = indexOffs[i];
int numv = indexOffs[i + 1] - foff;
int[] vidxs = new int[numv];
for (int j = 0; j < numv; j++) {
vidxs[j] = r.addVertex(pidxs[foff + j], nidxs != null ? nidxs[foff + j] : i, cidxs != null ? cidxs[foff + j] : -1, tidxs != null ? tidxs[foff + j] : -1);
}
// XXX currently handled using separate index list
// // triangle fan for faces, line loop for edges
// r.addTriangleFan(vidxs);
// if (props.getDrawEdges()) {
// r.addLineLoop(vidxs);
// }
}
return r;
}
Aggregations