Search in sources :

Example 6 with Mesh

use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.

the class FoundationPolygon method setPreviewPoint.

@Override
public void setPreviewPoint(final int x, final int y) {
    final PickedHousePart pick = SelectUtil.pickPart(x, y, container);
    Vector3 p;
    if (pick != null) {
        p = pick.getPoint().clone();
        p.setZ(container.getHeight());
        final Vector3 relativeP = toRelative(p);
        final int n = points.size() / 2;
        if (editPointIndex < n) {
            points.get(editPointIndex).set(relativeP);
        } else {
            if (SelectUtil.getCurrentEditPointMesh() != null) {
                SelectUtil.getCurrentEditPointMesh().setDefaultColor(ColorRGBA.WHITE);
            }
            editPointIndex -= n;
            final Mesh editPointShape = getEditPointShape(editPointIndex);
            SelectUtil.setCurrentEditPointMesh(editPointShape);
            editPointShape.setDefaultColor(ColorRGBA.RED);
            points.add(editPointIndex, relativeP);
            points.add(new Vector3());
            setEditPointsVisible(true);
        }
        draw();
    }
}
Also used : Mesh(com.ardor3d.scenegraph.Mesh) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 7 with Mesh

use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.

the class HousePart method addPrintMesh.

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();
        material.setDiffuse(mesh.getDefaultColor());
        newMesh.setRenderState(material);
        newMesh.getMeshData().transformVertices((Transform) mesh.getWorldTransform());
        newMesh.getMeshData().transformNormals((Transform) mesh.getWorldTransform(), true);
        list.add(newMesh);
    }
}
Also used : Mesh(com.ardor3d.scenegraph.Mesh) MaterialState(com.ardor3d.renderer.state.MaterialState)

Example 8 with Mesh

use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.

the class FresnelReflector 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(length)) {
        length = 2 * moduleLength;
    }
    if (Util.isZero(moduleWidth)) {
        moduleWidth = 2;
    }
    if (Util.isZero(reflectance)) {
        reflectance = 0.9;
    }
    if (Util.isZero(opticalEfficiency)) {
        opticalEfficiency = 0.99;
    }
    if (Util.isZero(nSectionLength)) {
        nSectionLength = 16;
    }
    if (Util.isZero(nSectionWidth)) {
        nSectionWidth = 4;
    }
    detailed = Scene.getInstance().countParts(this.getClass()) < 50;
    if (absorber != null) {
        // FIXME: Somehow the absorber foundation, when copied, doesn't point to the right object. This is not a prefect solution, but it fixes the problem.
        absorber = (Foundation) Scene.getInstance().getPart(absorber.getId());
    }
    mesh = new Mesh("Fresnel Reflector Face");
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
    mesh.setDefaultColor(SKY_BLUE);
    mesh.setModelBound(new OrientedBoundingBox());
    mesh.setUserData(new UserData(this));
    root.attachChild(mesh);
    reflector = new Box("Fresnel Reflector Box");
    reflector.setModelBound(new OrientedBoundingBox());
    final OffsetState offset = new OffsetState();
    offset.setFactor(1);
    offset.setUnits(1);
    reflector.setRenderState(offset);
    root.attachChild(reflector);
    final int nModules = Math.max(1, getNumberOfModules());
    outlines = new Line("Fresnel Reflector (Outline)");
    outlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8 + (nModules - 1) * 2));
    outlines.setDefaultColor(ColorRGBA.BLACK);
    outlines.setModelBound(new OrientedBoundingBox());
    outlines.setLineWidth(1f);
    outlines.setStipplePattern((short) 0xffff);
    Util.disablePickShadowLight(outlines);
    root.attachChild(outlines);
    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()) {
        oldReflectorCenter = points.get(0).clone();
    }
    oldLength = length;
    oldModuleWidth = moduleWidth;
}
Also used : Line(com.ardor3d.scenegraph.Line) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) OffsetState(com.ardor3d.renderer.state.OffsetState) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 9 with Mesh

use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.

the class Scene method exportObj.

public void exportObj(final File file) throws Exception {
    try {
        final List<Mesh> objs = new ArrayList<Mesh>();
        for (final HousePart part : parts) {
            part.addPrintMeshes(objs);
        }
        final Quaternion rotate = new Quaternion(-1, 0, 0, 1);
        for (final Mesh mesh : objs) {
            mesh.getMeshData().rotatePoints(rotate);
            if (mesh.getMeshData().getNormalBuffer() != null) {
                mesh.getMeshData().rotateNormals(rotate);
            }
            mesh.updateModelBound();
        }
        final String s = file.toString();
        new ObjExporter().save(objs, new File(s), new File(s.substring(0, s.lastIndexOf(".")) + ".mtl"), null);
    } catch (final Throwable t) {
        BugReporter.report(t);
    }
}
Also used : Quaternion(com.ardor3d.math.Quaternion) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) ObjExporter(com.ardor3d.extension.model.obj.ObjExporter) File(java.io.File) HousePart(org.concord.energy3d.model.HousePart)

Example 10 with Mesh

use of com.ardor3d.scenegraph.Mesh in project energy3d by concord-consortium.

the class Scene method applyGroundImage.

private void applyGroundImage() {
    final Mesh mesh = SceneManager.getInstance().getGroundImageLand();
    if (groundImage == null) {
        // set a dummy texture in case the mesh holds the original buffered image and causes memory leak
        mesh.setRenderState(new TextureState());
        mesh.setVisible(false);
        setFoundationsVisible(true);
    } else {
        SceneManager.getInstance().resizeGroundImageLand(groundImageScale);
        final Texture2D texture = new Texture2D();
        texture.setTextureKey(TextureKey.getRTTKey(MinificationFilter.NearestNeighborNoMipMaps));
        texture.setImage(AWTImageLoader.makeArdor3dImage(groundImage, true));
        final TextureState textureState = new TextureState();
        textureState.setTexture(texture);
        mesh.setRenderState(textureState);
        mesh.setVisible(!hideGroundImage);
        setFoundationsVisible(false);
    }
}
Also used : Texture2D(com.ardor3d.image.Texture2D) TextureState(com.ardor3d.renderer.state.TextureState) Mesh(com.ardor3d.scenegraph.Mesh)

Aggregations

Mesh (com.ardor3d.scenegraph.Mesh)69 Spatial (com.ardor3d.scenegraph.Spatial)36 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)33 Node (com.ardor3d.scenegraph.Node)31 CullHint (com.ardor3d.scenegraph.hint.CullHint)28 Vector3 (com.ardor3d.math.Vector3)25 FloatBuffer (java.nio.FloatBuffer)18 TPoint (org.poly2tri.triangulation.point.TPoint)16 Line (com.ardor3d.scenegraph.Line)15 ArrayList (java.util.ArrayList)15 BoundingBox (com.ardor3d.bounding.BoundingBox)12 Point (org.poly2tri.geometry.primitives.Point)12 HousePart (org.concord.energy3d.model.HousePart)11 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)10 PickResults (com.ardor3d.intersection.PickResults)10 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)10 Ray3 (com.ardor3d.math.Ray3)10 Foundation (org.concord.energy3d.model.Foundation)10 ColorRGBA (com.ardor3d.math.ColorRGBA)8 Calendar (java.util.Calendar)8