use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Foundation method setMeshThickness.
public void setMeshThickness(final Node node, final double thickness) {
final NodeState ns = getNodeState(node);
if (!Util.isEqual(thickness, ns.getMeshThickness())) {
final double delta = thickness - ns.getMeshThickness();
for (final Spatial s : node.getChildren()) {
final Mesh m = (Mesh) s;
final UserData u = (UserData) m.getUserData();
// do not use u.getRotateNormal() because in this case rotation would be applied to node, not mesh
m.addTranslation(u.getNormal().multiply(delta, null));
}
ns.setMeshThickness(thickness);
}
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Foundation method setRotatedNormalsForImportedMeshes.
private void setRotatedNormalsForImportedMeshes() {
if (importedNodes != null) {
drawImportedNodes();
// DO NOT skip zero azimuth case -- final boolean nonZeroAz = !Util.isZero(getAzimuth());
for (final Node node : importedNodes) {
for (final Spatial s : node.getChildren()) {
final Mesh m = (Mesh) s;
final UserData ud = (UserData) m.getUserData();
ud.setRotatedNormal(node.getRotation().applyPost(ud.getNormal(), null));
}
}
}
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Foundation method createMeshThickness.
private void createMeshThickness(final Node node) {
final NodeState ns = getNodeState(node);
double thickness = ns.getMeshThickness();
if (Util.isZero(thickness)) {
thickness = 0.05;
ns.setMeshThickness(thickness);
}
for (final Spatial s : node.getChildren()) {
final Mesh m = (Mesh) s;
final UserData u = (UserData) m.getUserData();
// do not use u.getRotateNormal() because in this case rotation would be applied to node, not mesh
m.addTranslation(u.getNormal().multiply(thickness, null));
}
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class SolarPanel method drawMesh.
@Override
protected void drawMesh() {
if (container == null) {
return;
}
final double az = Math.toRadians(relativeAzimuth);
final boolean heatMap = SceneManager.getInstance().getSolarHeatMap();
boolean onFlatSurface = onFlatSurface();
// if this solar panel rests on an imported mesh or not?
final Mesh host = meshLocator == null ? null : meshLocator.find();
if (host == null) {
normal = pickedNormal != null ? pickedNormal : computeNormalAndKeepOnSurface();
} else {
final UserData ud = (UserData) host.getUserData();
normal = ud.getRotatedNormal() == null ? ud.getNormal() : ud.getRotatedNormal();
onFlatSurface = Util.isEqual(normal, Vector3.UNIT_Z);
}
updateEditShapes();
final double annotationScaleFactor = 0.5 / Scene.getInstance().getAnnotationScale();
if (rotated) {
surround.setData(new Vector3(), panelHeight * annotationScaleFactor, panelWidth * annotationScaleFactor, 0.15);
} else {
surround.setData(new Vector3(), panelWidth * annotationScaleFactor, panelHeight * annotationScaleFactor, 0.15);
}
surround.updateModelBound();
final FloatBuffer boxVertexBuffer = surround.getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
final FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
final FloatBuffer outlineBuffer = outlineMesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
outlineBuffer.rewind();
textureBuffer.rewind();
int i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(1);
textureBuffer.put(0).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
mesh.updateModelBound();
outlineMesh.updateModelBound();
switch(trackerType) {
case ALTAZIMUTH_DUAL_AXIS_TRACKER:
normal = Heliodon.getInstance().computeSunLocation(Heliodon.getInstance().getCalendar()).normalizeLocal();
break;
case HORIZONTAL_SINGLE_AXIS_TRACKER:
final Vector3 sunDirection = Heliodon.getInstance().computeSunLocation(Heliodon.getInstance().getCalendar()).normalizeLocal();
final Vector3 rotationAxis = new Vector3(Math.sin(az), Math.cos(az), 0);
final double axisSunDot = sunDirection.dot(rotationAxis);
// avoid singularity when the direction of the sun is perpendicular to the rotation axis
rotationAxis.multiplyLocal(Util.isZero(axisSunDot) ? 0.001 : axisSunDot);
normal = sunDirection.subtractLocal(rotationAxis).normalizeLocal();
break;
case VERTICAL_SINGLE_AXIS_TRACKER:
final Vector3 a = Heliodon.getInstance().computeSunLocation(Heliodon.getInstance().getCalendar()).multiplyLocal(1, 1, 0).normalizeLocal();
final Vector3 b = Vector3.UNIT_Z.cross(a, null);
final Matrix3 m = new Matrix3().applyRotation(Math.toRadians(90 - tiltAngle), b.getX(), b.getY(), b.getZ());
normal = m.applyPost(a, null);
if (normal.getZ() < 0) {
normal = normal.negate(null);
}
break;
default:
if (onFlatSurface) {
// exactly 90 degrees will cause the solar panel to disappear
setNormal(Util.isZero(tiltAngle) ? Math.PI / 2 * 0.9999 : Math.toRadians(90 - tiltAngle), Math.toRadians(relativeAzimuth));
}
}
if (Util.isEqual(normal, Vector3.UNIT_Z)) {
normal = new Vector3(-0.001, 0, 1).normalizeLocal();
}
mesh.setRotation(new Matrix3().lookAt(normal, normal.getX() > 0 ? Vector3.UNIT_Z : Vector3.NEG_UNIT_Z));
mesh.setTranslation(onFlatSurface ? getAbsPoint(0).addLocal(0, 0, baseHeight) : getAbsPoint(0));
surround.setTranslation(mesh.getTranslation());
surround.setRotation(mesh.getRotation());
outlineMesh.setTranslation(mesh.getTranslation());
outlineMesh.setRotation(mesh.getRotation());
if (onFlatSurface) {
supportFrame.getSceneHints().setCullHint(CullHint.Inherit);
drawSupporFrame();
} else {
supportFrame.getSceneHints().setCullHint(CullHint.Always);
}
if (drawSunBeam) {
drawSunBeam();
}
if (heatMap) {
drawSolarCellOutlines();
} else {
solarCellOutlines.setVisible(false);
}
drawFloatingLabel(onFlatSurface);
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class SolarPanel method addPrintMesh.
@Override
protected void addPrintMesh(final List<Mesh> list, final Mesh mesh) {
if (mesh.getSceneHints().getCullHint() != CullHint.Always) {
final Mesh newMesh = mesh.makeCopy(false);
final MaterialState material = new MaterialState();
switch(colorOption) {
case COLOR_OPTION_BLACK:
material.setDiffuse(ColorRGBA.BLACK);
break;
case COLOR_OPTION_BLUE:
material.setDiffuse(ColorRGBA.BLUE);
break;
case COLOR_OPTION_GRAY:
material.setDiffuse(ColorRGBA.GRAY);
break;
default:
material.setDiffuse(mesh.getDefaultColor());
}
newMesh.setRenderState(material);
newMesh.getMeshData().transformVertices((Transform) mesh.getWorldTransform());
newMesh.getMeshData().transformNormals((Transform) mesh.getWorldTransform(), true);
list.add(newMesh);
}
}
Aggregations