Search in sources :

Example 1 with EventMoveHandle

use of org.twak.tweed.EventMoveHandle in project chordatlas by twak.

the class MiniGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    Material mat;
    if (transparency == 1)
        mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
    else {
        mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        mat.setColor("Color", new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, transparency));
    }
    for (Map.Entry<Integer, Matrix4d> e : trans.index.entrySet()) {
        if (!inBounds(e.getValue(), bounds))
            continue;
        File absRoot = Tweed.toWorkspace(MiniGen.this.root);
        System.out.println("loading mesh " + e.getKey() + " from " + absRoot);
        File f = new File(absRoot, e.getKey() + "/model.obj");
        Spatial mesh = tweed.getAssetManager().loadModel(tweed.makeWorkspaceRelative(f).toString());
        mesh.setLocalTransform(Jme3z.toJmeTransform(e.getValue()));
        Mode mode = renderLines ? Mesh.Mode.Lines : Mesh.Mode.Triangles;
        List<Spatial> ls;
        if (mesh instanceof Node)
            ls = ((Node) mesh).getChildren();
        else
            ls = Collections.singletonList(mesh);
        for (Spatial g : ls) {
            Geometry geometry = (Geometry) g;
            Mesh m = geometry.getMesh();
            m.setMode(mode);
            if (geometry.getMaterial().getName() == null)
                mesh.setMaterial(mat);
            gNode.attachChild(geometry);
            mesh.setUserData(Gen.class.getSimpleName(), new Object[] { this });
        }
    }
    Transform t = new Transform();
    t.fromTransformMatrix(trans.offset);
    gNode.setLocalTransform(t);
    gNode.setUserData(Gen.class.getSimpleName(), new Object[] { this });
    gNode.setUserData(HandleMe.class.getSimpleName(), true);
    gNode.setUserData(EventMoveHandle.class.getSimpleName(), new Object[] { new EventMoveHandle() {

        @Override
        public void posChanged() {
            MiniGen.this.save();
        }
    } });
    gNode.updateGeometricState();
    super.calculate();
}
Also used : EventMoveHandle(org.twak.tweed.EventMoveHandle) Mode(com.jme3.scene.Mesh.Mode) BlendMode(com.jme3.material.RenderState.BlendMode) Node(com.jme3.scene.Node) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Matrix4d(javax.vecmath.Matrix4d) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) HandleMe(org.twak.tweed.handles.HandleMe) MiniTransform(org.twak.readTrace.MiniTransform) Transform(com.jme3.math.Transform) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File)

Example 2 with EventMoveHandle

use of org.twak.tweed.EventMoveHandle in project chordatlas by twak.

the class PanoGen method calculate.

@Override
public void calculate() {
    File absFolder = Tweed.toWorkspace(PanoGen.this.folder);
    if (!absFolder.exists())
        throw new Error("File not found " + this.folder);
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    panos.clear();
    createPanoGens();
    Iterator<Pano> pit = panos.iterator();
    while (pit.hasNext()) {
        Pano p = pit.next();
        if (p.rx == 0 && Math.abs(p.rz - Mathz.TwoPI) < 1e-6)
            pit.remove();
    }
    Random randy = new Random(0xdeadbeef);
    for (Pano p : panos) {
        if (p.geom == null) {
            Box box1 = new Box(1f, 1f, 1f);
            p.geom = new Geometry("Box", box1);
            // p.geom.setUserData(Gen.class.getSimpleName(), new Object[]{this});
            p.geom.setUserData(EventMoveHandle.class.getSimpleName(), new Object[] { new EventMoveHandle() {

                @Override
                public void posChanged() {
                    p.location = new Vector3d(Jme3z.from(p.geom.getLocalTranslation()));
                    calculate();
                }
            } });
            // Material mat1 = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            ColorRGBA col = new ColorRGBA(color.getRed() * (0.2f + randy.nextFloat() * 0.8f) / 255f, color.getGreen() * (0.2f + randy.nextFloat() * 0.8f) / 255f, color.getBlue() * (0.2f + randy.nextFloat() * 0.8f) / 255f, 1f);
            Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
            mat.setColor("Diffuse", col);
            mat.setColor("Ambient", col);
            mat.setBoolean("UseMaterialColors", true);
            p.geom.setMaterial(mat);
        }
        p.geom.setLocalTranslation((float) p.location.x, (float) p.location.y, (float) p.location.z);
        p.geom.setLocalRotation(p.geomRot);
        p.geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {

            @Override
            public void clicked(Object data) {
                tweed.frame.setSelected(PanoGen.this);
                selected(p);
            }
        } });
        gNode.attachChild(p.geom);
    }
    super.calculate();
}
Also used : EventMoveHandle(org.twak.tweed.EventMoveHandle) ClickMe(org.twak.tweed.ClickMe) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) Random(java.util.Random) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3d(javax.vecmath.Vector3d) File(java.io.File)

Aggregations

Material (com.jme3.material.Material)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Geometry (com.jme3.scene.Geometry)2 Spatial (com.jme3.scene.Spatial)2 File (java.io.File)2 EventMoveHandle (org.twak.tweed.EventMoveHandle)2 BlendMode (com.jme3.material.RenderState.BlendMode)1 Transform (com.jme3.math.Transform)1 Mesh (com.jme3.scene.Mesh)1 Mode (com.jme3.scene.Mesh.Mode)1 Node (com.jme3.scene.Node)1 Box (com.jme3.scene.shape.Box)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 Matrix4d (javax.vecmath.Matrix4d)1 Vector3d (javax.vecmath.Vector3d)1 MiniTransform (org.twak.readTrace.MiniTransform)1 ClickMe (org.twak.tweed.ClickMe)1 HandleMe (org.twak.tweed.handles.HandleMe)1