use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class StlRenderer method drawSpindle.
@Override
public void drawSpindle(Vector3d pnt0, Vector3d pnt1, double rad) {
if (rad < Double.MIN_NORMAL) {
return;
}
double dx = pnt1.x - pnt0.x;
double dy = pnt1.y - pnt0.y;
double dz = pnt1.z - pnt0.z;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
// compute required rotation
RigidTransform3d lineRot = getLineTransform(pnt0, pnt1);
int resolution = getSurfaceResolution();
PrimitiveKey key = new PrimitiveKey(PrimitiveType.SPINDLE, resolution);
RenderObject robj = primitiveMap.get(key);
if (robj == null) {
robj = RenderObjectFactory.createSpindle(resolution, resolution / 2);
primitiveMap.put(key, robj);
}
// scale and translate model matrix
pushModelMatrix();
mulModelMatrix(lineRot);
scaleModelMatrix(rad, rad, len);
// draw spindle
drawTriangles(robj, 0);
// revert matrix transform
popModelMatrix();
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class StlRenderer method drawCylinder.
@Override
public void drawCylinder(Vector3d pnt0, Vector3d pnt1, double rad, boolean capped) {
if (rad < Double.MIN_NORMAL) {
return;
}
double dx = pnt1.x - pnt0.x;
double dy = pnt1.y - pnt0.y;
double dz = pnt1.z - pnt0.z;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
// compute required rotation
RigidTransform3d lineRot = getLineTransform(pnt0, pnt1);
int resolution = getSurfaceResolution();
PrimitiveKey key;
if (capped) {
key = new PrimitiveKey(PrimitiveType.CAPPED_CYLINDER, resolution);
} else {
key = new PrimitiveKey(PrimitiveType.UNCAPPED_CYLINDER, resolution);
}
RenderObject robj = primitiveMap.get(key);
if (robj == null) {
robj = RenderObjectFactory.createCylinder(resolution, capped);
primitiveMap.put(key, robj);
}
// scale and translate model matrix
pushModelMatrix();
mulModelMatrix(lineRot);
scaleModelMatrix(rad, rad, len);
// draw cylinder
drawTriangles(robj, 0);
// revert matrix transform
popModelMatrix();
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class StlRenderer method restoreDefaultState.
@Override
public void restoreDefaultState(boolean strictChecking) {
if (myMappingsSet) {
if (myColorMapProps != null) {
setColorMap(null);
}
if (myNormalMapProps != null) {
setNormalMap(null);
}
if (myBumpMapProps != null) {
setBumpMap(null);
}
myMappingsSet = false;
}
if (myNonDefaultColorSettings != 0) {
if (myBackColor != null) {
setBackColor(null);
}
if ((myNonDefaultColorSettings & EMISSION_BIT) != 0) {
setEmission(DEFAULT_MATERIAL_EMISSION);
}
if ((myNonDefaultColorSettings & SPECULAR_BIT) != 0) {
setSpecular(DEFAULT_MATERIAL_SPECULAR);
}
if ((myNonDefaultColorSettings & SHININESS_BIT) != 0) {
setShininess(DEFAULT_MATERIAL_SHININESS);
}
if (getColorInterpolation() != DEFAULT_COLOR_INTERPOLATION) {
setColorInterpolation(DEFAULT_COLOR_INTERPOLATION);
}
if (myActiveColor == ActiveColor.HIGHLIGHT) {
setHighlighting(false);
}
myNonDefaultColorSettings = 0;
}
if (myNonDefaultGeneralSettings != 0) {
if (myViewerState.faceMode != DEFAULT_FACE_STYLE) {
setFaceStyle(DEFAULT_FACE_STYLE);
}
if ((myNonDefaultGeneralSettings & LINE_WIDTH_BIT) != 0) {
setLineWidth(DEFAULT_LINE_WIDTH);
}
if ((myNonDefaultGeneralSettings & POINT_SIZE_BIT) != 0) {
setPointSize(DEFAULT_POINT_SIZE);
}
if (myViewerState.shading != DEFAULT_SHADING) {
setShading(DEFAULT_SHADING);
}
// }
if (myViewerState.colorMixing != DEFAULT_COLOR_MIXING) {
setVertexColorMixing(DEFAULT_COLOR_MIXING);
}
if (getDepthOffset() != DEFAULT_DEPTH_OFFSET) {
setDepthOffset(DEFAULT_DEPTH_OFFSET);
}
myNonDefaultGeneralSettings = 0;
}
if (myModelMatrixSet) {
int mmsize = modelMatrixStack.size();
if (mmsize > 0) {
if (strictChecking) {
throw new IllegalStateException("render() method exited with model matrix stack size of " + mmsize);
} else {
while (mmsize > 0) {
modelMatrixStack.pop();
mmsize--;
}
}
} else {
synchronized (modelMatrix) {
if (!modelMatrix.isIdentity()) {
// reset to identity
modelMatrix = new RigidTransform3d();
modelNormalMatrix = new Matrix3d();
}
}
}
myModelMatrixSet = false;
}
if (myDrawMode != null) {
if (strictChecking) {
throw new IllegalStateException("render() method exited while still in draw mode: " + myDrawMode);
} else {
resetDraw();
}
}
// set front alpha if not one
if (myCurrentMaterial.isTransparent()) {
setFrontAlpha(1.0f);
}
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class StlRenderer method drawCone.
@Override
public void drawCone(Vector3d pnt0, Vector3d pnt1, double rad0, double rad1, boolean capped) {
// get a capped or uncapped cylinder
double rad = 1;
double dx = pnt1.x - pnt0.x;
double dy = pnt1.y - pnt0.y;
double dz = pnt1.z - pnt0.z;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
// compute required rotation
RigidTransform3d lineRot = getLineTransform(pnt0, pnt1);
int resolution = getSurfaceResolution();
PrimitiveKey key;
if (capped) {
key = new PrimitiveKey(PrimitiveType.CAPPED_CYLINDER, resolution);
} else {
key = new PrimitiveKey(PrimitiveType.UNCAPPED_CYLINDER, resolution);
}
RenderObject robj = primitiveMap.get(key);
if (robj == null) {
robj = RenderObjectFactory.createCylinder(resolution, capped);
primitiveMap.put(key, robj);
}
// scale and translate model matrix
pushModelMatrix();
mulModelMatrix(lineRot);
scaleModelMatrix(rad, rad, len);
Point3d p0 = new Point3d();
Point3d p1 = new Point3d();
Point3d p2 = new Point3d();
// draw cylinder
robj.readLock();
{
try {
int[] tris = robj.getTriangles(0);
int ntris = robj.numTriangles(0);
int triStride = robj.getTriangleStride();
for (int i = 0; i < triStride * ntris; i += triStride) {
float[] v0 = robj.getVertexPosition(tris[i]);
float[] v1 = robj.getVertexPosition(tris[i + 1]);
float[] v2 = robj.getVertexPosition(tris[i + 2]);
// scale radially based on z
p0 = toPoint(v0);
double s0 = v0[2] * rad1 + (1 - v0[2]) * rad0;
p0.x *= s0;
p0.y *= s0;
p1 = toPoint(v1);
double s1 = v1[2] * rad1 + (1 - v1[2]) * rad0;
p1.x *= s1;
p1.y *= s1;
p2 = toPoint(v2);
double s2 = v2[2] * rad1 + (1 - v2[2]) * rad0;
p2.x *= s2;
p2.y *= s2;
// transform by model matrix
p0.transform(modelMatrix);
p1.transform(modelMatrix);
p2.transform(modelMatrix);
// write
writer.writeTriangle(p0, p1, p2);
}
} catch (IOException e) {
e.printStackTrace();
}
}
robj.readUnlock();
// revert matrix transform
popModelMatrix();
}
use of maspack.matrix.RigidTransform3d in project artisynth_core by artisynth.
the class StlRenderer method getLineTransform.
protected RigidTransform3d getLineTransform(Vector3d p0, Vector3d p1) {
RigidTransform3d X = new RigidTransform3d();
Vector3d utmp = new Vector3d();
utmp.set(p1.x - p0.x, p1.y - p0.y, p1.z - p0.z);
X.p.set(p0.x, p0.y, p0.z);
X.R.setZDirection(utmp);
return X;
}
Aggregations