use of maspack.render.RenderProps in project artisynth_core by artisynth.
the class FaceComponent method render.
@Override
public void render(Renderer renderer, int flags) {
RenderProps props = getRenderProps();
if (props == null) {
return;
}
if (props.getDrawEdges()) {
float savedLineWidth = renderer.getLineWidth();
Shading savedShadeModel = renderer.getShading();
renderer.setLineWidth(props.getLineWidth());
if (props.getLineColor() != null && !renderer.isSelecting()) {
renderer.setShading(Shading.NONE);
renderer.setLineColoring(props, isSelected());
}
if (useVertexColouring && !renderer.isSelecting()) {
renderer.setShading(Shading.SMOOTH);
} else {
renderer.setShading(Shading.FLAT);
}
drawEdges(renderer, props);
renderer.setLineWidth(savedLineWidth);
renderer.setShading(savedShadeModel);
}
if (props.getFaceStyle() != Renderer.FaceStyle.NONE) {
Shading savedShadeModel = renderer.getShading();
Shading shading = props.getShading();
if (shading != Shading.NONE) {
renderer.setFaceColoring(props, isSelected());
}
if (shading == Shading.NONE) {
renderer.setColor(props.getFaceColorF(), isSelected());
}
renderer.setShading(shading);
if (props.getDrawEdges()) {
renderer.setDepthOffset(1);
}
drawFaces(renderer, shading, props);
if (props.getDrawEdges()) {
renderer.setDepthOffset(0);
}
renderer.setShading(savedShadeModel);
}
}
use of maspack.render.RenderProps in project artisynth_core by artisynth.
the class TextComponent3d method render.
@Override
public void render(Renderer renderer, int flags) {
if (!isSelectable() && renderer.isSelecting()) {
return;
}
// text orientation computation
Rectangle2D box = renderer.getTextBounds(myFont, myText, myTextSize);
double w = box.getWidth();
double t = box.getY() + box.getHeight();
double vc = box.getY() + box.getHeight() / 2;
rEye.invert(renderer.getViewMatrix().R);
if (followEye) {
rEye.getColumn(0, xdir);
} else {
xdir[0] = 1;
xdir[1] = 0;
xdir[2] = 0;
}
renderPos.setZero();
switch(hAlignment) {
case CENTRE:
renderPos.add(-xdir[0] * w / 2, -xdir[1] * w / 2, -xdir[2] * w / 2);
break;
case RIGHT:
renderPos.add(-xdir[0] * w, -xdir[1] * w, -xdir[2] * w);
break;
default:
break;
}
if (followEye) {
rEye.getColumn(1, xdir);
} else {
xdir[0] = 0;
xdir[1] = 1;
xdir[2] = 0;
}
switch(vAlignment) {
case CENTRE:
renderPos.add(-xdir[0] * vc, -xdir[1] * vc, -xdir[2] * vc);
break;
case TOP:
renderPos.add(-xdir[0] * t, -xdir[1] * t, -xdir[2] * t);
break;
default:
}
// account for non-zero orientation
myTransform.setRotation(myOrientation);
if (followEye) {
myTransform.R.mul(rEye, myTransform.R);
renderPos.inverseTransform(rEye);
}
renderPos.transform(myTransform.R);
renderPos.add(myPos);
myTransform.p.set(renderPos);
renderer.pushModelMatrix();
renderer.mulModelMatrix(myTransform);
RenderProps rprops = getRenderProps();
// Shading savedShading = renderer.setShading (rprops.getShading ());
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setFaceColoring(rprops, isSelected());
FaceStyle savedFaceStyle = renderer.setFaceStyle(rprops.getFaceStyle());
final float[] ZERO = { 0, 0, 0 };
renderer.drawText(myFont, myText, ZERO, myTextSize);
renderer.setFaceStyle(savedFaceStyle);
renderer.setShading(savedShading);
renderer.popModelMatrix();
}
use of maspack.render.RenderProps in project artisynth_core by artisynth.
the class SkinDemo method addLoad.
public void addLoad() {
RigidBody lowerArm = model.rigidBodies().get("lower");
if (lowerArm == null) {
return;
}
double mass = 1.0;
Particle load = new Particle(mass, new Point3d(-14.14, 0, -14.14));
load.setName("load");
// Particle load = new Particle(mass,new Point3d(0,0,0));
RenderProps rp = new RenderProps(model.getRenderProps());
rp.setShading(Renderer.Shading.SMOOTH);
rp.setPointColor(Color.ORANGE);
rp.setPointRadius(len / 20);
load.setRenderProps(rp);
model.addParticle(load);
model.attachPoint(load, lowerArm, new Point3d(0, 0, len / 2));
}
use of maspack.render.RenderProps in project artisynth_core by artisynth.
the class ColoredSphereTest method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
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);
addRenderable(fm);
}
use of maspack.render.RenderProps in project artisynth_core by artisynth.
the class ForceTargetDemo method build.
public void build(String[] args) throws IOException {
// create MechModel and add to RootModel
mech = new MechModel("mech");
addModel(mech);
// create the components
p1 = new Particle("p1", /*mass=*/
2, /*x,y,z=*/
0, 0, 0.15);
p2 = new Particle("p2", 2, 10, 0, 0.15);
p3 = new Particle("p3", 2, 5, 5, 0);
p4 = new Particle("p4", 2, 5, -5, 0);
p5 = new Particle("p5", 0, 5, 0, 5);
p6 = new Particle("p6", 0, 5, 0, -5);
box = RigidBody.createBox("box", /*wx,wy,wz=*/
0.5, 0.3, 0.3, /*density=*/
1);
box.setPose(new RigidTransform3d(/*x,y,z=*/
5, 0, -0.15));
// create marker point and connect it to the box:
FrameMarker mkr = new FrameMarker(/*x,y,z=*/
0, 0, 0.15);
mkr.setFrame(box);
// create the muscle:
muscle = new Muscle("mus1", /*restLength=*/
5);
muscle.setPoints(p1, mkr);
muscle.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
1000));
muscle2 = new Muscle("mus2", /*restLength=*/
5);
muscle2.setPoints(p2, mkr);
muscle2.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
1000));
muscle3 = new Muscle("mus3", /*restLength=*/
5);
muscle3.setPoints(p3, mkr);
muscle3.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle4 = new Muscle("mus4", /*restLength=*/
5);
muscle4.setPoints(p4, mkr);
muscle4.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle5 = new Muscle("mus5", /*restLength=*/
5);
muscle5.setPoints(p5, mkr);
muscle5.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
muscle6 = new Muscle("mus6", /*restLength=*/
5);
muscle6.setPoints(p6, mkr);
muscle6.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
0, /*damping=*/
10, /*maxf=*/
4000));
if (two_cons == true) {
RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(90));
// Connection on the corner
// PlanarConnector connector =
// new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
// Connection in the center
con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
con.setUnilateral(false);
con.setPlaneSize(2);
RenderProps props = con.createRenderProps();
props.setPointColor(Color.blue);
props.setPointStyle(Renderer.PointStyle.SPHERE);
props.setPointRadius(0.06);
con.setRenderProps(props);
// con = new ParticlePlaneConstraint(p5, pl);
// RenderProps.setDrawEdges (con, true);
// RenderProps.setVisible (con, true);
RigidTransform3d XPW2 = new RigidTransform3d(5, 0, 0);
XPW2.R.mulAxisAngle(1, 0, 0, 0);
// Connection on the corner
// PlanarConnector connector =
// new PlanarConnector (box, new Vector3d (lenx/2, -2.5, 1.5), XPW);
// Connection in the center
con2 = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW2);
con2.setUnilateral(false);
con2.setPlaneSize(2);
con2.setRenderProps(props);
} else {
RigidTransform3d XPW = new RigidTransform3d(5, 0, 0);
XPW.R.mulAxisAngle(1, 0, 0, Math.toRadians(45));
con = new PlanarConnector(box, new Vector3d(0, 0, 0.15), XPW);
con.setUnilateral(false);
con.setPlaneSize(2);
RenderProps props = con.createRenderProps();
props.setPointColor(Color.blue);
props.setPointStyle(Renderer.PointStyle.SPHERE);
props.setPointRadius(0.06);
con.setRenderProps(props);
}
// con.setRenderProps (myRenderProps);
// add components to the mech model
mech.addParticle(p1);
mech.addParticle(p2);
mech.addParticle(p3);
mech.addParticle(p4);
mech.addParticle(p5);
mech.addParticle(p6);
mech.addRigidBody(box);
mech.addFrameMarker(mkr);
// mech.addParticle (p5);
mech.addAxialSpring(muscle);
mech.addAxialSpring(muscle2);
mech.addAxialSpring(muscle3);
mech.addAxialSpring(muscle4);
mech.addAxialSpring(muscle5);
mech.addAxialSpring(muscle6);
con.setName("con1");
if (two_cons == true) {
con2.setName("con2");
}
if (cons == true) {
mech.addBodyConnector(con);
ConnectorForceRenderer rend = new ConnectorForceRenderer(con);
myRenderProps = rend.createRenderProps();
myRenderProps.setLineStyle(LineStyle.CYLINDER);
myRenderProps.setLineRadius(0.175);
myRenderProps.setLineColor(Color.BLUE);
rend.setRenderProps(myRenderProps);
rend.setArrowSize(0.1);
addMonitor(rend);
}
if (two_cons == true) {
mech.addBodyConnector(con2);
}
// first particle set to be fixed
p1.setDynamic(false);
p2.setDynamic(false);
p3.setDynamic(false);
p4.setDynamic(false);
p5.setDynamic(false);
p6.setDynamic(false);
// increase model bounding box for the viewer
mech.setBounds(/*min=*/
-1, 0, -1, /*max=*/
1, 0, 0);
// set render properties for the components
setPointRenderProps(p1);
setPointRenderProps(p2);
setPointRenderProps(p3);
setPointRenderProps(p4);
setPointRenderProps(p5);
setPointRenderProps(p6);
setPointRenderProps(mkr);
setLineRenderProps(muscle);
setLineRenderProps(muscle2);
setLineRenderProps(muscle3);
setLineRenderProps(muscle4);
setLineRenderProps(muscle5);
setLineRenderProps(muscle6);
addTrackingController(mkr);
if (cons = true) {
addConForceProbe(10, 0.1);
}
}
Aggregations