Skip to content

Commit eef81fe

Browse files
committed
Make the thumbnail scene stable and reuse meshes that have not changed
1 parent f4f6992 commit eef81fe

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/creature/ThumbnailImage.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.neuronrobotics.bowlerstudio.creature;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
56

67
import com.neuronrobotics.bowlerstudio.physics.TransformFactory;
@@ -11,7 +12,6 @@
1112
import eu.mihosoft.vrl.v3d.CSG;
1213
import eu.mihosoft.vrl.v3d.MissingManipulatorException;
1314
import eu.mihosoft.vrl.v3d.Vector3d;
14-
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase;
1515
import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance;
1616
import javafx.scene.Group;
1717
import javafx.scene.Scene;
@@ -24,16 +24,17 @@
2424
import javafx.scene.shape.MeshView;
2525
import javafx.scene.transform.Transform;
2626
import javafx.scene.PerspectiveCamera;
27-
import javafx.embed.swing.SwingFXUtils;
2827
import javafx.scene.transform.Affine;
29-
import javafx.scene.transform.Rotate;
30-
import javafx.geometry.Rectangle2D;
3128

3229
public class ThumbnailImage {
33-
public static Bounds getSellectedBounds(List<CSG> incoming) {
30+
private HashMap<String,CSG> csgs=new HashMap<String, CSG>();
31+
private HashMap<String,MeshView> views = new HashMap<String, MeshView>();
32+
// Create a group to hold all the meshes
33+
private Group root = new Group();
34+
public Bounds getSellectedBounds() {
3435
Vector3d min = null;
3536
Vector3d max = null;
36-
for (CSG c : incoming) {
37+
for (CSG c : csgs.values()) {
3738
if(c.isHide())
3839
continue;
3940
if(c.isInGroup())
@@ -67,6 +68,9 @@ public static Bounds getSellectedBounds(List<CSG> incoming) {
6768
public WritableImage get(CSGDatabaseInstance instance,List<CSG> c) {
6869
ArrayList<CSG> csgList=new ArrayList<CSG>() ;
6970
for(CSG cs:c) {
71+
if (csgs.containsKey(cs.getName()))
72+
continue;
73+
csgs.put(cs.getName(), cs);
7074
if(cs.hasManipulator()) {
7175
TransformNR nr;
7276
try {
@@ -79,11 +83,26 @@ public WritableImage get(CSGDatabaseInstance instance,List<CSG> c) {
7983
}else
8084
csgList.add(cs);
8185
}
82-
// Create a group to hold all the meshes
83-
Group root = new Group();
86+
ArrayList<String> toRemove = new ArrayList<String>();
87+
for(String s:csgs.keySet()) {
88+
boolean exists=false;
89+
for(CSG cs:c) {
90+
if(cs.getName().contentEquals(s))
91+
exists=true;
92+
}
93+
if(!exists) {
94+
toRemove.add(s);
95+
}
96+
}
97+
for(String s:toRemove) {
98+
csgs.remove(s);
99+
MeshView mv = views.remove(s);
100+
root.getChildren().add(mv);
101+
}
102+
84103

85104
// Add all meshes to the group
86-
Bounds b = getSellectedBounds(csgList);
105+
Bounds b = getSellectedBounds();
87106

88107
double yOffset = (b.getMax().y-b.getMin().y)/2;
89108
double xOffset =(b.getMax().x -b.getMin().x)/2;
@@ -95,6 +114,7 @@ public WritableImage get(CSGDatabaseInstance instance,List<CSG> c) {
95114
continue;
96115
try {
97116
MeshView meshView = csg.movez(-zCenter).getMesh();
117+
views.put(csg.getName(), meshView);
98118
PhongMaterial material = new PhongMaterial();
99119
if (csg.isHole()) {
100120
material.setDiffuseColor(new Color(0.25, 0.25, 0.25, 0.75));

0 commit comments

Comments
 (0)