use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Roof method computeArea.
@Override
protected void computeArea() {
this.area = 0;
if (container == null) {
return;
}
if (areaByPartWithOverhang == null) {
areaByPartWithOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithOverhang.clear();
}
if (areaByPartWithoutOverhang == null) {
areaByPartWithoutOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithoutOverhang.clear();
}
for (final Spatial roofPart : roofPartsRoot.getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Node roofPartNode = (Node) roofPart;
final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(REAL_MESH_INDEX);
areaByPartWithOverhang.put(roofPartMesh, Util.computeArea(roofPartMesh));
final FloatBuffer vertexBuffer = roofPartMesh.getMeshData().getVertexBuffer();
final Vector3 p = new Vector3();
if (overhangLength <= OVERHANG_MIN) {
final double a = Util.computeArea(roofPartMesh);
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
if (result.isEmpty()) {
vertexBuffer.rewind();
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
final double a;
if (Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
a = Util.computeArea(roofPartMesh);
} else {
a = 0;
}
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
// if (roofPartsRoot.getNumberOfChildren() > 1) {
double highPointZ = Double.NEGATIVE_INFINITY;
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() > highPointZ) {
highPointZ = p.getZ();
}
}
final List<ReadOnlyVector3> highPoints = new ArrayList<ReadOnlyVector3>();
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() >= highPointZ - MathUtils.ZERO_TOLERANCE && Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
highPoints.add(new Vector3(p));
}
}
if (highPoints.size() == 1) {
result.add(highPoints.get(0));
} else {
final ReadOnlyVector3 lastPoint = result.get(result.size() - 1);
while (!highPoints.isEmpty()) {
double shortestDistance = Double.MAX_VALUE;
ReadOnlyVector3 nearestPoint = null;
for (final ReadOnlyVector3 hp : highPoints) {
final double distance = hp.distance(lastPoint);
if (distance < shortestDistance) {
shortestDistance = distance;
nearestPoint = hp;
}
}
result.add(nearestPoint);
highPoints.remove(nearestPoint);
}
}
result.add(result.get(0));
final double annotationScale = Scene.getInstance().getAnnotationScale();
final double a = Util.area3D_Polygon(result, (ReadOnlyVector3) roofPart.getUserData()) * annotationScale * annotationScale;
areaByPartWithoutOverhang.put(roofPartMesh, a);
this.area += a;
}
}
}
}
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Sensor method init.
@Override
protected void init() {
super.init();
mesh = new Mesh("Sensor");
mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
root.attachChild(mesh);
surround = new Box("Sensor (Surround)");
surround.setModelBound(new OrientedBoundingBox());
final OffsetState offset = new OffsetState();
offset.setFactor(1);
offset.setUnits(1);
surround.setRenderState(offset);
root.attachChild(surround);
outlineMesh = new Line("Sensor (Outline)");
outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
outlineMesh.setDefaultColor(ColorRGBA.BLACK);
outlineMesh.setModelBound(new OrientedBoundingBox());
root.attachChild(outlineMesh);
label = new BMText("" + getId(), "0", FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
Util.initHousePartLabel(label);
label.setFontScale(0.6);
label.setVisible(true);
root.attachChild(label);
updateTextureAndColor();
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Mirror method init.
@Override
protected void init() {
super.init();
if (Util.isZero(mirrorWidth)) {
mirrorWidth = 5;
}
if (Util.isZero(mirrorHeight)) {
mirrorHeight = 3;
}
if (Util.isZero(reflectance)) {
reflectance = 0.9;
}
if (Util.isZero(opticalEfficiency)) {
opticalEfficiency = 1;
}
if (Util.isZero(baseHeight)) {
baseHeight = 10;
}
if (heliostatTarget != null) {
// FIXME: Somehow the target, when copied, doesn't point to the right object. This is not a prefect solution, but it fixes the problem.
final HousePart hp = Scene.getInstance().getPart(heliostatTarget.getId());
if (hp instanceof Foundation) {
heliostatTarget = (Foundation) hp;
} else {
heliostatTarget = null;
}
}
mesh = new Mesh("Reflecting Mirror");
mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
root.attachChild(mesh);
surround = new Box("Mirror (Surround)");
surround.setModelBound(new OrientedBoundingBox());
final OffsetState offset = new OffsetState();
offset.setFactor(1);
offset.setUnits(1);
surround.setRenderState(offset);
root.attachChild(surround);
outlineMesh = new Line("Mirror (Outline)");
outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
outlineMesh.setDefaultColor(ColorRGBA.BLACK);
outlineMesh.setModelBound(new OrientedBoundingBox());
root.attachChild(outlineMesh);
// if there are many mirrors, reduce the solution of post
post = new Cylinder("Post Cylinder", 2, Scene.getInstance().getAllHeliostats().size() < 200 ? 10 : 2, 10, 0);
post.setRadius(0.6);
post.setDefaultColor(ColorRGBA.WHITE);
post.setRenderState(offsetState);
post.setModelBound(new BoundingBox());
post.updateModelBound();
root.attachChild(post);
lightBeams = new Line("Light Beams");
lightBeams.setLineWidth(1f);
lightBeams.setStipplePattern((short) 0xffff);
lightBeams.setModelBound(null);
// final BlendState blendState = new BlendState();
// blendState.setBlendEnabled(true);
// lightBeams.setRenderState(blendState);
// lightBeams.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
Util.disablePickShadowLight(lightBeams);
lightBeams.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
lightBeams.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
root.attachChild(lightBeams);
label = new BMText("Label", "# " + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
Util.initHousePartLabel(label);
label.setFontScale(0.5);
label.setVisible(false);
root.attachChild(label);
updateTextureAndColor();
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class SolarPanel method init.
@Override
protected void init() {
super.init();
if (Util.isZero(panelWidth)) {
panelWidth = 0.99;
}
if (Util.isZero(panelHeight)) {
panelHeight = 1.65;
}
if (Util.isZero(efficiency)) {
// make it the same as the default one in PvModuleSpecs
efficiency = 0.1833;
}
if (Util.isZero(temperatureCoefficientPmax)) {
temperatureCoefficientPmax = -0.005;
}
if (Util.isZero(nominalOperatingCellTemperature)) {
nominalOperatingCellTemperature = 48;
}
if (Util.isZero(inverterEfficiency)) {
inverterEfficiency = 0.95;
}
if (Util.isZero(baseHeight)) {
baseHeight = 5;
}
if (Util.isZero(numberOfCellsInX)) {
numberOfCellsInX = 6;
}
if (Util.isZero(numberOfCellsInY)) {
numberOfCellsInY = 10;
}
if (pvModuleSpecs == null) {
// backward compatibility
pvModuleSpecs = new PvModuleSpecs("Custom");
pvModuleSpecs.setCellEfficiency(efficiency);
pvModuleSpecs.setWidth(panelWidth);
pvModuleSpecs.setLength(panelHeight);
pvModuleSpecs.setNoct(nominalOperatingCellTemperature);
pvModuleSpecs.setPmaxTc(temperatureCoefficientPmax);
pvModuleSpecs.setLayout(numberOfCellsInX, numberOfCellsInY);
switch(cellType) {
case POLYCRYSTALLINE:
pvModuleSpecs.setCellType("Polycrystalline");
colorOption = COLOR_OPTION_BLUE;
break;
case MONOCRYSTALLINE:
pvModuleSpecs.setCellType("Monocrystalline");
colorOption = COLOR_OPTION_BLACK;
break;
case THIN_FILM:
pvModuleSpecs.setCellType("Thin Film");
colorOption = COLOR_OPTION_BLACK;
break;
}
} else {
convertStringPropertiesToIntegerProperties();
}
mesh = new Mesh("SolarPanel");
mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
root.attachChild(mesh);
surround = new Box("SolarPanel (Surround)");
surround.setModelBound(new OrientedBoundingBox());
final OffsetState offset = new OffsetState();
offset.setFactor(1);
offset.setUnits(1);
surround.setRenderState(offset);
root.attachChild(surround);
outlineMesh = new Line("SolarPanel (Outline)");
outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
outlineMesh.setDefaultColor(ColorRGBA.BLACK);
outlineMesh.setModelBound(new OrientedBoundingBox());
root.attachChild(outlineMesh);
supportFrame = new Mesh("Supporting Frame");
supportFrame.getMeshData().setIndexMode(IndexMode.Quads);
supportFrame.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(12));
supportFrame.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(12));
supportFrame.setRenderState(offsetState);
supportFrame.setModelBound(new BoundingBox());
root.attachChild(supportFrame);
sunBeam = new Line("Sun Beam");
sunBeam.setLineWidth(1f);
sunBeam.setStipplePattern((short) 0xffff);
sunBeam.setModelBound(null);
Util.disablePickShadowLight(sunBeam);
sunBeam.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
sunBeam.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
root.attachChild(sunBeam);
normalVector = new Line("Normal Vector");
normalVector.setLineWidth(1f);
normalVector.setStipplePattern((short) 0xffff);
normalVector.setModelBound(null);
Util.disablePickShadowLight(normalVector);
normalVector.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
normalVector.setDefaultColor(new ColorRGBA(1f, 1f, 0f, 1f));
root.attachChild(normalVector);
angles = new Node("Angles");
angles.getSceneHints().setAllPickingHints(false);
Util.disablePickShadowLight(angles);
root.attachChild(angles);
// the angle between the sun beam and the normal vector
sunAngle = new AngleAnnotation();
sunAngle.setColor(ColorRGBA.WHITE);
sunAngle.setLineWidth(1);
sunAngle.setFontSize(1);
sunAngle.setCustomRadius(normalVectorLength * 0.8);
angles.attachChild(sunAngle);
label = new BMText("Label", "# " + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
Util.initHousePartLabel(label);
label.setFontScale(0.5);
label.setVisible(false);
root.attachChild(label);
solarCellOutlines = new Line("Solar Cell Outlines");
solarCellOutlines.setLineWidth(1f);
solarCellOutlines.setStipplePattern((short) 0xffff);
solarCellOutlines.setModelBound(null);
Util.disablePickShadowLight(solarCellOutlines);
solarCellOutlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(1));
solarCellOutlines.setDefaultColor(new ColorRGBA(0f, 0f, 0f, 1f));
root.attachChild(solarCellOutlines);
updateTextureAndColor();
}
use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.
the class Wall method setOriginal.
@Override
public void setOriginal(final HousePart original) {
final Wall originalWall = (Wall) original;
this.thicknessNormal = originalWall.getThicknessNormal();
root.detachChild(invisibleMesh);
root.detachChild(backMesh);
root.detachChild(surroundMesh);
root.detachChild(windowsSurroundMesh);
root.detachChild(outlineMesh);
backMesh = originalWall.backMesh.makeCopy(true);
surroundMesh = originalWall.surroundMesh.makeCopy(true);
windowsSurroundMesh = originalWall.windowsSurroundMesh.makeCopy(true);
outlineMesh = originalWall.outlineMesh.makeCopy(true);
((Line) outlineMesh).setLineWidth(printOutlineThickness);
root.attachChild(backMesh);
root.attachChild(surroundMesh);
root.attachChild(windowsSurroundMesh);
root.attachChild(outlineMesh);
final Mesh orgInvisibleMesh = originalWall.invisibleMesh;
invisibleMesh = orgInvisibleMesh.makeCopy(true);
invisibleMesh.setUserData(new UserData(this, ((UserData) orgInvisibleMesh.getUserData()).getEditPointIndex(), false));
root.attachChild(invisibleMesh);
wallAndWindowsPoints = originalWall.wallAndWindowsPoints;
super.setOriginal(original);
}
Aggregations