use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.
the class ParabolicDish method init.
@Override
protected void init() {
super.init();
if (Util.isZero(copyLayoutGap)) {
// FIXME: Why is a transient member evaluated to zero?
copyLayoutGap = 0.2;
}
if (Util.isZero(rimRadius)) {
rimRadius = 3;
}
if (Util.isZero(focalLength)) {
focalLength = 2;
}
if (Util.isZero(reflectance)) {
reflectance = 0.9;
}
if (Util.isZero(absorptance)) {
absorptance = 0.95;
}
if (Util.isZero(opticalEfficiency)) {
opticalEfficiency = 0.7;
}
if (Util.isZero(thermalEfficiency)) {
thermalEfficiency = 0.3;
}
if (Util.isZero(nRadialSections)) {
nRadialSections = 32;
}
if (Util.isZero(nAxialSections)) {
nAxialSections = 32;
}
if (Util.isZero(nrib)) {
nrib = 6;
}
detailed = Scene.getInstance().countParts(getClass()) < 500;
final double annotationScale = Scene.getInstance().getAnnotationScale();
mesh = new Paraboloid("Paraboloid", rimRadius / annotationScale, 2.0 * Math.sqrt(focalLength / annotationScale), nAxialSections, nRadialSections);
mesh.setDefaultColor(SKY_BLUE);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
CullState cullState = new CullState();
cullState.setCullFace(Face.Front);
mesh.setRenderState(cullState);
root.attachChild(mesh);
dish = (Paraboloid) mesh;
dishBack = mesh.makeCopy(true);
dishBack.clearRenderState(StateType.Texture);
dishBack.setDefaultColor(ColorRGBA.LIGHT_GRAY);
cullState = new CullState();
cullState.setCullFace(Face.None);
dishBack.setRenderState(cullState);
root.attachChild(dishBack);
// if there are many dishes, reduce the solution of post
post = new Cylinder("Post Cylinder", 2, detailed ? 10 : 2, 10, 0);
post.setDefaultColor(ColorRGBA.WHITE);
post.setRadius(0.6);
post.setRenderState(offsetState);
post.setModelBound(new BoundingBox());
post.updateModelBound();
root.attachChild(post);
// if there are many mirrors, reduce the solution of post
duct = new Cylinder("Duct Cylinder", 2, detailed ? 10 : 2, 10, 0);
duct.setDefaultColor(ColorRGBA.WHITE);
duct.setRadius(0.6);
duct.setRenderState(offsetState);
duct.setModelBound(new BoundingBox());
duct.updateModelBound();
root.attachChild(duct);
final ColorRGBA receiverColor = new ColorRGBA(0.9f, 0.9f, 0.95f, 1);
// if there are many mirrors, reduce the solution of post
receiver = new Cylinder("Receiver Cylinder", 2, detailed ? 10 : 2, 10, 0, true);
receiver.setDefaultColor(receiverColor);
receiver.setRadius(2);
receiver.setHeight(3);
receiver.setRenderState(offsetState);
receiver.setModelBound(new BoundingBox());
receiver.updateModelBound();
root.attachChild(receiver);
outlines = new Line("Parabolic Dish (Outline)");
outlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(2 * (dish.getRSamples() + 1)));
outlines.setDefaultColor(ColorRGBA.BLACK);
outlines.setModelBound(new OrientedBoundingBox());
outlines.setLineWidth(1f);
outlines.setStipplePattern((short) 0xffff);
Util.disablePickShadowLight(outlines);
root.attachChild(outlines);
tripod = new Cylinder[3];
for (int i = 0; i < 3; i++) {
// if there are many mirrors, reduce the solution of post
tripod[i] = new Cylinder("Tripod Cylinder " + i, 2, detailed ? 10 : 2, 10, 0);
tripod[i].setDefaultColor(receiverColor);
tripod[i].setRadius(0.2);
tripod[i].setRenderState(offsetState);
tripod[i].setModelBound(new BoundingBox());
tripod[i].updateModelBound();
}
lightBeams = new Line("Light Beams");
lightBeams.setLineWidth(1f);
lightBeams.setStipplePattern((short) 0xffff);
lightBeams.setModelBound(null);
Util.disablePickShadowLight(lightBeams);
lightBeams.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(2));
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();
setStructureType(structureType);
if (!points.isEmpty()) {
oldDishCenter = points.get(0).clone();
}
}
use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.
the class ParabolicTrough method init.
@Override
protected void init() {
super.init();
if (Util.isZero(copyLayoutGap)) {
// FIXME: Why is a transient member evaluated to zero?
copyLayoutGap = 0.2;
}
if (Util.isZero(moduleLength)) {
moduleLength = 3;
}
if (Util.isZero(troughLength)) {
troughLength = 2 * moduleLength;
}
if (Util.isZero(apertureWidth)) {
apertureWidth = 2;
}
if (Util.isZero(semilatusRectum)) {
semilatusRectum = 2;
}
if (Util.isZero(reflectance)) {
reflectance = 0.9;
}
if (Util.isZero(absorptance)) {
absorptance = 0.95;
}
if (Util.isZero(opticalEfficiency)) {
opticalEfficiency = 0.7;
}
if (Util.isZero(thermalEfficiency)) {
thermalEfficiency = 0.3;
}
if (Util.isZero(nSectionParabola)) {
nSectionParabola = 16;
}
if (Util.isZero(nSectionAxis)) {
nSectionAxis = 32;
}
detailed = Scene.getInstance().countParts(this.getClass()) < 50;
mesh = new ParabolicCylinder("Parabolic Cylinder", nSectionParabola, semilatusRectum, apertureWidth, troughLength);
mesh.setDefaultColor(SKY_BLUE);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
CullState cullState = new CullState();
cullState.setCullFace(Face.Back);
mesh.setRenderState(cullState);
root.attachChild(mesh);
reflector = (ParabolicCylinder) mesh;
reflectorBack = mesh.makeCopy(true);
reflectorBack.clearRenderState(StateType.Texture);
reflectorBack.setDefaultColor(ColorRGBA.WHITE);
cullState = new CullState();
cullState.setCullFace(Face.None);
reflectorBack.setRenderState(cullState);
root.attachChild(reflectorBack);
final ColorRGBA tubeColor = new ColorRGBA(0.8f, 0.8f, 0.8f, 0.8f);
absorber = new Cylinder("Absorber Tube", 2, detailed ? 10 : 4, 0.5, 0, true);
final BlendState blend = new BlendState();
blend.setBlendEnabled(true);
absorber.setRenderState(blend);
absorber.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
absorber.setDefaultColor(tubeColor);
absorber.setModelBound(new OrientedBoundingBox());
root.attachChild(absorber);
absorberEnd1 = new Cylinder("Absorber End Tube 1", 2, detailed ? 10 : 4, 0.5, 0, true);
absorberEnd1.setRenderState(blend);
absorberEnd1.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
absorberEnd1.setDefaultColor(tubeColor);
absorberEnd1.setModelBound(new OrientedBoundingBox());
root.attachChild(absorberEnd1);
absorberEnd2 = new Cylinder("Absorber End Tube 2", 2, detailed ? 10 : 4, 0.5, 0, true);
absorberEnd2.setRenderState(blend);
absorberEnd2.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
absorberEnd2.setDefaultColor(tubeColor);
absorberEnd2.setModelBound(new OrientedBoundingBox());
root.attachChild(absorberEnd2);
if (detailed) {
absorberCore = new Cylinder("Absorber Tube Core", 2, 4, 0.4, 0, true);
absorberCore.setDefaultColor(ColorRGBA.BROWN);
absorberCore.setModelBound(new OrientedBoundingBox());
root.attachChild(absorberCore);
absorberEnd1Core = new Cylinder("Absorber End Tube 1 Core", 2, 4, 0.4, 0, true);
absorberEnd1Core.setDefaultColor(ColorRGBA.BROWN);
absorberEnd1Core.setModelBound(new OrientedBoundingBox());
root.attachChild(absorberEnd1Core);
absorberEnd2Core = new Cylinder("Absorber End Tube 2 Core", 2, 4, 0.4, 0, true);
absorberEnd2Core.setDefaultColor(ColorRGBA.BROWN);
absorberEnd2Core.setModelBound(new OrientedBoundingBox());
root.attachChild(absorberEnd2Core);
}
final int nModules = getNumberOfModules();
outlines = new Line("Parabolic Trough (Outline)");
outlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4 + 2 * (reflector.getNumberOfSamples() + 1) * (nModules + 1)));
outlines.setDefaultColor(ColorRGBA.BLACK);
outlines.setModelBound(new OrientedBoundingBox());
outlines.setLineWidth(1f);
outlines.setStipplePattern((short) 0xffff);
Util.disablePickShadowLight(outlines);
root.attachChild(outlines);
steelFrame = new Line("Parabolic Trough Steel Frame");
steelFrame.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
steelFrame.setDefaultColor(ColorRGBA.GRAY);
steelFrame.setModelBound(new OrientedBoundingBox());
steelFrame.setLineWidth(3);
steelFrame.setStipplePattern((short) 0xffff);
root.attachChild(steelFrame);
lightBeams = new Line("Light Beams");
lightBeams.setLineWidth(1f);
lightBeams.setStipplePattern((short) 0xffff);
lightBeams.setModelBound(null);
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);
modulesRoot = new Node("Modules Root");
root.attachChild(modulesRoot);
updateTextureAndColor();
if (!points.isEmpty()) {
oldTroughCenter = points.get(0).clone();
}
oldTroughLength = troughLength;
oldApertureWidth = apertureWidth;
}
use of com.ardor3d.bounding.OrientedBoundingBox in project energy3d by concord-consortium.
the class SolarPanel method isDrawable.
@Override
public boolean isDrawable() {
if (container == null) {
return true;
}
if (mesh.getWorldBound() == null) {
return true;
}
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart == null || selectedPart.isDrawCompleted()) {
// if nothing is really selected, skip overlap check
return true;
}
final OrientedBoundingBox bound = (OrientedBoundingBox) mesh.getWorldBound().clone(null);
bound.setExtent(bound.getExtent().divide(1.5, null).addLocal(0, 0, 1));
for (final HousePart child : container.getChildren()) {
if (child != this && child instanceof SolarPanel && bound.intersects(child.mesh.getWorldBound())) {
return false;
}
}
return true;
}
use of com.ardor3d.bounding.OrientedBoundingBox 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.bounding.OrientedBoundingBox in project energy3d by concord-consortium.
the class Util method drawBoundingBox.
public static void drawBoundingBox(final Spatial spatial, final Line boundingBox) {
OrientedBoundingBox box = null;
if (spatial instanceof Mesh) {
box = getOrientedBoundingBox((Mesh) spatial);
} else if (spatial instanceof Node) {
box = getOrientedBoundingBox((Node) spatial);
} else {
return;
}
FloatBuffer buf = boundingBox.getMeshData().getVertexBuffer();
if (buf == null || buf.capacity() != 24) {
buf = BufferUtils.createVector3Buffer(24);
boundingBox.getMeshData().setVertexBuffer(buf);
} else {
buf.rewind();
buf.limit(buf.capacity());
}
final ReadOnlyVector3 center = box.getCenter();
final ReadOnlyVector3 extent = box.getExtent();
final ReadOnlyVector3 vx = box.getXAxis().multiply(extent.getX(), null);
final ReadOnlyVector3 vy = box.getYAxis().multiply(extent.getY(), null);
final ReadOnlyVector3 vz = box.getZAxis().multiply(extent.getZ(), null);
double x, y, z;
// #1: (1, 1, 1) to (-1, 1, 1)
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #2: (1, 1, 1) to (1, -1, 1)
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #3: (1, 1, 1) to (1, 1, -1)
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #4: (-1, -1, -1) to (1, -1, -1)
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #5: (-1, -1, -1) to (-1, 1, -1)
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #6: (-1, -1, -1) to (-1, -1, 1)
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #7: (-1, 1, 1) to (-1, -1, 1)
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #8: (-1, 1, 1) to (-1, 1, -1)
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #9: (1, -1, 1) to (-1, -1, 1)
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #10: (1, -1, 1) to (1, -1, -1)
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() + vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #11: (1, 1, -1) to (-1, 1, -1)
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() - vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
// #12: (1, 1, -1) to (1, -1, -1)
x = center.getX() + vx.getX();
y = center.getY() + vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
x = center.getX() + vx.getX();
y = center.getY() - vy.getY();
z = center.getZ() - vz.getZ();
buf.put((float) x).put((float) y).put((float) z);
boundingBox.updateModelBound();
boundingBox.setVisible(true);
}
Aggregations