use of com.ardor3d.bounding.BoundingBox 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.BoundingBox 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.BoundingBox in project energy3d by concord-consortium.
the class Tree method init.
@Override
protected void init() {
super.init();
switch(treeType) {
case COTTONWOOD:
treeWidth = 80;
treeHeight = 100;
break;
case LINDEN:
treeWidth = 90;
treeHeight = 120;
break;
case OAK:
treeWidth = 70;
treeHeight = 80;
break;
case ELM:
treeWidth = 60;
treeHeight = 75;
break;
case MAPLE:
treeWidth = 30;
treeHeight = 60;
break;
case PINE:
treeWidth = 30;
treeHeight = 80;
break;
default:
treeWidth = 30;
treeHeight = 40;
}
mesh = new Quad("Tree Quad", treeWidth, treeHeight);
mesh.setModelBound(new BoundingBox());
mesh.updateModelBound();
mesh.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
mesh.setTranslation(0, 0, treeHeight / 2.0);
mesh.getSceneHints().setPickingHint(PickingHint.Pickable, false);
final BlendState bs = new BlendState();
bs.setEnabled(true);
bs.setBlendEnabled(false);
bs.setTestEnabled(true);
bs.setTestFunction(TestFunction.GreaterThan);
bs.setReference(0.7f);
mesh.setRenderState(bs);
mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
billboard = new BillboardNode("Billboard");
billboard.setAlignment(BillboardAlignment.AxialZ);
billboard.attachChild(mesh);
root.attachChild(billboard);
switch(treeType) {
case PINE:
// axis samples, radial samples, radius, height, closed
crown = new Cone("Tree Crown", 2, 6, 18, 20, false);
break;
default:
// z samples, radial samples, radius
crown = new Sphere("Tree Crown", 4, 8, 14);
}
crown.setModelBound(new BoundingSphere());
crown.updateModelBound();
final Cylinder trunk = new Cylinder("Tree Trunk", 10, 10, 1, 20);
trunk.setModelBound(new BoundingBox());
trunk.updateModelBound();
switch(treeType) {
case COTTONWOOD:
crown.setScale(3, 3, 3.5);
crown.setTranslation(0, 0, 55);
trunk.setScale(8, 8, 2);
trunk.setTranslation(0, 0, 20);
break;
case LINDEN:
crown.setScale(3.5, 3.5, 4);
crown.setTranslation(0, 0, 65);
trunk.setScale(5, 5, 2);
trunk.setTranslation(0, 0, 20);
break;
case OAK:
crown.setScale(2.5, 2.5, 3);
crown.setTranslation(0, 0, 45);
trunk.setScale(5, 5, 2);
trunk.setTranslation(0, 0, 20);
break;
case ELM:
crown.setScale(2, 2, 2.5);
crown.setTranslation(0, 0, 40);
trunk.setScale(2, 2, 2);
trunk.setTranslation(0, 0, 20);
break;
case MAPLE:
crown.setScale(1, 1, 2.1);
crown.setTranslation(0, 0, 32);
trunk.setTranslation(0, 0, 10);
break;
case PINE:
crown.setScale(1, 1, -4.0);
crown.setTranslation(0, 0, 45);
trunk.setTranslation(0, 0, 10);
break;
default:
crown.setScale(1, 1, 1.2);
crown.setTranslation(0, 0, 24);
trunk.setTranslation(0, 0, 10);
break;
}
collisionRoot = new Node("Tree Collision Root");
collisionRoot.attachChild(crown);
collisionRoot.attachChild(trunk);
if (points.size() > 0) {
collisionRoot.setTranslation(getAbsPoint(0));
}
collisionRoot.updateWorldTransform(true);
collisionRoot.updateWorldBound(true);
collisionRoot.getSceneHints().setCullHint(showPolygons ? CullHint.Never : CullHint.Always);
root.attachChild(collisionRoot);
crown.setUserData(new UserData(this));
trunk.setUserData(new UserData(this));
updateTextureAndColor();
}
use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.
the class MeshLib method createMeshes.
public static void createMeshes(final Node root, final ArrayList<GroupData> groups) {
if (groups.size() != root.getNumberOfChildren()) {
root.detachAllChildren();
}
int meshIndex = 0;
for (final GroupData group : groups) {
final Node node;
final Mesh mesh;
final Mesh meshWithHoles;
final BMText label;
if (meshIndex < root.getNumberOfChildren()) {
node = (Node) root.getChild(meshIndex);
mesh = (Mesh) node.getChild(0);
label = (BMText) node.getChild(3);
meshWithHoles = (Mesh) node.getChild(6);
node.getSceneHints().setAllPickingHints(true);
} else {
node = new Node("Roof Part #" + meshIndex);
mesh = new Mesh("Roof Mesh #" + meshIndex);
meshWithHoles = new Mesh("Roof Mesh with Holes #" + meshIndex);
mesh.setVisible(false);
mesh.setModelBound(new BoundingBox());
meshWithHoles.setModelBound(new BoundingBox());
meshWithHoles.setRenderState(HousePart.offsetState);
label = new BMText("Label Text", "", FontManager.getInstance().getPartNumberFont(), Align.South, Justify.Center);
Util.initHousePartLabel(label);
final Mesh wireframeMesh = new Line("Roof (wireframe)");
wireframeMesh.setDefaultColor(ColorRGBA.BLACK);
wireframeMesh.setModelBound(new BoundingBox());
wireframeMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(10));
// offset to avoid z-fighting
wireframeMesh.setTranslation(group.key.multiply(0.001, null));
final Line dashLineMesh = new Line("Roof (dash line)");
dashLineMesh.setStipplePattern((short) 0xFF00);
dashLineMesh.setVisible(false);
dashLineMesh.setModelBound(new BoundingBox());
final Node sizeAnnotation = new Node("Roof Size Annot");
final Node angleAnnotation = new Node("Roof Angle Annot");
// disable picking for all except mesh
Util.disablePickShadowLight(sizeAnnotation);
Util.disablePickShadowLight(angleAnnotation);
Util.disablePickShadowLight(wireframeMesh);
Util.disablePickShadowLight(dashLineMesh);
// meshWithHoles.getSceneHints().setAllPickingHints(false);
node.attachChild(mesh);
node.attachChild(sizeAnnotation);
node.attachChild(angleAnnotation);
node.attachChild(label);
node.attachChild(wireframeMesh);
node.attachChild(dashLineMesh);
node.attachChild(meshWithHoles);
root.attachChild(node);
}
node.getSceneHints().setCullHint(CullHint.Never);
CollisionTreeManager.getInstance().removeCollisionTree(mesh);
CollisionTreeManager.getInstance().removeCollisionTree(meshWithHoles);
final Vector3 normal = group.key;
node.setUserData(normal);
final FloatBuffer buf = BufferUtils.createVector3Buffer(group.vertices.size());
mesh.getMeshData().setVertexBuffer(buf);
final Vector3 center = new Vector3();
for (final ReadOnlyVector3 v : group.vertices) {
buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
center.addLocal(v);
}
center.multiplyLocal(1.0 / group.vertices.size());
label.setTranslation(center.add(normal.multiply(0.1, null), null));
mesh.updateModelBound();
meshIndex++;
}
}
use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.
the class SceneManager method drawGrids.
public Mesh drawGrids(final double gridSize) {
final Mesh gridsMesh = new Line("Ground Grids");
gridsMesh.getSceneHints().setCullHint(CullHint.Always);
gridsMesh.setDefaultColor(new ColorRGBA(0, 0, 1, 1));
final BlendState blendState = new BlendState();
blendState.setBlendEnabled(true);
gridsMesh.setRenderState(blendState);
gridsMesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
final ReadOnlyVector3 width = Vector3.UNIT_X.multiply(2000, null);
final ReadOnlyVector3 height = Vector3.UNIT_Y.multiply(2000, null);
final ArrayList<ReadOnlyVector3> points = new ArrayList<ReadOnlyVector3>();
final ReadOnlyVector3 pMiddle = Vector3.ZERO;
final int cols = (int) (width.length() / gridSize);
for (int col = 1; col < cols / 2 + 1; col++) {
for (int neg = -1; neg <= 1; neg += 2) {
final ReadOnlyVector3 lineP1 = width.normalize(null).multiplyLocal(neg * col * gridSize).addLocal(pMiddle).subtractLocal(height.multiply(0.5, null));
points.add(lineP1);
final ReadOnlyVector3 lineP2 = lineP1.add(height, null);
points.add(lineP2);
if (col == 0) {
break;
}
}
}
final int rows = (int) (height.length() / gridSize);
for (int row = 1; row < rows / 2 + 1; row++) {
for (int neg = -1; neg <= 1; neg += 2) {
final ReadOnlyVector3 lineP1 = height.normalize(null).multiplyLocal(neg * row * gridSize).addLocal(pMiddle).subtractLocal(width.multiply(0.5, null));
points.add(lineP1);
final ReadOnlyVector3 lineP2 = lineP1.add(width, null);
points.add(lineP2);
if (row == 0) {
break;
}
}
}
final FloatBuffer buf = BufferUtils.createVector3Buffer(points.size());
for (final ReadOnlyVector3 p : points) {
buf.put(p.getXf()).put(p.getYf()).put(0.01f);
}
gridsMesh.getMeshData().setVertexBuffer(buf);
gridsMesh.getMeshData().updateVertexCount();
Util.disablePickShadowLight(gridsMesh);
gridsMesh.setModelBound(new BoundingBox());
gridsMesh.updateModelBound();
gridsMesh.updateWorldBound(true);
return gridsMesh;
}
Aggregations