|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright (c) 2009-2022 jMonkeyEngine
|
|
|
|
|
|
+ * Copyright (c) 2009-2023 jMonkeyEngine
|
|
* All rights reserved.
|
|
* All rights reserved.
|
|
*
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* Redistribution and use in source and binary forms, with or without
|
|
@@ -36,8 +36,10 @@ import com.jme3.plugins.json.JsonArray;
|
|
import com.jme3.plugins.json.JsonElement;
|
|
import com.jme3.plugins.json.JsonElement;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -51,14 +53,20 @@ public class CustomContentManager {
|
|
private GltfModelKey key;
|
|
private GltfModelKey key;
|
|
private GltfLoader gltfLoader;
|
|
private GltfLoader gltfLoader;
|
|
|
|
|
|
- private final Map<String, ExtensionLoader> defaultExtensionLoaders = new HashMap<>();
|
|
|
|
|
|
+
|
|
|
|
+ static final Map<String, Class<? extends ExtensionLoader>> defaultExtensionLoaders = new ConcurrentHashMap<>();
|
|
|
|
+ static {
|
|
|
|
+ defaultExtensionLoaders.put("KHR_materials_pbrSpecularGlossiness", PBRSpecGlossExtensionLoader.class);
|
|
|
|
+ defaultExtensionLoaders.put("KHR_lights_punctual", LightsPunctualExtensionLoader.class);
|
|
|
|
+ defaultExtensionLoaders.put("KHR_materials_unlit", UnlitExtensionLoader.class);
|
|
|
|
+ defaultExtensionLoaders.put("KHR_texture_transform", TextureTransformExtensionLoader.class);
|
|
|
|
+ defaultExtensionLoaders.put("KHR_materials_emissive_strength", PBREmissiveStrengthExtensionLoader.class);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private final Map<String, ExtensionLoader> loadedExtensionLoaders = new HashMap<>();
|
|
|
|
|
|
public CustomContentManager() {
|
|
public CustomContentManager() {
|
|
- defaultExtensionLoaders.put("KHR_materials_pbrSpecularGlossiness", new PBRSpecGlossExtensionLoader());
|
|
|
|
- defaultExtensionLoaders.put("KHR_lights_punctual", new LightsPunctualExtensionLoader());
|
|
|
|
- defaultExtensionLoaders.put("KHR_materials_unlit", new UnlitExtensionLoader());
|
|
|
|
- defaultExtensionLoaders.put("KHR_texture_transform", new TextureTransformExtensionLoader());
|
|
|
|
- defaultExtensionLoaders.put("KHR_materials_emissive_strength", new PBREmissiveStrengthExtensionLoader());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void init(GltfLoader gltfLoader) {
|
|
void init(GltfLoader gltfLoader) {
|
|
@@ -107,12 +115,29 @@ public class CustomContentManager {
|
|
|
|
|
|
for (Map.Entry<String, JsonElement> ext : extensions.getAsJsonObject().entrySet()) {
|
|
for (Map.Entry<String, JsonElement> ext : extensions.getAsJsonObject().entrySet()) {
|
|
ExtensionLoader loader = null;
|
|
ExtensionLoader loader = null;
|
|
|
|
+
|
|
if (key != null) {
|
|
if (key != null) {
|
|
loader = key.getExtensionLoader(ext.getKey());
|
|
loader = key.getExtensionLoader(ext.getKey());
|
|
}
|
|
}
|
|
|
|
+
|
|
if (loader == null) {
|
|
if (loader == null) {
|
|
- loader = defaultExtensionLoaders.get(ext.getKey());
|
|
|
|
|
|
+ loader = loadedExtensionLoaders.get(ext.getKey());
|
|
|
|
+ if (loader == null) {
|
|
|
|
+ try {
|
|
|
|
+ Class<? extends ExtensionLoader> clz = defaultExtensionLoaders.get(ext.getKey());
|
|
|
|
+ if (clz != null) {
|
|
|
|
+ loader = clz.getDeclaredConstructor().newInstance();
|
|
|
|
+ }
|
|
|
|
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
|
|
|
+ logger.log(Level.WARNING, "Could not instantiate loader", e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (loader != null) {
|
|
|
|
+ loadedExtensionLoaders.put(ext.getKey(), loader);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
if (loader == null) {
|
|
if (loader == null) {
|
|
logger.log(Level.WARNING, "Could not find loader for extension " + ext.getKey());
|
|
logger.log(Level.WARNING, "Could not find loader for extension " + ext.getKey());
|