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();
}
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();
}
Aggregations