From 202a4451274540febde059e5eb26e1327815ea61 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 4 Dec 2016 21:11:48 +1300 Subject: ObjFile can now have an Appearance constructor method overriden to supply for example a ShaderAppearance --- .../org/jogamp/java3d/loaders/objectfile/ObjectFile.java | 15 +++++++++++++-- .../java3d/loaders/objectfile/ObjectFileMaterials.java | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFile.java b/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFile.java index abbc2e4..5b54ab7 100644 --- a/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFile.java +++ b/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFile.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import org.jogamp.java3d.Appearance; import org.jogamp.java3d.BranchGroup; import org.jogamp.java3d.Shape3D; import org.jogamp.vecmath.Point3f; @@ -1180,12 +1181,11 @@ public class ObjectFile implements Loader { // Put geometry into Shape3d Shape3D shape = new Shape3D(); - // issue 638; default to BY_COPY for consistency //PJ: gl2es2 requires by ref, and nio is much faster shape.setGeometry(gi.getGeometryArray(true, false, true)); String matName = (String)groupMaterials.get(curname); - materials.assignMaterial(matName, shape); + materials.assignMaterial(matName, shape, createAppearance()); group.addChild(shape); scene.addNamedObject(curname, shape); @@ -1203,6 +1203,17 @@ public class ObjectFile implements Loader { /** + * Override to provide a custom appearance, for example + * a ShaderAppearance with shaders + * @return + */ + public Appearance createAppearance() + { + return new Appearance(); + } + + + /** * The Object File is loaded from the already opened file. * To attach the model to your scene, call getSceneGroup() on * the Scene object passed back, and attach the returned diff --git a/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFileMaterials.java b/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFileMaterials.java index 09c3660..0645071 100644 --- a/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFileMaterials.java +++ b/src/main/java/org/jogamp/java3d/loaders/objectfile/ObjectFileMaterials.java @@ -98,14 +98,14 @@ class ObjectFileMaterials implements ImageObserver { } - void assignMaterial(String matName, Shape3D shape) { + void assignMaterial(String matName, Shape3D shape, Appearance a) { ObjectFileMaterial p = null; if ((DEBUG & 1) != 0) System.out.println("Color " + matName); Material m = new Material(); p = (ObjectFileMaterial)materials.get(matName); - Appearance a = new Appearance(); + if (p != null) { // Set ambient & diffuse color -- cgit v1.2.3