11package com .neuronrobotics .bowlerstudio .creature ;
22
33import java .util .ArrayList ;
4+ import java .util .HashMap ;
45import java .util .List ;
56
67import com .neuronrobotics .bowlerstudio .physics .TransformFactory ;
1112import eu .mihosoft .vrl .v3d .CSG ;
1213import eu .mihosoft .vrl .v3d .MissingManipulatorException ;
1314import eu .mihosoft .vrl .v3d .Vector3d ;
14- import eu .mihosoft .vrl .v3d .parametrics .CSGDatabase ;
1515import eu .mihosoft .vrl .v3d .parametrics .CSGDatabaseInstance ;
1616import javafx .scene .Group ;
1717import javafx .scene .Scene ;
2424import javafx .scene .shape .MeshView ;
2525import javafx .scene .transform .Transform ;
2626import javafx .scene .PerspectiveCamera ;
27- import javafx .embed .swing .SwingFXUtils ;
2827import javafx .scene .transform .Affine ;
29- import javafx .scene .transform .Rotate ;
30- import javafx .geometry .Rectangle2D ;
3128
3229public 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