|
@@ -220,6 +220,32 @@ public class SpatialUtil {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates material of existing objects from an original file.
|
|
|
+ *
|
|
|
+ * @param root
|
|
|
+ * @param original
|
|
|
+ */
|
|
|
+ public static void updateMaterialDataFromOriginal(final Spatial root,
|
|
|
+ final Spatial original) {
|
|
|
+ //loop through original to also find new geometry
|
|
|
+ original.depthFirstTraversal(new SceneGraphVisitorAdapter() {
|
|
|
+ @Override
|
|
|
+ public void visit(Geometry geom) {
|
|
|
+ //will always return same class type as 2nd param, so casting is safe
|
|
|
+ Geometry spat = (Geometry) findTaggedSpatial(root, geom);
|
|
|
+ if (spat != null && spat.getMaterial() != null
|
|
|
+ && geom.getMaterial() != null
|
|
|
+ && !spat.getMaterial().equals(geom.getMaterial())) {
|
|
|
+ spat.setMaterial(geom.getMaterial().clone());
|
|
|
+ logger.log(LogLevel.USERINFO,
|
|
|
+ "Updated material for Geometry {0}", geom.getName()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Adds a leaf to a spatial, including all nonexisting parents.
|
|
|
*
|
|
@@ -241,6 +267,10 @@ public class SpatialUtil {
|
|
|
logger.log(Level.INFO, "Attaching {0} to {1} in root {2} to add leaf {3}", new Object[]{s, other, root, leaf});
|
|
|
//set original path data to leaf and new parents
|
|
|
for (Spatial spt = leaf; spt != parent; spt = spt.getParent()) {
|
|
|
+ if (spt == null) {
|
|
|
+ // this is to avoid a crash when changing mesh names
|
|
|
+ return;
|
|
|
+ }
|
|
|
spt.setUserData(ORIGINAL_NAME, spt.getName());
|
|
|
spt.setUserData(ORIGINAL_PATH, getSpatialPath(spt));
|
|
|
spt = spt.getParent();
|