use of org.twak.tweed.ClickMe 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();
}
use of org.twak.tweed.ClickMe in project chordatlas by twak.
the class GreebleGrid method mb2Tex.
private Geometry mb2Tex(Output output, List<Face> chain, String name, String texture, Node node, ClickMe clickMe) {
Geometry geom;
{
MatMeshBuilder builder = mbs.get(name, texture);
geom = new Geometry("material_" + texture, builder.getMesh());
geom.setUserData(Jme3z.MAT_KEY, name);
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
if (new File(tweed.DATA + "/" + texture).exists())
mat.setTexture("DiffuseMap", tweed.getAssetManager().loadTexture(texture));
else {
System.out.println(this.getClass().getSimpleName() + " can't find " + tweed.SCRATCH + texture);
mat.setColor("Diffuse", ColorRGBA.Red);
}
mat.setColor("Ambient", ColorRGBA.White);
if (builder.normal != null)
mat.setTexture("NormalMap", tweed.getAssetManager().loadTexture(builder.normal));
// mat.setColor( "Ambient", ColorRGBA.Gray );
mat.setColor("Diffuse", ColorRGBA.White);
if (builder.spec != null)
mat.setTexture("SpecularMap", tweed.getAssetManager().loadTexture(builder.spec));
else
mat.setColor("Specular", ColorRGBA.White);
// mat.setFloat("Shininess", 6f);
mat.setBoolean("UseMaterialColors", true);
geom.setMaterial(mat);
geom.updateGeometricState();
geom.updateModelBound();
if (chain != null)
geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { clickMe });
}
return geom;
}
use of org.twak.tweed.ClickMe in project chordatlas by twak.
the class PlanesGen method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
for (Plane p : planes) {
p.color = color;
Spatial s = p.render(tweed);
if (s == null)
continue;
s.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {
@Override
public void clicked(Object data) {
selected(p);
}
} });
gNode.attachChild(s);
}
super.calculate();
}
use of org.twak.tweed.ClickMe in project chordatlas by twak.
the class GreebleSkel method createMesh.
public void createMesh(Output output) {
float[] roofColor = new float[] { 0.3f, 0.3f, 0.3f, 1 }, wallColor = new float[] { 228 / 255f, 223 / 255f, 206 / 255f, 1.0f };
if (output.faces == null)
return;
double bestWallArea = 0, bestRoofArea = 0;
for (Face f : output.faces.values()) {
double area = Loopz.area3(f.getLoopL());
Tag t = getTag(f.profile, RoofTag.class);
if (t != null && area > bestRoofArea && ((RoofTag) t).color != null) {
roofColor = ((RoofTag) t).color;
bestRoofArea = area;
}
t = getTag(f.profile, WallTag.class);
if (t != null && area > bestWallArea && ((WallTag) t).color != null) {
wallColor = ((WallTag) t).color;
bestWallArea = area;
}
}
greebleGrid = new GreebleGrid(tweed, mbs = new MMeshBuilderCache());
output.addNonSkeletonSharedEdges(new RoofTag(roofColor));
edges(output, roofColor);
for (List<Face> chain : Campz.findChains(output)) {
// for ( Face f : output.faces.values() )
// mbs.get(roofColor).add3d( Loopz.insertInnerEdges( f.getLoopL() ), zToYup );
Optional<Tag> opt = chain.stream().flatMap(f -> f.profile.stream()).filter(tag -> tag instanceof WallTag).findAny();
WallTag wt = null;
Set<QuadF> features = new HashSet<>();
MiniFacade mf = null;
if (opt.isPresent() && (wt = (WallTag) opt.get()).miniFacade != null) {
MiniFacade mf2 = new MiniFacade(wt.miniFacade);
Line facadeLine;
{
Edge e = chain.get(0).edge;
// we might rotate the facade to apply a set of features to a different side of the building.
facadeLine = new Line(e.end.x, e.end.y, e.start.x, e.start.y);
}
if (TweedSettings.settings.snapFacadeWidth) {
// move/scale mf horizontally from mean-image-location to mesh-facade-location
double[] meshSE = findSE(wt.miniFacade, facadeLine, chain);
mf2.scaleX(meshSE[0], meshSE[1]);
}
// find window locations in 3 space
mf2.rects.values().stream().flatMap(f -> f.stream()).map(r -> new QuadF(r, facadeLine)).forEach(q -> features.add(q));
mf = mf2;
}
for (Face f : chain) {
face(f, mf, features, roofColor, wallColor);
}
for (QuadF w : features) if ((w.original.f == Feature.WINDOW || w.original.f == Feature.SHOP) && w.foundAll()) {
greebleGrid.createDormerWindow(w, mbs.WOOD, mbs.GLASS, (float) wt.sillDepth, (float) wt.sillHeight, (float) wt.corniceHeight, 0.6, 0.9);
}
// for ( String mName : mbs.cache.keySet() )
// for (float[] mCol : mbs.cache.get( mName ).keySet() )
// node.attachChild( mb2Geom( output, chain, mName, mCol ) );
greebleGrid.attachAll(node, chain, output, new ClickMe() {
@Override
public void clicked(Object data) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
selected(output, node, findSuperEdge(output, chain));
}
});
} catch (Throwable th) {
th.printStackTrace();
}
}
});
}
}
use of org.twak.tweed.ClickMe in project chordatlas by twak.
the class LineGen3d method calculate.
@Override
public void calculate() {
for (Spatial s : gNode.getChildren()) s.removeFromParent();
{
Geometry geom;
Mesh m = new Mesh();
m.setMode(Mesh.Mode.Lines);
List<Float> coords = new ArrayList();
List<Integer> inds = new ArrayList();
for (Line3d l : getLines()) {
inds.add(inds.size());
inds.add(inds.size());
coords.add((float) l.start.x);
coords.add((float) l.start.y);
coords.add((float) l.start.z);
coords.add((float) l.end.x);
coords.add((float) l.end.y);
coords.add((float) l.end.z);
}
m.setBuffer(VertexBuffer.Type.Position, 3, Arrayz.toFloatArray(coords));
m.setBuffer(VertexBuffer.Type.Index, 2, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
Material lineMaterial = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
lineMaterial.setColor("Color", new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1f));
geom.setMaterial(lineMaterial);
geom.setLocalTranslation(0, 0, 0);
gNode.attachChild(geom);
}
// int c = 0;
VertexBuffer emptyVB = new VertexBuffer(Type.Index);
emptyVB.setupData(Usage.Static, 3, Format.UnsignedShort, BufferUtils.createShortBuffer(0));
{
Geometry geom;
Random randy = new Random();
for (Map.Entry<Loop<Point3d>, Integer> e : getFaces().entrySet()) {
Loop<Point3d> p = e.getKey();
final int callbackI = e.getValue();
Mesh m = Jme3z.fromLoop(p);
// m.setMode( Mesh.Mode.Triangles );
//
// List<Integer> inds = new ArrayList<>();
// List<Float> pos = new ArrayList<>();
// List<Float> norms = new ArrayList<>();
//
// Loopz.triangulate( p, true, inds, pos, norms );
//
// m.set setVe( Type.Index, Arrayz.toIntArray(inds));
geom = new Geometry(filename, m);
geom.setCullHint(CullHint.Never);
// ColorRGBA col = Jme3z.toJme( Rainbow.getColour( c++ ) );
ColorRGBA col = new ColorRGBA(color.getRed() * randy.nextFloat() / 500f + 0.1f, color.getGreen() * randy.nextFloat() / 500f + 0.1f, color.getBlue() * randy.nextFloat() / 500f + 0.1f, 1f);
Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setColor("Diffuse", col);
mat.setColor("Ambient", col);
mat.setBoolean("UseMaterialColors", true);
geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {
@Override
public void clicked(Object data) {
polyClicked(callbackI);
}
} });
geom.setUserData(Gen.class.getSimpleName(), new Object[] { this });
geom.setMaterial(mat);
geom.setLocalTranslation(0, 0, 0);
if (TweedSettings.settings.LOD) {
LodGenerator lod = new LodGenerator(geom);
lod.bakeLods(LodGenerator.TriangleReductionMethod.COLLAPSE_COST, 10, 100);
GISLodControl lc = new GISLodControl();
lc.setTrisPerPixel(0.000001f);
geom.addControl(lc);
}
gNode.attachChild(geom);
}
}
gNode.updateModelBound();
super.calculate();
}
Aggregations