diff --git a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/GltfModelBuilder.java b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/GltfModelBuilder.java index 51271a6f..f35fcddf 100644 --- a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/GltfModelBuilder.java +++ b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/GltfModelBuilder.java @@ -45,6 +45,7 @@ import de.javagl.jgltf.model.MeshModel; import de.javagl.jgltf.model.MeshPrimitiveModel; import de.javagl.jgltf.model.NodeModel; +import de.javagl.jgltf.model.PbrMaterialModel; import de.javagl.jgltf.model.SceneModel; import de.javagl.jgltf.model.SkinModel; import de.javagl.jgltf.model.TextureModel; @@ -65,12 +66,11 @@ import de.javagl.jgltf.model.impl.DefaultNodeModel; import de.javagl.jgltf.model.impl.DefaultSceneModel; import de.javagl.jgltf.model.impl.DefaultSkinModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.jgltf.model.impl.DefaultTextureModel; import de.javagl.jgltf.model.structure.BufferBuilderStrategies; import de.javagl.jgltf.model.structure.BufferBuilderStrategy; import de.javagl.jgltf.model.v1.GltfModelV1; -import de.javagl.jgltf.model.v1.MaterialModelV1; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A class for building {@link GltfModel} instances.
@@ -387,10 +387,10 @@ public void addMaterialModel(MaterialModel materialModel) boolean added = materialModelsSet.add(materialModel); if (added) { - if (materialModel instanceof MaterialModelV1) + if (materialModel instanceof DefaultTechniqueMaterialModel) { - MaterialModelV1 materialModelV1 = - (MaterialModelV1)materialModel; + DefaultTechniqueMaterialModel materialModelV1 = + (DefaultTechniqueMaterialModel)materialModel; addTechniqueModel(materialModelV1.getTechniqueModel()); @@ -404,15 +404,15 @@ public void addMaterialModel(MaterialModel materialModel) } } } - if (materialModel instanceof MaterialModelV2) + if (materialModel instanceof PbrMaterialModel) { - MaterialModelV2 materialModelV2 = - (MaterialModelV2)materialModel; - addTextureModel(materialModelV2.getBaseColorTexture()); - addTextureModel(materialModelV2.getOcclusionTexture()); - addTextureModel(materialModelV2.getMetallicRoughnessTexture()); - addTextureModel(materialModelV2.getEmissiveTexture()); - addTextureModel(materialModelV2.getNormalTexture()); + PbrMaterialModel pbrMaterialModel = + (PbrMaterialModel)materialModel; + addTextureModel(pbrMaterialModel.getBaseColorTexture()); + addTextureModel(pbrMaterialModel.getOcclusionTexture()); + addTextureModel(pbrMaterialModel.getMetallicRoughnessTexture()); + addTextureModel(pbrMaterialModel.getEmissiveTexture()); + addTextureModel(pbrMaterialModel.getNormalTexture()); } } } diff --git a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialBuilder.java b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialBuilder.java index 181af698..c2a0249f 100644 --- a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialBuilder.java +++ b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialBuilder.java @@ -27,12 +27,16 @@ package de.javagl.jgltf.model.creation; import de.javagl.jgltf.model.ImageModel; +import de.javagl.jgltf.model.PbrMaterialModel.AlphaMode; import de.javagl.jgltf.model.TextureModel; -import de.javagl.jgltf.model.v2.MaterialModelV2; -import de.javagl.jgltf.model.v2.MaterialModelV2.AlphaMode; +import de.javagl.jgltf.model.impl.DefaultNormalTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultOcclusionTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; +import de.javagl.jgltf.model.impl.DefaultPbrMetallicRoughnessModel; +import de.javagl.jgltf.model.impl.DefaultTextureInfoModel; /** - * A class for building {@link MaterialModelV2} instances + * A class for building {@link DefaultPbrMaterialModel} instances */ public class MaterialBuilder { @@ -47,16 +51,22 @@ public static MaterialBuilder create() } /** - * The {@link MaterialModelV2} that is currently being built + * The {@link DefaultPbrMaterialModel} that is currently being built */ - private MaterialModelV2 materialModel; + private DefaultPbrMaterialModel materialModel; + + /** + * The {@link DefaultPbrMetallicRoughnessModel} + */ + private DefaultPbrMetallicRoughnessModel metallicRoughnessModel; /** * Private constructor */ private MaterialBuilder() { - materialModel = new MaterialModelV2(); + materialModel = new DefaultPbrMaterialModel(); + metallicRoughnessModel = new DefaultPbrMetallicRoughnessModel(); } /** @@ -71,7 +81,8 @@ private MaterialBuilder() public MaterialBuilder setBaseColorFactor( double r, double g, double b, double a) { - materialModel.setBaseColorFactor(new double[] { r, g, b, a }); + metallicRoughnessModel.setBaseColorFactor(new double[] { r, g, b, a }); + materialModel.setPbrMetallicRoughnessModel(metallicRoughnessModel); return this; } @@ -102,8 +113,11 @@ public MaterialBuilder setBaseColorTexture( public MaterialBuilder setBaseColorTexture( TextureModel baseColorTexture, Integer texCoord) { - materialModel.setBaseColorTexture(baseColorTexture); - materialModel.setBaseColorTexcoord(texCoord); + DefaultTextureInfoModel textureInfo = new DefaultTextureInfoModel(); + textureInfo.setTextureModel(baseColorTexture); + textureInfo.setTexCoord(texCoord); + metallicRoughnessModel.setBaseColorTexture(textureInfo); + materialModel.setPbrMetallicRoughnessModel(metallicRoughnessModel); return this; } @@ -117,8 +131,9 @@ public MaterialBuilder setBaseColorTexture( public MaterialBuilder setMetallicRoughnessFactors( double metallicFactor, double roughnessFactor) { - materialModel.setMetallicFactor(metallicFactor); - materialModel.setRoughnessFactor(roughnessFactor); + metallicRoughnessModel.setMetallicFactor(metallicFactor); + metallicRoughnessModel.setRoughnessFactor(roughnessFactor); + materialModel.setPbrMetallicRoughnessModel(metallicRoughnessModel); return this; } @@ -149,8 +164,11 @@ public MaterialBuilder setMetallicRoughnessTexture( public MaterialBuilder setMetallicRoughnessTexture( TextureModel metallicRoughnessTexture, Integer texCoord) { - materialModel.setMetallicRoughnessTexture(metallicRoughnessTexture); - materialModel.setMetallicRoughnessTexcoord(texCoord); + DefaultTextureInfoModel textureInfo = new DefaultTextureInfoModel(); + textureInfo.setTextureModel(metallicRoughnessTexture); + textureInfo.setTexCoord(texCoord); + metallicRoughnessModel.setMetallicRoughnessTextureInfo(textureInfo); + materialModel.setPbrMetallicRoughnessModel(metallicRoughnessModel); return this; } @@ -184,9 +202,12 @@ public MaterialBuilder setNormalTexture( public MaterialBuilder setNormalTexture( TextureModel normalTexture, double scale, Integer texCoord) { - materialModel.setNormalTexture(normalTexture); - materialModel.setNormalScale(scale); - materialModel.setNormalTexcoord(texCoord); + DefaultNormalTextureInfoModel textureInfo = + new DefaultNormalTextureInfoModel(); + textureInfo.setTextureModel(normalTexture); + textureInfo.setTexCoord(texCoord); + textureInfo.setScale(scale); + materialModel.setNormalTextureInfoModel(textureInfo); return this; } @@ -220,9 +241,12 @@ public MaterialBuilder setOcclusionTexture( public MaterialBuilder setOcclusionTexture( TextureModel occlusionTexture, double strength, Integer texCoord) { - materialModel.setOcclusionTexture(occlusionTexture); - materialModel.setOcclusionStrength(strength); - materialModel.setOcclusionTexcoord(texCoord); + DefaultOcclusionTextureInfoModel textureInfo = + new DefaultOcclusionTextureInfoModel(); + textureInfo.setTextureModel(occlusionTexture); + textureInfo.setTexCoord(texCoord); + textureInfo.setStrength(strength); + materialModel.setOcclusionTextureInfoModel(textureInfo); return this; } @@ -260,9 +284,12 @@ public MaterialBuilder setEmissiveTexture( public MaterialBuilder setEmissiveTexture(TextureModel emissiveTexture, double r, double g, double b, Integer texCoord) { - materialModel.setEmissiveTexture(emissiveTexture); + DefaultTextureInfoModel textureInfo = + new DefaultTextureInfoModel(); + textureInfo.setTextureModel(emissiveTexture); + textureInfo.setTexCoord(texCoord); + materialModel.setEmissiveTextureInfoModel(textureInfo); materialModel.setEmissiveFactor(new double[] { r, g, b }); - materialModel.setEmissiveTexcoord(texCoord); return this; } @@ -303,14 +330,15 @@ public MaterialBuilder setDoubleSided(boolean doubleSided) } /** - * Create the {@link MaterialModelV2} instance with the current state + * Create the {@link DefaultPbrMaterialModel} instance with the current state * - * @return The {@link MaterialModelV2} + * @return The {@link DefaultPbrMaterialModel} */ - public MaterialModelV2 build() + public DefaultPbrMaterialModel build() { - MaterialModelV2 result = materialModel; - materialModel = new MaterialModelV2(); + DefaultPbrMaterialModel result = materialModel; + materialModel = new DefaultPbrMaterialModel(); + metallicRoughnessModel = new DefaultPbrMetallicRoughnessModel(); return result; } } diff --git a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialModels.java b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialModels.java index 4ff785bf..44288967 100644 --- a/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialModels.java +++ b/jgltf-model-builder/src/main/java/de/javagl/jgltf/model/creation/MaterialModels.java @@ -30,8 +30,8 @@ import de.javagl.jgltf.model.MaterialModel; import de.javagl.jgltf.model.TextureModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.impl.DefaultTextureModel; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * Methods related to {@link MaterialModel} instances @@ -48,14 +48,14 @@ public class MaterialModels * @param a The alpha component * @return The material model */ - public static MaterialModelV2 createFromBaseColor( + public static DefaultPbrMaterialModel createFromBaseColor( double r, double g, double b, double a) { MaterialBuilder builder = MaterialBuilder.create(); builder.setBaseColorFactor(r, g, b, a); builder.setDoubleSided(true); builder.setMetallicRoughnessFactors(0.0, 1.0); - MaterialModelV2 result = builder.build(); + DefaultPbrMaterialModel result = builder.build(); return result; } @@ -67,14 +67,14 @@ public static MaterialModelV2 createFromBaseColor( * @param texCoord The optional texture coordinate index * @return The material model */ - public static MaterialModelV2 createFromBaseColorTexture( + public static DefaultPbrMaterialModel createFromBaseColorTexture( TextureModel baseColorTexture, Integer texCoord) { MaterialBuilder builder = MaterialBuilder.create(); builder.setBaseColorTexture(baseColorTexture, texCoord); builder.setDoubleSided(true); builder.setMetallicRoughnessFactors(0.0, 1.0); - MaterialModelV2 result = builder.build(); + DefaultPbrMaterialModel result = builder.build(); return result; } @@ -87,14 +87,14 @@ public static MaterialModelV2 createFromBaseColorTexture( * @param uri The URI for the image * @return The material model */ - public static MaterialModelV2 createFromImageFile( + public static DefaultPbrMaterialModel createFromImageFile( String imageFileName, String uri) { MaterialBuilder builder = MaterialBuilder.create(); builder.setBaseColorTexture(imageFileName, uri, null); builder.setDoubleSided(true); builder.setMetallicRoughnessFactors(0.0, 1.0); - MaterialModelV2 result = builder.build(); + DefaultPbrMaterialModel result = builder.build(); return result; } @@ -108,7 +108,7 @@ public static MaterialModelV2 createFromImageFile( * @param mimeType The MIME type of the image * @return The material model */ - public static MaterialModelV2 createFromBufferedImage( + public static DefaultPbrMaterialModel createFromBufferedImage( BufferedImage bufferedImage, String uri, String mimeType) { DefaultTextureModel baseColorTexture = @@ -117,7 +117,7 @@ public static MaterialModelV2 createFromBufferedImage( builder.setBaseColorTexture(baseColorTexture, null); builder.setDoubleSided(true); builder.setMetallicRoughnessFactors(0.0, 1.0); - MaterialModelV2 result = builder.build(); + DefaultPbrMaterialModel result = builder.build(); return result; } diff --git a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationBasicExample.java b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationBasicExample.java index df800cb5..0e3eed83 100644 --- a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationBasicExample.java +++ b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationBasicExample.java @@ -11,10 +11,10 @@ import de.javagl.jgltf.model.creation.SceneModels; import de.javagl.jgltf.model.impl.DefaultGltfModel; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.io.GltfWriter; import de.javagl.jgltf.model.io.v2.GltfAssetV2; import de.javagl.jgltf.model.io.v2.GltfAssetsV2; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A basic example for the glTF model creation.
@@ -46,7 +46,7 @@ private static GltfModel createGltfModel() MeshPrimitiveModels.create(indices, positions, null, null); // Create a material, and assign it to the mesh primitive - MaterialModelV2 materialModel = + DefaultPbrMaterialModel materialModel = MaterialModels.createFromBaseColor(1.0f, 0.0f, 0.0f, 1.0f); meshPrimitiveModel.setMaterialModel(materialModel); diff --git a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationExample.java b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationExample.java index 1ea2eeab..4ab03afa 100644 --- a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationExample.java +++ b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationExample.java @@ -17,11 +17,11 @@ import de.javagl.jgltf.model.impl.DefaultMeshModel; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; import de.javagl.jgltf.model.impl.DefaultNodeModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.impl.DefaultSceneModel; import de.javagl.jgltf.model.io.GltfWriter; import de.javagl.jgltf.model.io.v2.GltfAssetV2; import de.javagl.jgltf.model.io.v2.GltfAssetsV2; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A basic example for the glTF model creation.
@@ -42,7 +42,7 @@ public static void main(String[] args) throws Exception private static GltfModel createGltfModel() { // Create a material - MaterialModelV2 materialModel = createMaterial(); + DefaultPbrMaterialModel materialModel = createMaterial(); // Create a mesh primitive DefaultMeshPrimitiveModel meshPrimitiveModel = createMeshPrimitive(); @@ -117,7 +117,7 @@ private static DefaultMeshPrimitiveModel createMeshPrimitive() return meshPrimitiveModel; } - private static MaterialModelV2 createMaterial() + private static DefaultPbrMaterialModel createMaterial() { // Create a material using the MaterialBuilder class. // This allows configuring all elements of the resulting @@ -138,7 +138,7 @@ private static MaterialModelV2 createMaterial() materialBuilder.setEmissiveTexture( emissiveTexture, 1.0f, 1.0f, 1.0f, 1); - MaterialModelV2 materialModel = materialBuilder.build(); + DefaultPbrMaterialModel materialModel = materialBuilder.build(); return materialModel; } diff --git a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationMorphTargetsExample.java b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationMorphTargetsExample.java index 7336d140..59bec89b 100644 --- a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationMorphTargetsExample.java +++ b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationMorphTargetsExample.java @@ -14,11 +14,11 @@ import de.javagl.jgltf.model.impl.DefaultGltfModel; import de.javagl.jgltf.model.impl.DefaultMeshModel; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.io.Buffers; import de.javagl.jgltf.model.io.GltfWriter; import de.javagl.jgltf.model.io.v2.GltfAssetV2; import de.javagl.jgltf.model.io.v2.GltfAssetsV2; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * Basic tests and examples for the glTF model creation with morph targets @@ -74,7 +74,7 @@ private static GltfModel createGltfModel() meshPrimitiveBuilder.build(); // Create a material, and assign it to the mesh primitive - MaterialModelV2 materialModel = + DefaultPbrMaterialModel materialModel = MaterialModels.createFromBaseColor(1.0f, 0.9f, 0.9f, 1.0f); meshPrimitiveModel.setMaterialModel(materialModel); diff --git a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationTextureExample.java b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationTextureExample.java index bfa5f0c4..03bfdfbf 100644 --- a/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationTextureExample.java +++ b/jgltf-model-builder/src/test/java/de/javagl/jgltf/model/creation/example/GltfModelCreationTextureExample.java @@ -16,10 +16,10 @@ import de.javagl.jgltf.model.creation.MeshPrimitiveModels; import de.javagl.jgltf.model.creation.SceneModels; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.io.GltfWriter; import de.javagl.jgltf.model.io.v2.GltfAssetV2; import de.javagl.jgltf.model.io.v2.GltfAssetsV2; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A basic example for the glTF model creation. @@ -67,7 +67,7 @@ private static GltfModel createGltfModel() // Create a material from a buffered image BufferedImage bufferedImage = createTextureImage(); - MaterialModelV2 materialModel = MaterialModels.createFromBufferedImage( + DefaultPbrMaterialModel materialModel = MaterialModels.createFromBufferedImage( bufferedImage, "texture.jpg", "image/jpeg"); // Assign the material to the mesh primitive diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/NormalTextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/NormalTextureInfoModel.java new file mode 100644 index 00000000..44927d14 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/NormalTextureInfoModel.java @@ -0,0 +1,41 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +/** + * Interface for the normal texture information that is part of a + * {@link PbrMaterialModel}. + */ +public interface NormalTextureInfoModel extends TextureInfoModel +{ + /** + * Returns the scalar factor applied to each vector of the normal texture + * + * @return The scale + */ + double getScale(); +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/OcclusionTextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/OcclusionTextureInfoModel.java new file mode 100644 index 00000000..4790880c --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/OcclusionTextureInfoModel.java @@ -0,0 +1,41 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +/** + * Interface for the occlusion texture information that is part of a + * {@link PbrMaterialModel}. + */ +public interface OcclusionTextureInfoModel extends TextureInfoModel +{ + /** + * Returns the scalar multiplier controlling the amount of occlusion + * + * @return The strength + */ + double getStrength(); +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMaterialModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMaterialModel.java new file mode 100644 index 00000000..14c66e49 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMaterialModel.java @@ -0,0 +1,320 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +/** + * Interface for a {@link MaterialModel} that is tailored for Physically + * Based Rendering (PBR), as defined in glTF 2.0. + */ +public interface PbrMaterialModel extends MaterialModel +{ + /** + * Alpha modes + */ + public static enum AlphaMode + { + /** + * Opaque mode + */ + OPAQUE, + + /** + * Masking mode + */ + MASK, + + /** + * Blend mode + */ + BLEND + } + + /** + * Returns the {@link PbrMetallicRoughnessModel} of this material + * + * @return The {@link PbrMetallicRoughnessModel} + */ + PbrMetallicRoughnessModel getPbrMetallicRoughnessModel(); + + /** + * Returns the base color {@link TextureModel} + * + * @return The {@link TextureModel} + */ + default TextureModel getBaseColorTexture() + { + PbrMetallicRoughnessModel pbrMetallicRoughnessModel = + getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughnessModel == null) + { + return null; + } + TextureInfoModel textureInfo = + pbrMetallicRoughnessModel.getBaseColorTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTextureModel(); + } + + /** + * Returns the base color texture coordinate index + * + * @return The index + */ + default Integer getBaseColorTexcoord() + { + PbrMetallicRoughnessModel pbrMetallicRoughnessModel = + getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughnessModel == null) + { + return null; + } + TextureInfoModel textureInfo = + pbrMetallicRoughnessModel.getBaseColorTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTexCoord(); + } + + /** + * Returns the metallic-roughness {@link TextureModel} + * + * @return The {@link TextureModel} + */ + default TextureModel getMetallicRoughnessTexture() + { + PbrMetallicRoughnessModel pbrMetallicRoughnessModel = + getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughnessModel == null) + { + return null; + } + TextureInfoModel textureInfo = + pbrMetallicRoughnessModel.getMetallicRoughnessTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTextureModel(); + } + + /** + * Returns the metallic-roughness texture coordinate index + * + * @return The index + */ + default Integer getMetallicRoughnessTexcoord() + { + PbrMetallicRoughnessModel pbrMetallicRoughnessModel = + getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughnessModel == null) + { + return null; + } + TextureInfoModel textureInfo = + pbrMetallicRoughnessModel.getMetallicRoughnessTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTexCoord(); + } + + /** + * Returns the {@link NormalTextureInfoModel} of this material + * + * @return The {@link NormalTextureInfoModel} + */ + NormalTextureInfoModel getNormalTextureInfoModel(); + + /** + * Returns the normal {@link TextureModel} + * + * @return The {@link TextureModel} + */ + default TextureModel getNormalTexture() + { + TextureInfoModel textureInfo = getNormalTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTextureModel(); + } + + /** + * Returns the normal texture coordinate index + * + * @return The index + */ + default Integer getNormalTexcoord() + { + TextureInfoModel textureInfo = getNormalTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTexCoord(); + } + + /** + * Returns the normal scale + * + * @return The normal scale + */ + default Double getNormalScale() + { + NormalTextureInfoModel textureInfo = getNormalTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getScale(); + } + + /** + * Returns the {@link OcclusionTextureInfoModel} of this material + * + * @return The {@link OcclusionTextureInfoModel} + */ + OcclusionTextureInfoModel getOcclusionTextureInfoModel(); + + /** + * Returns the occlusion {@link TextureModel} + * + * @return The {@link TextureModel} + */ + default TextureModel getOcclusionTexture() + { + TextureInfoModel textureInfo = getOcclusionTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTextureModel(); + } + + /** + * Returns the occlusion texture coordinate index + * + * @return The index + */ + default Integer getOcclusionTexcoord() + { + TextureInfoModel textureInfo = getOcclusionTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTexCoord(); + } + + /** + * Returns the occlusion strength + * + * @return The occlusion strength + */ + default Double getOcclusionStrength() + { + OcclusionTextureInfoModel textureInfo = getOcclusionTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getStrength(); + } + + /** + * Returns the {@link TextureInfoModel} for the emissive texture + * + * @return The {@link TextureInfoModel} + */ + TextureInfoModel getEmissiveTextureInfoModel(); + + /** + * Returns the emissive {@link TextureModel} + * + * @return The {@link TextureModel} + */ + default TextureModel getEmissiveTexture() + { + TextureInfoModel textureInfo = getEmissiveTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTextureModel(); + } + + /** + * Returns the emissive texture coordinate index + * + * @return The index + */ + default Integer getEmissiveTexcoord() + { + TextureInfoModel textureInfo = getEmissiveTextureInfoModel(); + if (textureInfo == null) + { + return null; + } + return textureInfo.getTexCoord(); + } + + /** + * Returns the emissive factor + * + * @return The emissive factor + */ + double[] getEmissiveFactor(); + + /** + * Returns the alpha mode + * + * @return The alpha mode + */ + AlphaMode getAlphaMode(); + + /** + * Returns the alpha cutoff + * + * @return The alpha cutoff + */ + double getAlphaCutoff(); + + /** + * Returns whether the material is double sided + * + * @return Whether the material is double sided + */ + boolean isDoubleSided(); + +} \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMetallicRoughnessModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMetallicRoughnessModel.java new file mode 100644 index 00000000..36a3c139 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/PbrMetallicRoughnessModel.java @@ -0,0 +1,70 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +/** + * Interface for the metallic-roughness texture information that is part of a + * {@link PbrMaterialModel}. + */ +public interface PbrMetallicRoughnessModel extends ModelElement +{ + /** + * Returns the base color factor + * + * @return The base color factor + */ + double[] getBaseColorFactor(); + + /** + * Returns the base color texture info + * + * @return The base color texture info + */ + TextureInfoModel getBaseColorTextureInfoModel(); + + /** + * Returns the metallic factor + * + * @return The metallic factor + */ + double getMetallicFactor(); + + /** + * Returns the roughness factor + * + * @return The roughness factor + */ + double getRoughnessFactor(); + + /** + * Returns the metallic-roughness-texture info + * + * @return The metallic-roughness texture info + */ + TextureInfoModel getMetallicRoughnessTextureInfoModel(); + +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/TechniqueMaterialModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/TechniqueMaterialModel.java new file mode 100644 index 00000000..36a0e474 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/TechniqueMaterialModel.java @@ -0,0 +1,55 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +import java.util.Map; + +import de.javagl.jgltf.model.gl.TechniqueModel; + +/** + * Interface for a {@link MaterialModel} that uses the {@link TechniqueModel} + * based material definition of glTF 1.0. + */ +public interface TechniqueMaterialModel extends MaterialModel +{ + /** + * Returns the {@link TechniqueModel} + * + * @return The {@link TechniqueModel} + */ + TechniqueModel getTechniqueModel(); + + /** + * Returns the parameter values of this material. Note that if any + * parameter value of the original material is the texture ID + * for a parameter of type GL_SAMPLER2D, then the respective value + * will be the appropriate {@link TextureModel} instance. + * + * @return The values + */ + Map getValues(); +} \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/TextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/TextureInfoModel.java new file mode 100644 index 00000000..5e8f10b1 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/TextureInfoModel.java @@ -0,0 +1,49 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model; + +/** + * Interface for the texture information that is part of a + * {@link PbrMaterialModel}. + */ +public interface TextureInfoModel extends ModelElement +{ + /** + * Returns the {@link TextureModel} + * + * @return The {@link TextureModel} + */ + TextureModel getTextureModel(); + + /** + * The optional set index of texture's TEXCOORD attribute used for texture + * coordinate mapping.
+ * + * @return The set index + */ + Integer getTexCoord(); +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNormalTextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNormalTextureInfoModel.java new file mode 100644 index 00000000..cf88ea0d --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultNormalTextureInfoModel.java @@ -0,0 +1,66 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import de.javagl.jgltf.model.NormalTextureInfoModel; + +/** + * Implementation of a {@link NormalTextureInfoModel} + */ +public class DefaultNormalTextureInfoModel extends DefaultTextureInfoModel + implements NormalTextureInfoModel +{ + /** + * The scale factor + */ + private double scale; + + /** + * Creates a new instance + */ + public DefaultNormalTextureInfoModel() + { + scale = 1.0; + } + + /** + * Set the scale factor + * + * @param scale The scale factor + */ + public void setScale(double scale) + { + this.scale = scale; + } + + @Override + public double getScale() + { + return scale; + } + +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultOcclusionTextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultOcclusionTextureInfoModel.java new file mode 100644 index 00000000..f6c4e524 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultOcclusionTextureInfoModel.java @@ -0,0 +1,66 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import de.javagl.jgltf.model.OcclusionTextureInfoModel; + +/** + * Implementation of a {@link OcclusionTextureInfoModel} + */ +public class DefaultOcclusionTextureInfoModel extends DefaultTextureInfoModel + implements OcclusionTextureInfoModel +{ + /** + * The occlusion strength + */ + private double strength; + + /** + * Creates a new instance + */ + public DefaultOcclusionTextureInfoModel() + { + strength = 1.0; + } + + /** + * Set the occlusion strength + * + * @param strength The strength + */ + public void setStrength(double strength) + { + this.strength = strength; + } + + @Override + public double getStrength() + { + return strength; + } + +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMaterialModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMaterialModel.java new file mode 100644 index 00000000..47374c1b --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMaterialModel.java @@ -0,0 +1,229 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import de.javagl.jgltf.model.NormalTextureInfoModel; +import de.javagl.jgltf.model.OcclusionTextureInfoModel; +import de.javagl.jgltf.model.PbrMaterialModel; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; +import de.javagl.jgltf.model.TextureInfoModel; + +/** + * Default implementation of a {@link PbrMaterialModel} for glTF 2.0.
+ */ +public final class DefaultPbrMaterialModel extends AbstractNamedModelElement + implements PbrMaterialModel +{ + /** + * The {@link PbrMetallicRoughnessModel} + */ + private PbrMetallicRoughnessModel pbrMetallicRoughnessModel; + + /** + * THe {@link NormalTextureInfoModel} + */ + private NormalTextureInfoModel normalTextureInfoModel; + + /** + * The {@link OcclusionTextureInfoModel} + */ + private OcclusionTextureInfoModel occlusionTextureInfoModel; + + /** + * The emissive {@link TextureInfoModel} + */ + private TextureInfoModel emissiveTextureInfoModel; + + /** + * The emissive factor + */ + private double[] emissiveFactor; + + /** + * The alpha mode + */ + private AlphaMode alphaMode; + + /** + * The alpha cutoff + */ + private double alphaCutoff; + + /** + * Whether the material is double sided + */ + private boolean doubleSided; + + /** + * Creates a new instance with default values + */ + public DefaultPbrMaterialModel() + { + pbrMetallicRoughnessModel = null; + normalTextureInfoModel = null; + occlusionTextureInfoModel = null; + emissiveTextureInfoModel = null; + + emissiveFactor = new double[]{0.0, 0.0, 0.0 }; + + alphaMode = AlphaMode.OPAQUE; + alphaCutoff = 0.5; + + doubleSided = false; + } + + @Override + public PbrMetallicRoughnessModel getPbrMetallicRoughnessModel() + { + return pbrMetallicRoughnessModel; + } + + /** + * Set the {@link PbrMetallicRoughnessModel} + * + * @param pbrMetallicRoughnessModel The {@link PbrMetallicRoughnessModel} + */ + public void setPbrMetallicRoughnessModel( + PbrMetallicRoughnessModel pbrMetallicRoughnessModel) + { + this.pbrMetallicRoughnessModel = pbrMetallicRoughnessModel; + } + + @Override + public NormalTextureInfoModel getNormalTextureInfoModel() + { + return normalTextureInfoModel; + } + + /** + * Set the {@link NormalTextureInfoModel} + * @param normalTextureInfoModel The {@link NormalTextureInfoModel} + */ + public void + setNormalTextureInfoModel(NormalTextureInfoModel normalTextureInfoModel) + { + this.normalTextureInfoModel = normalTextureInfoModel; + } + + @Override + public OcclusionTextureInfoModel getOcclusionTextureInfoModel() + { + return occlusionTextureInfoModel; + } + + /** + * Set the {@link OcclusionTextureInfoModel} + * + * @param occlusionTextureInfoModel The {@link OcclusionTextureInfoModel} + */ + public void setOcclusionTextureInfoModel( + OcclusionTextureInfoModel occlusionTextureInfoModel) + { + this.occlusionTextureInfoModel = occlusionTextureInfoModel; + } + + @Override + public TextureInfoModel getEmissiveTextureInfoModel() + { + return emissiveTextureInfoModel; + } + + /** + * Set the emissive {@link TextureInfoModel} + * + * @param emissiveTextureInfoModel The {@link TextureInfoModel} + */ + public void + setEmissiveTextureInfoModel(TextureInfoModel emissiveTextureInfoModel) + { + this.emissiveTextureInfoModel = emissiveTextureInfoModel; + } + + @Override + public double[] getEmissiveFactor() + { + return emissiveFactor; + } + + /** + * Set the emissive factor + * + * @param emissiveFactor The emissive factor + */ + public void setEmissiveFactor(double[] emissiveFactor) + { + this.emissiveFactor = emissiveFactor; + } + + @Override + public AlphaMode getAlphaMode() + { + return alphaMode; + } + + /** + * Set the alpha mode + * + * @param alphaMode The alpha mode + */ + public void setAlphaMode(AlphaMode alphaMode) + { + this.alphaMode = alphaMode; + } + + @Override + public double getAlphaCutoff() + { + return alphaCutoff; + } + + /** + * Set the alpha cutoff + * + * @param alphaCutoff The alpha cutoff + */ + public void setAlphaCutoff(double alphaCutoff) + { + this.alphaCutoff = alphaCutoff; + } + + @Override + public boolean isDoubleSided() + { + return doubleSided; + } + + /** + * Set whether the material is double sided + * + * @param doubleSided Whether the material is double sided + */ + public void setDoubleSided(boolean doubleSided) + { + this.doubleSided = doubleSided; + } +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMetallicRoughnessModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMetallicRoughnessModel.java new file mode 100644 index 00000000..94447b08 --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultPbrMetallicRoughnessModel.java @@ -0,0 +1,240 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import de.javagl.jgltf.model.NormalTextureInfoModel; +import de.javagl.jgltf.model.OcclusionTextureInfoModel; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; +import de.javagl.jgltf.model.TextureInfoModel; + +/** + * Default implementation of a {@link PbrMetallicRoughnessModel} + */ +public class DefaultPbrMetallicRoughnessModel extends AbstractModelElement + implements PbrMetallicRoughnessModel +{ + /** + * The base color factor + */ + private double[] baseColorFactor; + + /** + * The base color texture info + */ + private TextureInfoModel baseColorTextureInfoModel; + + /** + * The metallic factor + */ + private double metallicFactor; + + /** + * The roughness factor + */ + private double roughnessFactor; + + /** + * The metallic-roughness texture info + */ + private TextureInfoModel metallicRoughnessTextureInfoModel; + + /** + * The normal texture info + */ + private NormalTextureInfoModel normalTextureInfoModel; + + /** + * The occlusion texture info + */ + private OcclusionTextureInfoModel occlusionTextureInfoModel; + + /** + * The emissive texture info + */ + private TextureInfoModel emissiveTextureInfoModel; + + /** + * Creates a new instance with default values + */ + public DefaultPbrMetallicRoughnessModel() + { + baseColorFactor = new double[] + { 1.0, 1.0, 1.0, 1.0 }; + baseColorTextureInfoModel = null; + metallicFactor = 1.0; + roughnessFactor = 1.0; + metallicRoughnessTextureInfoModel = null; + normalTextureInfoModel = null; + occlusionTextureInfoModel = null; + emissiveTextureInfoModel = null; + } + + @Override + public double[] getBaseColorFactor() + { + return baseColorFactor; + } + + /** + * Set the base color factor + * + * @param baseColorFactor The base color factor + */ + public void setBaseColorFactor(double[] baseColorFactor) + { + this.baseColorFactor = baseColorFactor; + } + + @Override + public TextureInfoModel getBaseColorTextureInfoModel() + { + return baseColorTextureInfoModel; + } + + /** + * Set the base color texture info model + * + * @param baseColorTextureInfoModel The base color texture info model + */ + public void setBaseColorTexture(TextureInfoModel baseColorTextureInfoModel) + { + this.baseColorTextureInfoModel = baseColorTextureInfoModel; + } + + @Override + public double getMetallicFactor() + { + return metallicFactor; + } + + /** + * Set the metallic factor + * + * @param metallicFactor The metallic factor + */ + public void setMetallicFactor(double metallicFactor) + { + this.metallicFactor = metallicFactor; + } + + @Override + public double getRoughnessFactor() + { + return roughnessFactor; + } + + /** + * Set the roughness factor + * + * @param roughnessFactor The roughness factor + */ + public void setRoughnessFactor(double roughnessFactor) + { + this.roughnessFactor = roughnessFactor; + } + + @Override + public TextureInfoModel getMetallicRoughnessTextureInfoModel() + { + return metallicRoughnessTextureInfoModel; + } + + /** + * Set the metallic-roughness-texture info model + * + * @param metallicRoughnessTextureInfoModel The metallic-roughness-texture + * info model + */ + public void setMetallicRoughnessTextureInfo( + TextureInfoModel metallicRoughnessTextureInfoModel) + { + this.metallicRoughnessTextureInfoModel = + metallicRoughnessTextureInfoModel; + } + + /** + * Returns the normal texture info model + * + * @return The normal texture info model + */ + public NormalTextureInfoModel getNormalTextureInfoModel() + { + return normalTextureInfoModel; + } + + /** + * Set the normal texture info model + * + * @param normalTextureInfoModel The normal texture info model + */ + public void + setNormalTextureInfoModel(NormalTextureInfoModel normalTextureInfoModel) + { + this.normalTextureInfoModel = normalTextureInfoModel; + } + + /** + * Returns the occlusion texture info model + * + * @return The occlusion texture info model + */ + public OcclusionTextureInfoModel getOcclusionTextureInfoModel() + { + return occlusionTextureInfoModel; + } + + /** + * Set the occlusion texture info model + * + * @param occlusionTextureInfoModel The occlusion texture info model + */ + public void setOcclusionTextureInfoModel( + OcclusionTextureInfoModel occlusionTextureInfoModel) + { + this.occlusionTextureInfoModel = occlusionTextureInfoModel; + } + + /** + * Returns the emissive texture info model + * + * @return The emissive texture info model + */ + public TextureInfoModel getEmissiveTextureInfoModel() + { + return emissiveTextureInfoModel; + } + + /** + * Set the emissive texture info model + * + * @param emissiveTextureInfoModel The emissive texture info model + */ + public void setEmissiveTexture(TextureInfoModel emissiveTextureInfoModel) + { + this.emissiveTextureInfoModel = emissiveTextureInfoModel; + } +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/MaterialModelV1.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTechniqueMaterialModel.java similarity index 69% rename from jgltf-model/src/main/java/de/javagl/jgltf/model/v1/MaterialModelV1.java rename to jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTechniqueMaterialModel.java index 8d67d4fa..498bb25e 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/MaterialModelV1.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTechniqueMaterialModel.java @@ -1,120 +1,102 @@ -/* - * www.javagl.de - JglTF - * - * Copyright 2015-2017 Marco Hutter - http://www.javagl.de - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -package de.javagl.jgltf.model.v1; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import de.javagl.jgltf.impl.v1.Material; -import de.javagl.jgltf.model.MaterialModel; -import de.javagl.jgltf.model.TextureModel; -import de.javagl.jgltf.model.gl.TechniqueModel; -import de.javagl.jgltf.model.impl.AbstractNamedModelElement; - -/** - * Implementation of a {@link MaterialModel} for glTF 1.0.
- *
- * Note: This class is actually no longer specific for glTF 1.0. It might - * be renamed to "TechniqueBasedMaterialModel" and moved to a different - * package in the future. - */ -public final class MaterialModelV1 extends AbstractNamedModelElement - implements MaterialModel -{ - /** - * The {@link TechniqueModel} - */ - private TechniqueModel techniqueModel; - - /** - * The material parameter values - */ - private Map values; - - /** - * Creates a new instance - */ - public MaterialModelV1() - { - this.values = Collections.emptyMap(); - } - - /** - * Set the material parameter values to be an unmodifiable shallow - * copy of the given map (or the empty map if the given map is - * null) - * - * @param values The material parameter values - */ - public void setValues(Map values) - { - if (values == null) - { - this.values = Collections.emptyMap(); - } - else - { - this.values = Collections.unmodifiableMap( - new LinkedHashMap(values)); - } - } - - /** - * Set the {@link TechniqueModel} - * - * @param techniqueModel The {@link TechniqueModel} - */ - public void setTechniqueModel(TechniqueModel techniqueModel) - { - this.techniqueModel = techniqueModel; - } - - /** - * Returns the {@link TechniqueModel} - * - * @return The {@link TechniqueModel} - */ - public TechniqueModel getTechniqueModel() - { - return techniqueModel; - } - - /** - * Returns the parameter values of this material. Note that if any - * parameter value of the original {@link Material} is the texture ID - * for a parameter of type GL_SAMPLER2D, then the respective value - * will be the appropriate {@link TextureModel} instance. - * - * @return The values - */ - public Map getValues() - { - return values; - } - +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import de.javagl.jgltf.model.TechniqueMaterialModel; +import de.javagl.jgltf.model.gl.TechniqueModel; + +/** + * Implementation of a {@link TechniqueMaterialModel}.
+ */ +public final class DefaultTechniqueMaterialModel extends AbstractNamedModelElement + implements TechniqueMaterialModel +{ + /** + * The {@link TechniqueModel} + */ + private TechniqueModel techniqueModel; + + /** + * The material parameter values + */ + private Map values; + + /** + * Creates a new instance + */ + public DefaultTechniqueMaterialModel() + { + this.values = Collections.emptyMap(); + } + + /** + * Set the material parameter values to be an unmodifiable shallow + * copy of the given map (or the empty map if the given map is + * null) + * + * @param values The material parameter values + */ + public void setValues(Map values) + { + if (values == null) + { + this.values = Collections.emptyMap(); + } + else + { + this.values = Collections.unmodifiableMap( + new LinkedHashMap(values)); + } + } + + /** + * Set the {@link TechniqueModel} + * + * @param techniqueModel The {@link TechniqueModel} + */ + public void setTechniqueModel(TechniqueModel techniqueModel) + { + this.techniqueModel = techniqueModel; + } + + @Override + public TechniqueModel getTechniqueModel() + { + return techniqueModel; + } + + @Override + public Map getValues() + { + return values; + } + } \ No newline at end of file diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTextureInfoModel.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTextureInfoModel.java new file mode 100644 index 00000000..4577201f --- /dev/null +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/impl/DefaultTextureInfoModel.java @@ -0,0 +1,88 @@ +/* + * www.javagl.de - JglTF + * + * Copyright 2015-2017 Marco Hutter - http://www.javagl.de + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +package de.javagl.jgltf.model.impl; + +import de.javagl.jgltf.model.ImageModel; +import de.javagl.jgltf.model.TextureInfoModel; +import de.javagl.jgltf.model.TextureModel; + +/** + * Implementation of a {@link TextureInfoModel} + */ +public class DefaultTextureInfoModel extends AbstractNamedModelElement + implements TextureInfoModel +{ + /** + * The {@link ImageModel} + */ + private TextureModel textureModel; + + /** + * The texture coordinate set index + */ + private Integer texCoord; + + /** + * Creates a new instance + */ + public DefaultTextureInfoModel() + { + // Default constructor + } + + /** + * Set the {@link TextureModel} + * + * @param textureModel The {@link TextureModel} + */ + public void setTextureModel(TextureModel textureModel) + { + this.textureModel = textureModel; + } + + @Override + public TextureModel getTextureModel() + { + return textureModel; + } + + /** + * Set the texture coordinate set index + * + * @param texCoord The set index + */ + public void setTexCoord(Integer texCoord) + { + this.texCoord = texCoord; + } + + @Override + public Integer getTexCoord() + { + return texCoord; + } +} diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java index 16e86595..faca539e 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/structure/GltfModelStructures.java @@ -59,9 +59,13 @@ import de.javagl.jgltf.model.MeshModel; import de.javagl.jgltf.model.MeshPrimitiveModel; import de.javagl.jgltf.model.NodeModel; +import de.javagl.jgltf.model.NormalTextureInfoModel; +import de.javagl.jgltf.model.OcclusionTextureInfoModel; import de.javagl.jgltf.model.Optionals; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; import de.javagl.jgltf.model.SceneModel; import de.javagl.jgltf.model.SkinModel; +import de.javagl.jgltf.model.TextureInfoModel; import de.javagl.jgltf.model.TextureModel; import de.javagl.jgltf.model.gl.ProgramModel; import de.javagl.jgltf.model.gl.ShaderModel; @@ -90,12 +94,16 @@ import de.javagl.jgltf.model.impl.DefaultMeshModel; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; import de.javagl.jgltf.model.impl.DefaultNodeModel; +import de.javagl.jgltf.model.impl.DefaultNormalTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultOcclusionTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; +import de.javagl.jgltf.model.impl.DefaultPbrMetallicRoughnessModel; import de.javagl.jgltf.model.impl.DefaultSceneModel; import de.javagl.jgltf.model.impl.DefaultSkinModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; +import de.javagl.jgltf.model.impl.DefaultTextureInfoModel; import de.javagl.jgltf.model.impl.DefaultTextureModel; import de.javagl.jgltf.model.v1.GltfModelV1; -import de.javagl.jgltf.model.v1.MaterialModelV1; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A class for modifying the structure of a glTF model.
@@ -240,14 +248,14 @@ public void prepare(GltfModel sourceGltfModel) { materialModelsMap = computeMapping( source.getMaterialModels(), - MaterialModelV1::new, + DefaultTechniqueMaterialModel::new, target::addMaterialModel); } else { materialModelsMap = computeMapping( source.getMaterialModels(), - MaterialModelV2::new, + DefaultPbrMaterialModel::new, target::addMaterialModel); } @@ -387,7 +395,7 @@ private DefaultGltfModel create(DefaultBufferBuilderStrategy.Config config) { if (this.target == null) { - throw new GltfException("The 'prepare' method has not bee called"); + throw new GltfException("The 'prepare' method has not been called"); } Level level = Level.FINE; if (logger.isLoggable(level)) @@ -961,10 +969,10 @@ private void initMaterialModelsV1() List sourceMaterialModels = source.getMaterialModels(); for (int i = 0; i < sourceMaterialModels.size(); i++) { - MaterialModelV1 sourceMaterialModel = - (MaterialModelV1) sourceMaterialModels.get(i); - MaterialModelV1 targetMaterialModel = - (MaterialModelV1) materialModelsMap.get(sourceMaterialModel); + DefaultTechniqueMaterialModel sourceMaterialModel = + (DefaultTechniqueMaterialModel) sourceMaterialModels.get(i); + DefaultTechniqueMaterialModel targetMaterialModel = + (DefaultTechniqueMaterialModel) materialModelsMap.get(sourceMaterialModel); copyGltfChildOfRootPropertyElements( sourceMaterialModel, targetMaterialModel); @@ -973,15 +981,15 @@ private void initMaterialModelsV1() } /** - * Initialize the given {@link MaterialModelV1} based on the given - * {@link MaterialModelV1} + * Initialize the given {@link DefaultTechniqueMaterialModel} based on the given + * {@link DefaultTechniqueMaterialModel} * - * @param sourceMaterialModel The source {@link MaterialModelV1} - * @param targetMaterialModel The target {@link MaterialModelV1} + * @param sourceMaterialModel The source {@link DefaultTechniqueMaterialModel} + * @param targetMaterialModel The target {@link DefaultTechniqueMaterialModel} */ private void initMaterialModel( - MaterialModelV1 sourceMaterialModel, - MaterialModelV1 targetMaterialModel) + DefaultTechniqueMaterialModel sourceMaterialModel, + DefaultTechniqueMaterialModel targetMaterialModel) { TechniqueModel sourceTechniqueModel = sourceMaterialModel.getTechniqueModel(); @@ -1028,10 +1036,10 @@ private void initMaterialModelsV2() List sourceMaterialModels = source.getMaterialModels(); for (int i = 0; i < sourceMaterialModels.size(); i++) { - MaterialModelV2 sourceMaterialModel = - (MaterialModelV2) sourceMaterialModels.get(i); - MaterialModelV2 targetMaterialModel = - (MaterialModelV2) materialModelsMap.get(sourceMaterialModel); + DefaultPbrMaterialModel sourceMaterialModel = + (DefaultPbrMaterialModel) sourceMaterialModels.get(i); + DefaultPbrMaterialModel targetMaterialModel = + (DefaultPbrMaterialModel) materialModelsMap.get(sourceMaterialModel); copyGltfChildOfRootPropertyElements( sourceMaterialModel, targetMaterialModel); @@ -1040,88 +1048,125 @@ private void initMaterialModelsV2() } /** - * Initialize the given {@link MaterialModelV2} based on the given - * {@link MaterialModelV2} + * Initialize the given {@link DefaultPbrMaterialModel} based on the given + * {@link DefaultPbrMaterialModel} * - * @param sourceMaterialModel The source {@link MaterialModelV2} - * @param targetMaterialModel The target {@link MaterialModelV2} + * @param sourceMaterial The source {@link DefaultPbrMaterialModel} + * @param targetMaterial The target {@link DefaultPbrMaterialModel} */ private void initMaterialModel( - MaterialModelV2 sourceMaterialModel, - MaterialModelV2 targetMaterialModel) + DefaultPbrMaterialModel sourceMaterial, + DefaultPbrMaterialModel targetMaterial) { - targetMaterialModel.setAlphaMode( - sourceMaterialModel.getAlphaMode()); - targetMaterialModel.setAlphaCutoff( - sourceMaterialModel.getAlphaCutoff()); - - targetMaterialModel.setDoubleSided( - sourceMaterialModel.isDoubleSided()); - - TextureModel sourceBaseColorTexture = - sourceMaterialModel.getBaseColorTexture(); - DefaultTextureModel targetBaseColorTexture = - textureModelsMap.get(sourceBaseColorTexture); - targetMaterialModel.setBaseColorTexture( - targetBaseColorTexture); - targetMaterialModel.setBaseColorTexcoord( - sourceMaterialModel.getBaseColorTexcoord()); - - double[] baseColorFactor = sourceMaterialModel.getBaseColorFactor(); - targetMaterialModel.setBaseColorFactor( - Optionals.clone(baseColorFactor)); + targetMaterial.setAlphaMode(sourceMaterial.getAlphaMode()); + targetMaterial.setAlphaCutoff(sourceMaterial.getAlphaCutoff()); - TextureModel sourceMetallicRoughnessTexture = - sourceMaterialModel.getMetallicRoughnessTexture(); - DefaultTextureModel targetMetallicRoughnessTexture = - textureModelsMap.get(sourceMetallicRoughnessTexture); - targetMaterialModel.setMetallicRoughnessTexture( - targetMetallicRoughnessTexture); - targetMaterialModel.setMetallicRoughnessTexcoord( - sourceMaterialModel.getMetallicRoughnessTexcoord()); + targetMaterial.setDoubleSided(sourceMaterial.isDoubleSided()); - targetMaterialModel.setMetallicFactor( - sourceMaterialModel.getMetallicFactor()); - targetMaterialModel.setRoughnessFactor( - sourceMaterialModel.getRoughnessFactor()); + PbrMetallicRoughnessModel sourcePbrMetallicRoughness = + sourceMaterial.getPbrMetallicRoughnessModel(); + if (sourcePbrMetallicRoughness != null) + { + DefaultPbrMetallicRoughnessModel targetPbrMetallicRoughness = + new DefaultPbrMetallicRoughnessModel(); - TextureModel sourceNormalTexture = - sourceMaterialModel.getNormalTexture(); - DefaultTextureModel targetNormalTexture = - textureModelsMap.get(sourceNormalTexture); - targetMaterialModel.setNormalTexture( - targetNormalTexture); - targetMaterialModel.setNormalTexcoord( - sourceMaterialModel.getNormalTexcoord()); - - targetMaterialModel.setNormalScale( - sourceMaterialModel.getNormalScale()); + TextureInfoModel sourceBaseColorTextureInfo = + sourcePbrMetallicRoughness.getBaseColorTextureInfoModel(); + if (sourceBaseColorTextureInfo != null) + { + TextureModel sourceBaseColorTexture = + sourceBaseColorTextureInfo.getTextureModel(); - TextureModel sourceOcclusionTexture = - sourceMaterialModel.getOcclusionTexture(); - DefaultTextureModel targetOcclusionTexture = - textureModelsMap.get(sourceOcclusionTexture); - targetMaterialModel.setOcclusionTexture( - targetOcclusionTexture); - targetMaterialModel.setOcclusionTexcoord( - sourceMaterialModel.getOcclusionTexcoord()); - - targetMaterialModel.setOcclusionStrength( - sourceMaterialModel.getOcclusionStrength()); - + DefaultTextureModel targetBaseColorTexture = + textureModelsMap.get(sourceBaseColorTexture); - TextureModel sourceEmissiveTexture = - sourceMaterialModel.getEmissiveTexture(); - DefaultTextureModel targetEmissiveTexture = - textureModelsMap.get(sourceEmissiveTexture); - targetMaterialModel.setEmissiveTexture( - targetEmissiveTexture); - targetMaterialModel.setEmissiveTexcoord( - sourceMaterialModel.getEmissiveTexcoord()); - - double emissiveFactor[] = sourceMaterialModel.getEmissiveFactor(); - targetMaterialModel.setEmissiveFactor( - Optionals.clone(emissiveFactor)); + DefaultTextureInfoModel targetBaseColorTextureInfo = + new DefaultTextureInfoModel(); + targetBaseColorTextureInfo.setTextureModel( + targetBaseColorTexture); + targetBaseColorTextureInfo.setTexCoord( + sourceBaseColorTextureInfo.getTexCoord()); + + targetPbrMetallicRoughness.setBaseColorTexture( + targetBaseColorTextureInfo); + + targetPbrMetallicRoughness.setMetallicFactor( + sourcePbrMetallicRoughness.getMetallicFactor()); + targetPbrMetallicRoughness.setRoughnessFactor( + sourcePbrMetallicRoughness.getRoughnessFactor()); + + double[] sourceBaseColorFactor = sourcePbrMetallicRoughness.getBaseColorFactor(); + targetPbrMetallicRoughness.setBaseColorFactor( + Optionals.clone(sourceBaseColorFactor)); + } + targetMaterial.setPbrMetallicRoughnessModel( + targetPbrMetallicRoughness); + } + + NormalTextureInfoModel sourceNormalTextureInfo = + sourceMaterial.getNormalTextureInfoModel(); + if (sourceNormalTextureInfo != null) + { + DefaultNormalTextureInfoModel targetNormalTextureInfo = + new DefaultNormalTextureInfoModel(); + + TextureModel sourceNormalTexture = + sourceNormalTextureInfo.getTextureModel(); + DefaultTextureModel targetNormalTexture = + textureModelsMap.get(sourceNormalTexture); + targetNormalTextureInfo.setTextureModel(targetNormalTexture); + targetNormalTextureInfo.setTexCoord( + sourceNormalTextureInfo.getTexCoord()); + + targetNormalTextureInfo.setScale( + sourceNormalTextureInfo.getScale()); + + targetMaterial.setNormalTextureInfoModel(targetNormalTextureInfo); + } + + OcclusionTextureInfoModel sourceOcclusionTextureInfo = + sourceMaterial.getOcclusionTextureInfoModel(); + if (sourceOcclusionTextureInfo != null) + { + DefaultOcclusionTextureInfoModel targetOcclusionTextureInfo = + new DefaultOcclusionTextureInfoModel(); + + TextureModel sourceOcclusionTexture = + sourceOcclusionTextureInfo.getTextureModel(); + DefaultTextureModel targetOcclusionTexture = + textureModelsMap.get(sourceOcclusionTexture); + targetOcclusionTextureInfo.setTextureModel(targetOcclusionTexture); + targetOcclusionTextureInfo.setTexCoord( + sourceOcclusionTextureInfo.getTexCoord()); + + targetOcclusionTextureInfo.setStrength( + sourceOcclusionTextureInfo.getStrength()); + + targetMaterial.setOcclusionTextureInfoModel( + targetOcclusionTextureInfo); + } + + TextureInfoModel sourceEmissiveTextureInfo = + sourceMaterial.getEmissiveTextureInfoModel(); + if (sourceEmissiveTextureInfo != null) + { + DefaultTextureInfoModel targetEmissiveTextureInfo = + new DefaultTextureInfoModel(); + + TextureModel sourceEmissiveTexture = + sourceEmissiveTextureInfo.getTextureModel(); + DefaultTextureModel targetEmissiveTexture = + textureModelsMap.get(sourceEmissiveTexture); + targetEmissiveTextureInfo.setTextureModel(targetEmissiveTexture); + targetEmissiveTextureInfo.setTexCoord( + sourceEmissiveTextureInfo.getTexCoord()); + + targetMaterial.setEmissiveTextureInfoModel( + targetEmissiveTextureInfo); + } + + double emissiveFactor[] = sourceMaterial.getEmissiveFactor(); + targetMaterial.setEmissiveFactor(Optionals.clone(emissiveFactor)); } diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfCreatorV1.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfCreatorV1.java index 5609f3d8..d4843b92 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfCreatorV1.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfCreatorV1.java @@ -99,6 +99,7 @@ import de.javagl.jgltf.model.gl.TechniqueParametersModel; import de.javagl.jgltf.model.gl.TechniqueStatesFunctionsModel; import de.javagl.jgltf.model.gl.TechniqueStatesModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; /** * A class for creating the {@link GlTF version 1.0 glTF} from a @@ -635,9 +636,9 @@ private Image createImage(ImageModel imageModel) */ private Material createMaterial(MaterialModel materialModel) { - if (materialModel instanceof MaterialModelV1) + if (materialModel instanceof DefaultTechniqueMaterialModel) { - MaterialModelV1 materialModelV1 = (MaterialModelV1)materialModel; + DefaultTechniqueMaterialModel materialModelV1 = (DefaultTechniqueMaterialModel)materialModel; return createMaterialV1(materialModelV1); } // TODO It should be possible to use a glTF 2.0 material model here @@ -646,12 +647,12 @@ private Material createMaterial(MaterialModel materialModel) } /** - * Create the {@link Material} for the given {@link MaterialModelV1} + * Create the {@link Material} for the given {@link DefaultTechniqueMaterialModel} * - * @param materialModel The {@link MaterialModelV1} + * @param materialModel The {@link DefaultTechniqueMaterialModel} * @return The {@link Material} */ - private Material createMaterialV1(MaterialModelV1 materialModel) + private Material createMaterialV1(DefaultTechniqueMaterialModel materialModel) { Material material = new Material(); transferGltfChildOfRootPropertyElements(materialModel, material); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java index cdb465d9..cd1766e4 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/GltfModelCreatorV1.java @@ -121,6 +121,7 @@ import de.javagl.jgltf.model.impl.DefaultNodeModel; import de.javagl.jgltf.model.impl.DefaultSceneModel; import de.javagl.jgltf.model.impl.DefaultSkinModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.jgltf.model.impl.DefaultTextureModel; import de.javagl.jgltf.model.io.Buffers; import de.javagl.jgltf.model.io.GltfAsset; @@ -424,7 +425,7 @@ private void createMaterialModels() Map materials = Optionals.of(gltf.getMaterials()); for (int i = 0; i < materials.size(); i++) { - gltfModel.addMaterialModel(new MaterialModelV1()); + gltfModel.addMaterialModel(new DefaultTechniqueMaterialModel()); } } @@ -1377,8 +1378,8 @@ private void initMaterialModels() { String materialId = entry.getKey(); Material material = entry.getValue(); - MaterialModelV1 materialModel = - (MaterialModelV1) get("materials", + DefaultTechniqueMaterialModel materialModel = + (DefaultTechniqueMaterialModel) get("materials", materialId, gltfModel::getMaterialModel); transferGltfChildOfRootPropertyElements(material, materialModel); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/gl/DefaultModels.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/gl/DefaultModels.java index 7962f9aa..77f31554 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/gl/DefaultModels.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v1/gl/DefaultModels.java @@ -56,9 +56,9 @@ import de.javagl.jgltf.model.gl.impl.DefaultTechniqueModel; import de.javagl.jgltf.model.gl.impl.DefaultTechniqueParametersModel; import de.javagl.jgltf.model.gl.impl.DefaultTechniqueStatesModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.jgltf.model.io.Buffers; import de.javagl.jgltf.model.io.IO; -import de.javagl.jgltf.model.v1.MaterialModelV1; /** * A class containing the default {@link TechniqueModel} and @@ -96,7 +96,7 @@ public class DefaultModels /** * The default {@link MaterialModel} */ - private static final MaterialModelV1 DEFAULT_MATERIAL_MODEL; + private static final DefaultTechniqueMaterialModel DEFAULT_MATERIAL_MODEL; static { @@ -144,7 +144,7 @@ public class DefaultModels // Create a model for the default material Material material = GltfDefaults.getDefaultMaterial(); - DEFAULT_MATERIAL_MODEL = new MaterialModelV1(); + DEFAULT_MATERIAL_MODEL = new DefaultTechniqueMaterialModel(); DEFAULT_MATERIAL_MODEL.setValues(material.getValues()); DEFAULT_MATERIAL_MODEL.setTechniqueModel(DEFAULT_TECHNIQUE_MODEL); } diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java index 6fa5be9f..5917edca 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfCreatorV2.java @@ -67,9 +67,9 @@ import de.javagl.jgltf.model.AccessorDatas; import de.javagl.jgltf.model.AccessorModel; import de.javagl.jgltf.model.AnimationModel; -import de.javagl.jgltf.model.AssetModel; import de.javagl.jgltf.model.AnimationModel.Channel; import de.javagl.jgltf.model.AnimationModel.Sampler; +import de.javagl.jgltf.model.AssetModel; import de.javagl.jgltf.model.BufferModel; import de.javagl.jgltf.model.BufferViewModel; import de.javagl.jgltf.model.CameraModel; @@ -85,11 +85,15 @@ import de.javagl.jgltf.model.NamedModelElement; import de.javagl.jgltf.model.NodeModel; import de.javagl.jgltf.model.Optionals; +import de.javagl.jgltf.model.PbrMaterialModel; +import de.javagl.jgltf.model.PbrMaterialModel.AlphaMode; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; import de.javagl.jgltf.model.SceneModel; import de.javagl.jgltf.model.SkinModel; +import de.javagl.jgltf.model.TextureInfoModel; import de.javagl.jgltf.model.TextureModel; import de.javagl.jgltf.model.impl.DefaultNodeModel; -import de.javagl.jgltf.model.v2.MaterialModelV2.AlphaMode; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; /** * A class for creating the {@link GlTF version 2.0 glTF} from a @@ -598,7 +602,7 @@ private Image createImage(ImageModel imageModel) /** * Create the {@link Material} for the given {@link MaterialModel}. - * If the given {@link MaterialModel} is not a {@link MaterialModelV2}, + * If the given {@link MaterialModel} is not a {@link DefaultPbrMaterialModel}, * then a warning is printed and null is returned. * * @param materialModel The {@link MaterialModel} @@ -606,10 +610,10 @@ private Image createImage(ImageModel imageModel) */ private Material createMaterial(MaterialModel materialModel) { - if (materialModel instanceof MaterialModelV2) + if (materialModel instanceof DefaultPbrMaterialModel) { - MaterialModelV2 materialModelV2 = (MaterialModelV2)materialModel; - return createMaterialV2(materialModelV2); + DefaultPbrMaterialModel DefaultPbrMaterialModel = (DefaultPbrMaterialModel)materialModel; + return createMaterialV2(DefaultPbrMaterialModel); } // TODO It should be possible to use a glTF 1.0 material model here logger.severe("Cannot store glTF 1.0 material in glTF 2.0"); @@ -617,12 +621,12 @@ private Material createMaterial(MaterialModel materialModel) } /** - * Create the {@link Material} for the given {@link MaterialModelV2} + * Create the {@link Material} for the given {@link PbrMaterialModel} * - * @param materialModel The {@link MaterialModelV2} + * @param materialModel The {@link PbrMaterialModel} * @return The {@link Material} */ - private Material createMaterialV2(MaterialModelV2 materialModel) + private Material createMaterialV2(PbrMaterialModel materialModel) { Material material = new Material(); transferGltfChildOfRootPropertyElements(materialModel, material); @@ -642,39 +646,59 @@ private Material createMaterialV2(MaterialModelV2 materialModel) } material.setDoubleSided(materialModel.isDoubleSided()); - MaterialPbrMetallicRoughness pbrMetallicRoughness = - new MaterialPbrMetallicRoughness(); - material.setPbrMetallicRoughness(pbrMetallicRoughness); - - pbrMetallicRoughness.setBaseColorFactor( - materialModel.getBaseColorFactor()); - TextureModel baseColorTexture = - materialModel.getBaseColorTexture(); - if (baseColorTexture != null) + PbrMetallicRoughnessModel pbrMetallicRoughnessModel = + materialModel.getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughnessModel != null) { - TextureInfo baseColorTextureInfo = new TextureInfo(); - baseColorTextureInfo.setIndex( - textureIndices.get(baseColorTexture)); - baseColorTextureInfo.setTexCoord( - materialModel.getBaseColorTexcoord()); - pbrMetallicRoughness.setBaseColorTexture(baseColorTextureInfo); - } + MaterialPbrMetallicRoughness pbrMetallicRoughness = + new MaterialPbrMetallicRoughness(); + material.setPbrMetallicRoughness(pbrMetallicRoughness); + + pbrMetallicRoughness.setBaseColorFactor( + pbrMetallicRoughnessModel.getBaseColorFactor()); + + TextureInfoModel baseColorTextureInfoModel = + pbrMetallicRoughnessModel.getBaseColorTextureInfoModel(); + if (baseColorTextureInfoModel != null) + { + TextureModel baseColorTexture = + baseColorTextureInfoModel.getTextureModel(); + if (baseColorTexture != null) + { + TextureInfo baseColorTextureInfo = new TextureInfo(); + baseColorTextureInfo + .setIndex(textureIndices.get(baseColorTexture)); + baseColorTextureInfo + .setTexCoord(baseColorTextureInfoModel.getTexCoord()); + pbrMetallicRoughness + .setBaseColorTexture(baseColorTextureInfo); + } + } + + pbrMetallicRoughness.setMetallicFactor( + pbrMetallicRoughnessModel.getMetallicFactor()); + pbrMetallicRoughness.setRoughnessFactor( + pbrMetallicRoughnessModel.getRoughnessFactor()); + TextureInfoModel metallicRoughnessTextureInfoModel = + pbrMetallicRoughnessModel + .getMetallicRoughnessTextureInfoModel(); + if (metallicRoughnessTextureInfoModel != null) + { + TextureModel metallicRoughnessTexture = + metallicRoughnessTextureInfoModel.getTextureModel(); + if (metallicRoughnessTexture != null) + { + TextureInfo metallicRoughnessTextureInfo = + new TextureInfo(); + metallicRoughnessTextureInfo + .setIndex(textureIndices.get(metallicRoughnessTexture)); + metallicRoughnessTextureInfo.setTexCoord( + metallicRoughnessTextureInfoModel.getTexCoord()); + pbrMetallicRoughness.setMetallicRoughnessTexture( + metallicRoughnessTextureInfo); + } + } - pbrMetallicRoughness.setMetallicFactor( - materialModel.getMetallicFactor()); - pbrMetallicRoughness.setRoughnessFactor( - materialModel.getRoughnessFactor()); - TextureModel metallicRoughnessTexture = - materialModel.getMetallicRoughnessTexture(); - if (metallicRoughnessTexture != null) - { - TextureInfo metallicRoughnessTextureInfo = new TextureInfo(); - metallicRoughnessTextureInfo.setIndex( - textureIndices.get(metallicRoughnessTexture)); - metallicRoughnessTextureInfo.setTexCoord( - materialModel.getMetallicRoughnessTexcoord()); - pbrMetallicRoughness.setMetallicRoughnessTexture( - metallicRoughnessTextureInfo); } TextureModel normalTexture = materialModel.getNormalTexture(); diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java index b58cf7c2..e31b99cc 100644 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java +++ b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/GltfModelCreatorV2.java @@ -85,8 +85,11 @@ import de.javagl.jgltf.model.MeshPrimitiveModel; import de.javagl.jgltf.model.NodeModel; import de.javagl.jgltf.model.Optionals; +import de.javagl.jgltf.model.PbrMaterialModel.AlphaMode; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; import de.javagl.jgltf.model.SceneModel; import de.javagl.jgltf.model.SkinModel; +import de.javagl.jgltf.model.TextureInfoModel; import de.javagl.jgltf.model.TextureModel; import de.javagl.jgltf.model.impl.AbstractModelElement; import de.javagl.jgltf.model.impl.AbstractNamedModelElement; @@ -106,16 +109,19 @@ import de.javagl.jgltf.model.impl.DefaultMeshModel; import de.javagl.jgltf.model.impl.DefaultMeshPrimitiveModel; import de.javagl.jgltf.model.impl.DefaultNodeModel; +import de.javagl.jgltf.model.impl.DefaultNormalTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultOcclusionTextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; +import de.javagl.jgltf.model.impl.DefaultPbrMetallicRoughnessModel; import de.javagl.jgltf.model.impl.DefaultSceneModel; import de.javagl.jgltf.model.impl.DefaultSkinModel; +import de.javagl.jgltf.model.impl.DefaultTextureInfoModel; import de.javagl.jgltf.model.impl.DefaultTextureModel; import de.javagl.jgltf.model.io.Buffers; import de.javagl.jgltf.model.io.GltfAsset; import de.javagl.jgltf.model.io.IO; import de.javagl.jgltf.model.io.MimeTypes; import de.javagl.jgltf.model.io.v2.GltfAssetV2; -import de.javagl.jgltf.model.v2.MaterialModelV2.AlphaMode; -import de.javagl.jgltf.model.v2.gl.Materials; /** * A class that is responsible for filling a {@link DefaultGltfModel} with @@ -373,7 +379,7 @@ private void createMaterialModels() List materials = Optionals.of(gltf.getMaterials()); for (int i = 0; i < materials.size(); i++) { - MaterialModelV2 materialModel = new MaterialModelV2(); + DefaultPbrMaterialModel materialModel = new DefaultPbrMaterialModel(); gltfModel.addMaterialModel(materialModel); } } @@ -963,8 +969,8 @@ private DefaultMeshPrimitiveModel createMeshPrimitiveModel( Integer materialIndex = meshPrimitive.getMaterial(); if (materialIndex != null) { - MaterialModelV2 materialModel = - (MaterialModelV2) gltfModel.getMaterialModel(materialIndex); + DefaultPbrMaterialModel materialModel = + (DefaultPbrMaterialModel) gltfModel.getMaterialModel(materialIndex); meshPrimitiveModel.setMaterialModel(materialModel); } @@ -1154,8 +1160,8 @@ private void initMaterialModels() for (int i = 0; i < materials.size(); i++) { Material material = materials.get(i); - MaterialModelV2 materialModel = - (MaterialModelV2) gltfModel.getMaterialModel(i); + DefaultPbrMaterialModel materialModel = + (DefaultPbrMaterialModel) gltfModel.getMaterialModel(i); transferGltfChildOfRootPropertyElements(material, materialModel); initMaterialModel(materialModel, material); @@ -1163,110 +1169,107 @@ private void initMaterialModels() } /** - * Initialize the given {@link MaterialModelV2} based on the given + * Initialize the given {@link DefaultPbrMaterialModel} based on the given * {@link Material} * - * @param materialModel The {@link MaterialModelV2} + * @param materialModel The {@link DefaultPbrMaterialModel} * @param material The {@link Material} */ private void initMaterialModel( - MaterialModelV2 materialModel, Material material) + DefaultPbrMaterialModel materialModel, Material material) { - MaterialPbrMetallicRoughness pbrMetallicRoughness = - material.getPbrMetallicRoughness(); - if (pbrMetallicRoughness == null) - { - pbrMetallicRoughness = - Materials.createDefaultMaterialPbrMetallicRoughness(); - } - String alphaModeString = material.getAlphaMode(); if (alphaModeString != null) { materialModel.setAlphaMode(AlphaMode.valueOf(alphaModeString)); } - materialModel.setAlphaCutoff( - Optionals.of(material.getAlphaCutoff(), 0.5)); + else + { + materialModel.setAlphaMode(AlphaMode.OPAQUE); + } + materialModel.setAlphaCutoff(Optionals.of( + material.getAlphaCutoff(), + material.defaultAlphaCutoff())); materialModel.setDoubleSided( Boolean.TRUE.equals(material.isDoubleSided())); - TextureInfo baseColorTextureInfo = - pbrMetallicRoughness.getBaseColorTexture(); - if (baseColorTextureInfo != null) - { - int index = baseColorTextureInfo.getIndex(); - TextureModel textureModel = gltfModel.getTextureModel(index); - materialModel.setBaseColorTexture(textureModel); - materialModel.setBaseColorTexcoord( - baseColorTextureInfo.getTexCoord()); - } - double[] baseColorFactor = Optionals.of( - pbrMetallicRoughness.getBaseColorFactor(), - pbrMetallicRoughness.defaultBaseColorFactor()); - materialModel.setBaseColorFactor(baseColorFactor); - - TextureInfo metallicRoughnessTextureInfo = - pbrMetallicRoughness.getMetallicRoughnessTexture(); - if (metallicRoughnessTextureInfo != null) + MaterialPbrMetallicRoughness pbrMetallicRoughness = + material.getPbrMetallicRoughness(); + if (pbrMetallicRoughness != null) { - int index = metallicRoughnessTextureInfo.getIndex(); - TextureModel textureModel = gltfModel.getTextureModel(index); - materialModel.setMetallicRoughnessTexture(textureModel); - materialModel.setMetallicRoughnessTexcoord( - metallicRoughnessTextureInfo.getTexCoord()); + // Create the PbrMetallicRoughnessModel and assign it to the + // material model + DefaultPbrMetallicRoughnessModel pbrMetallicRoughnessModel = + new DefaultPbrMetallicRoughnessModel(); + materialModel.setPbrMetallicRoughnessModel( + pbrMetallicRoughnessModel); + + // Initialize the PbrMetallicRoughnessModel + transferGltfPropertyElements( + pbrMetallicRoughness, pbrMetallicRoughnessModel); + initPbrMetallicRoughness( + pbrMetallicRoughnessModel, pbrMetallicRoughness); } - double metallicFactor = Optionals.of( - pbrMetallicRoughness.getMetallicFactor(), - pbrMetallicRoughness.defaultMetallicFactor()); - materialModel.setMetallicFactor(metallicFactor); - - double roughnessFactor = Optionals.of( - pbrMetallicRoughness.getRoughnessFactor(), - pbrMetallicRoughness.defaultRoughnessFactor()); - materialModel.setRoughnessFactor(roughnessFactor); MaterialNormalTextureInfo normalTextureInfo = material.getNormalTexture(); if (normalTextureInfo != null) { - int index = normalTextureInfo.getIndex(); - TextureModel textureModel = gltfModel.getTextureModel(index); - materialModel.setNormalTexture(textureModel); - materialModel.setNormalTexcoord( - normalTextureInfo.getTexCoord()); + // Create the TextureInfoModel and assign it to the material model + DefaultNormalTextureInfoModel normalTextureInfoModel = + new DefaultNormalTextureInfoModel(); + materialModel.setNormalTextureInfoModel(normalTextureInfoModel); + + // Initialize the TextureInfoModel + transferGltfPropertyElements( + normalTextureInfo, normalTextureInfoModel); + initTextureInfo(normalTextureInfoModel, normalTextureInfo); + // The additional 'scale' property for normals double normalScale = Optionals.of( normalTextureInfo.getScale(), normalTextureInfo.defaultScale()); - materialModel.setNormalScale(normalScale); + normalTextureInfoModel.setScale(normalScale); + } MaterialOcclusionTextureInfo occlusionTextureInfo = material.getOcclusionTexture(); if (occlusionTextureInfo != null) { - int index = occlusionTextureInfo.getIndex(); - TextureModel textureModel = gltfModel.getTextureModel(index); - materialModel.setOcclusionTexture(textureModel); - materialModel.setOcclusionTexcoord( - occlusionTextureInfo.getTexCoord()); + // Create the TextureInfoModel and assign it to the material model + DefaultOcclusionTextureInfoModel occlusionTextureInfoModel = + new DefaultOcclusionTextureInfoModel(); + materialModel.setOcclusionTextureInfoModel( + occlusionTextureInfoModel); + + // Initialize the TextureInfoModel + transferGltfPropertyElements( + occlusionTextureInfo, occlusionTextureInfoModel); + initTextureInfo(occlusionTextureInfoModel, occlusionTextureInfo); + // The additional 'strength' property for occlusion double occlusionStrength = Optionals.of( occlusionTextureInfo.getStrength(), occlusionTextureInfo.defaultStrength()); - materialModel.setOcclusionStrength(occlusionStrength); + occlusionTextureInfoModel.setStrength(occlusionStrength); + } TextureInfo emissiveTextureInfo = material.getEmissiveTexture(); if (emissiveTextureInfo != null) { - int index = emissiveTextureInfo.getIndex(); - TextureModel textureModel = gltfModel.getTextureModel(index); - materialModel.setEmissiveTexture(textureModel); - materialModel.setEmissiveTexcoord( - emissiveTextureInfo.getTexCoord()); + // Create the TextureInfoModel and assign it to the material model + DefaultTextureInfoModel emissiveTextureInfoModel = + new DefaultTextureInfoModel(); + materialModel.setEmissiveTextureInfoModel(emissiveTextureInfoModel); + + // Initialize the TextureInfoModel + transferGltfPropertyElements( + emissiveTextureInfo, emissiveTextureInfoModel); + initTextureInfo(emissiveTextureInfoModel, emissiveTextureInfo); } double[] emissiveFactor = Optionals.of( @@ -1274,6 +1277,83 @@ private void initMaterialModel( material.defaultEmissiveFactor()); materialModel.setEmissiveFactor(emissiveFactor); } + + /** + * Initialize the given {@link PbrMetallicRoughnessModel} based on the + * given {@link MaterialPbrMetallicRoughness}. + * + * @param pbrMetallicRoughnessModel The {@link PbrMetallicRoughnessModel} + * @param pbrMetallicRoughness The {@link MaterialPbrMetallicRoughness} + */ + private void initPbrMetallicRoughness( + DefaultPbrMetallicRoughnessModel pbrMetallicRoughnessModel, + MaterialPbrMetallicRoughness pbrMetallicRoughness) + { + TextureInfo baseColorTextureInfo = + pbrMetallicRoughness.getBaseColorTexture(); + if (baseColorTextureInfo != null) + { + // Create the TextureInfoModel and assign it to the material model + DefaultTextureInfoModel baseColorTextureInfoModel = + new DefaultTextureInfoModel(); + pbrMetallicRoughnessModel.setBaseColorTexture( + baseColorTextureInfoModel); + + // Initialize the TextureInfoModel + transferGltfPropertyElements( + baseColorTextureInfo, baseColorTextureInfoModel); + initTextureInfo(baseColorTextureInfoModel, baseColorTextureInfo); + } + double[] baseColorFactor = Optionals.of( + pbrMetallicRoughness.getBaseColorFactor(), + pbrMetallicRoughness.defaultBaseColorFactor()); + pbrMetallicRoughnessModel.setBaseColorFactor(baseColorFactor); + + TextureInfo metallicRoughnessTextureInfo = + pbrMetallicRoughness.getMetallicRoughnessTexture(); + if (metallicRoughnessTextureInfo != null) + { + // Create the TextureInfoModel and assign it to the material model + DefaultTextureInfoModel metallicRoughnessTextureInfoModel = + new DefaultTextureInfoModel(); + pbrMetallicRoughnessModel.setMetallicRoughnessTextureInfo( + metallicRoughnessTextureInfoModel); + + // Initialize the TextureInfoModel + transferGltfPropertyElements( + metallicRoughnessTextureInfo, + metallicRoughnessTextureInfoModel); + initTextureInfo(metallicRoughnessTextureInfoModel, + metallicRoughnessTextureInfo); + } + + double metallicFactor = Optionals.of( + pbrMetallicRoughness.getMetallicFactor(), + pbrMetallicRoughness.defaultMetallicFactor()); + pbrMetallicRoughnessModel.setMetallicFactor(metallicFactor); + + double roughnessFactor = Optionals.of( + pbrMetallicRoughness.getRoughnessFactor(), + pbrMetallicRoughness.defaultRoughnessFactor()); + pbrMetallicRoughnessModel.setRoughnessFactor(roughnessFactor); + } + + /** + * Initialize the given {@link TextureInfoModel} based on the given + * {@link TextureInfo}. + * + * @param textureInfoModel The {@link TextureInfoModel} + * @param textureInfo The {@link TextureInfo} + */ + private void initTextureInfo(DefaultTextureInfoModel textureInfoModel, + TextureInfo textureInfo) + { + int index = textureInfo.getIndex(); + TextureModel textureModel = gltfModel.getTextureModel(index); + textureInfoModel.setTextureModel(textureModel); + textureInfoModel.setTexCoord(textureInfo.getTexCoord()); + } + /** * Initialize the {@link ExtensionsModel} with the extensions that @@ -1332,7 +1412,7 @@ private static void transferGltfChildOfRootPropertyElements( modelElement.setName(property.getName()); transferGltfPropertyElements(property, modelElement); } - + /** * Returns an array containing the double representations of the given * numbers, or null if the given list is null. diff --git a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/MaterialModelV2.java b/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/MaterialModelV2.java deleted file mode 100644 index e9a480bb..00000000 --- a/jgltf-model/src/main/java/de/javagl/jgltf/model/v2/MaterialModelV2.java +++ /dev/null @@ -1,571 +0,0 @@ -/* - * www.javagl.de - JglTF - * - * Copyright 2015-2017 Marco Hutter - http://www.javagl.de - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -package de.javagl.jgltf.model.v2; - -import de.javagl.jgltf.model.MaterialModel; -import de.javagl.jgltf.model.TextureModel; -import de.javagl.jgltf.model.impl.AbstractNamedModelElement; - -/** - * Implementation of a {@link MaterialModel} for glTF 2.0.
- *
- * Note: This class might be renamed to "PbrBasedMaterialModel" and moved to - * a different package in the future. - */ -public final class MaterialModelV2 extends AbstractNamedModelElement - implements MaterialModel -{ - /** - * Alpha modes - */ - public static enum AlphaMode - { - /** - * Opaque mode - */ - OPAQUE, - - /** - * Masking mode - */ - MASK, - - /** - * Blend mode - */ - BLEND - } - - /** - * The base color factor - */ - private double[] baseColorFactor; - - /** - * The base color texture - */ - private TextureModel baseColorTexture; - - /** - * The texture coordinate set for the base color texture - */ - private Integer baseColorTexcoord; - - /** - * The metallic factor - */ - private double metallicFactor; - - /** - * The roughness factor - */ - private double roughnessFactor; - - /** - * The metallic-roughness texture - */ - private TextureModel metallicRoughnessTexture; - - /** - * The texture coordinate set for the metallic-roughness texture - */ - private Integer metallicRoughnessTexcoord; - - /** - * The normal texture - */ - private TextureModel normalTexture; - - /** - * The texture coordinate set for the normal texture - */ - private Integer normalTexcoord; - - /** - * The normal scale - */ - private double normalScale; - - /** - * The occlusion texture - */ - private TextureModel occlusionTexture; - - /** - * The texture coordinate set for the occlusion texture - */ - private Integer occlusionTexcoord; - - /** - * The occlusion strength - */ - private double occlusionStrength; - - /** - * The emissive texture - */ - private TextureModel emissiveTexture; - - /** - * The texture coordinate set for the emissive texture - */ - private Integer emissiveTexcoord; - - /** - * The emissive factor - */ - private double[] emissiveFactor; - - /** - * The alpha mode - */ - private AlphaMode alphaMode; - - /** - * The alpha cutoff - */ - private double alphaCutoff; - - /** - * Whether the material is double sided - */ - private boolean doubleSided; - - - /** - * Creates a new instance with default values - */ - public MaterialModelV2() - { - baseColorFactor = new double[]{ 1.0, 1.0, 1.0, 1.0 }; - baseColorTexture = null; - baseColorTexcoord = null; - - metallicFactor = 1.0; - roughnessFactor = 1.0; - metallicRoughnessTexture = null; - metallicRoughnessTexcoord = null; - - normalScale = 1.0; - normalTexture = null; - normalTexcoord = null; - - occlusionTexture = null; - occlusionTexcoord = null; - occlusionStrength = 1.0; - - emissiveTexture = null; - emissiveTexcoord = null; - emissiveFactor = new double[]{0.0, 0.0, 0.0 }; - - alphaMode = AlphaMode.OPAQUE; - alphaCutoff = 0.5; - - doubleSided = false; - } - - /** - * Returns the base color factor - * - * @return The base color factor - */ - public double[] getBaseColorFactor() - { - return baseColorFactor; - } - - /** - * Set the base color factor - * - * @param baseColorFactor The base color factor - */ - public void setBaseColorFactor(double[] baseColorFactor) - { - this.baseColorFactor = baseColorFactor; - } - - /** - * Returns the base color texture - * - * @return The base color texture - */ - public TextureModel getBaseColorTexture() - { - return baseColorTexture; - } - - /** - * Set the base color texture - * - * @param baseColorTexture The base color texture - */ - public void setBaseColorTexture(TextureModel baseColorTexture) - { - this.baseColorTexture = baseColorTexture; - } - - /** - * Return the base color texture coordinate set - * - * @return The texture coordinate set - */ - public Integer getBaseColorTexcoord() - { - return baseColorTexcoord; - } - - /** - * Set the base color texture coordinate set - * - * @param baseColorTexcoord The texture coordinate set - */ - public void setBaseColorTexcoord(Integer baseColorTexcoord) - { - this.baseColorTexcoord = baseColorTexcoord; - } - - /** - * Returns the metallic factor - * - * @return The metallic factor - */ - public double getMetallicFactor() - { - return metallicFactor; - } - - /** - * Set the metallic factor - * - * @param metallicFactor The metallic factor - */ - public void setMetallicFactor(double metallicFactor) - { - this.metallicFactor = metallicFactor; - } - - /** - * Returns the roughness factor - * - * @return The roughness factor - */ - public double getRoughnessFactor() - { - return roughnessFactor; - } - - /** - * Set the roughness factor - * - * @param roughnessFactor The roughness factor - */ - public void setRoughnessFactor(double roughnessFactor) - { - this.roughnessFactor = roughnessFactor; - } - - /** - * Returns the metallic-roughness-texture - * - * @return The metallic-roughness texture - */ - public TextureModel getMetallicRoughnessTexture() - { - return metallicRoughnessTexture; - } - - /** - * Set the metallic-roughness-texture - * - * @param metallicRoughnessTexture The metallic-roughness-texture - */ - public void setMetallicRoughnessTexture( - TextureModel metallicRoughnessTexture) - { - this.metallicRoughnessTexture = metallicRoughnessTexture; - } - - /** - * Returns the metallic-roughness texture coordinate set - * - * @return The texture coordinate set - */ - public Integer getMetallicRoughnessTexcoord() - { - return metallicRoughnessTexcoord; - } - - /** - * Set the metallic-roughness texture coordinate set - * - * @param metallicRoughnessTexcoord The texture coordinate set - */ - public void setMetallicRoughnessTexcoord(Integer metallicRoughnessTexcoord) - { - this.metallicRoughnessTexcoord = metallicRoughnessTexcoord; - } - - /** - * Returns the normal texture - * - * @return The normal texture - */ - public TextureModel getNormalTexture() - { - return normalTexture; - } - - /** - * Set the normal texture - * - * @param normalTexture The normal texture - */ - public void setNormalTexture(TextureModel normalTexture) - { - this.normalTexture = normalTexture; - } - - /** - * Returns the normal texture coordinate set - * - * @return The texture coordinate set - */ - public Integer getNormalTexcoord() - { - return normalTexcoord; - } - - /** - * Set the normal texture coordinate set - * - * @param normalTexcoord The texture coordinate set - */ - public void setNormalTexcoord(Integer normalTexcoord) - { - this.normalTexcoord = normalTexcoord; - } - - /** - * Returns the normal scale - * - * @return The normal scale - */ - public double getNormalScale() - { - return normalScale; - } - - /** - * Set the normal scale - * - * @param normalScale The normal scale - */ - public void setNormalScale(double normalScale) - { - this.normalScale = normalScale; - } - - /** - * Returns the occlusion texture - * - * @return The occlusion texture - */ - public TextureModel getOcclusionTexture() - { - return occlusionTexture; - } - - /** - * Set the occlusion texture - * - * @param occlusionTexture The occlusion texture - */ - public void setOcclusionTexture(TextureModel occlusionTexture) - { - this.occlusionTexture = occlusionTexture; - } - - /** - * Returns the occlusion texture coordinate set - * - * @return The texture coordinate set - */ - public Integer getOcclusionTexcoord() - { - return occlusionTexcoord; - } - - /** - * Set the occlusion texture coordinate set - * - * @param occlusionTexcoord The texture coordinate set - */ - public void setOcclusionTexcoord(Integer occlusionTexcoord) - { - this.occlusionTexcoord = occlusionTexcoord; - } - - /** - * Returns the occlusion strength - * - * @return The occlusion strength - */ - public double getOcclusionStrength() - { - return occlusionStrength; - } - - /** - * Set the occlusion strength - * - * @param occlusionStrength The occlusion strength - */ - public void setOcclusionStrength(double occlusionStrength) - { - this.occlusionStrength = occlusionStrength; - } - - /** - * Returns the emissive texture - * - * @return The emissive texture - */ - public TextureModel getEmissiveTexture() - { - return emissiveTexture; - } - - /** - * Set the emissive texture - * - * @param emissiveTexture The emissive texture - */ - public void setEmissiveTexture(TextureModel emissiveTexture) - { - this.emissiveTexture = emissiveTexture; - } - - /** - * Set the emissive texture coordinate set - * - * @return The texture coordinate set - */ - public Integer getEmissiveTexcoord() - { - return emissiveTexcoord; - } - - /** - * Set the emissive texture coordinate set - * - * @param emissiveTexcoord The texture coordinate set - */ - public void setEmissiveTexcoord(Integer emissiveTexcoord) - { - this.emissiveTexcoord = emissiveTexcoord; - } - - /** - * Returns the emissive factor - * - * @return The emissive factor - */ - public double[] getEmissiveFactor() - { - return emissiveFactor; - } - - /** - * Set the emissive factor - * - * @param emissiveFactor The emissive factor - */ - public void setEmissiveFactor(double[] emissiveFactor) - { - this.emissiveFactor = emissiveFactor; - } - - /** - * Returns the alpha mode - * - * @return The alpha mode - */ - public AlphaMode getAlphaMode() - { - return alphaMode; - } - - /** - * Set the alpha mode - * - * @param alphaMode The alpha mode - */ - public void setAlphaMode(AlphaMode alphaMode) - { - this.alphaMode = alphaMode; - } - - /** - * Returns the alpha cutoff - * - * @return The alpha cutoff - */ - public double getAlphaCutoff() - { - return alphaCutoff; - } - - /** - * Set the alpha cutoff - * - * @param alphaCutoff The alpha cutoff - */ - public void setAlphaCutoff(double alphaCutoff) - { - this.alphaCutoff = alphaCutoff; - } - - /** - * Returns whether the material is double sided - * - * @return Whether the material is double sided - */ - public boolean isDoubleSided() - { - return doubleSided; - } - - /** - * Set whether the material is double sided - * - * @param doubleSided Whether the material is double sided - */ - public void setDoubleSided(boolean doubleSided) - { - this.doubleSided = doubleSided; - } -} diff --git a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV1.java b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV1.java index fc47d14d..0f10bc71 100644 --- a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV1.java +++ b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV1.java @@ -30,13 +30,13 @@ import de.javagl.jgltf.model.MaterialModel; import de.javagl.jgltf.model.TextureModel; -import de.javagl.jgltf.model.v1.MaterialModelV1; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.obj.Mtl; import de.javagl.obj.ReadableObj; /** * Implementation of a {@link MtlMaterialHandler} that generates - * {@link MaterialModelV1} instances + * {@link DefaultTechniqueMaterialModel} instances */ class MtlMaterialHandlerV1 implements MtlMaterialHandler { @@ -81,7 +81,7 @@ public MaterialModel createMaterial(ReadableObj obj, Mtl mtl) private MaterialModel createMaterialWithTexture( boolean withNormals, Mtl mtl) { - MaterialModelV1 materialModelV1 = new MaterialModelV1(); + DefaultTechniqueMaterialModel materialModelV1 = new DefaultTechniqueMaterialModel(); if (withNormals) { materialModelV1.setTechniqueModel( @@ -107,7 +107,7 @@ private MaterialModel createMaterialWithTexture( public MaterialModel createMaterialWithColor(boolean withNormals, double r, double g, double b) { - MaterialModelV1 materialModelV1 = new MaterialModelV1(); + DefaultTechniqueMaterialModel materialModelV1 = new DefaultTechniqueMaterialModel(); if (withNormals) { materialModelV1.setTechniqueModel( diff --git a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV2.java b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV2.java index b2d4e8a6..3e0c5885 100644 --- a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV2.java +++ b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialHandlerV2.java @@ -27,15 +27,17 @@ package de.javagl.jgltf.obj.model; import de.javagl.jgltf.model.MaterialModel; +import de.javagl.jgltf.model.PbrMaterialModel.AlphaMode; import de.javagl.jgltf.model.TextureModel; -import de.javagl.jgltf.model.v2.MaterialModelV2; -import de.javagl.jgltf.model.v2.MaterialModelV2.AlphaMode; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; +import de.javagl.jgltf.model.impl.DefaultPbrMetallicRoughnessModel; +import de.javagl.jgltf.model.impl.DefaultTextureInfoModel; import de.javagl.obj.FloatTuple; import de.javagl.obj.Mtl; import de.javagl.obj.ReadableObj; /** - * A class for providing {@link MaterialModelV2} instances that are used when + * A class for providing {@link DefaultPbrMaterialModel} instances that are used when * converting an OBJ into a glTF model. */ class MtlMaterialHandlerV2 implements MtlMaterialHandler @@ -65,7 +67,7 @@ public MaterialModel createMaterial(ReadableObj obj, Mtl mtl) { return createMaterialWithTexture(mtl); } - MaterialModelV2 material = createMaterialWithColor( + DefaultPbrMaterialModel material = createMaterialWithColor( true, 0.75f, 0.75f, 0.75f); if (mtl == null) { @@ -91,13 +93,16 @@ public MaterialModel createMaterial(ReadableObj obj, Mtl mtl) material.setAlphaMode(AlphaMode.BLEND); } } - material.setBaseColorFactor(baseColorFactor); - + + DefaultPbrMetallicRoughnessModel metallicRoughness = + new DefaultPbrMetallicRoughnessModel(); + metallicRoughness.setBaseColorFactor(baseColorFactor); Float shininess = mtl.getNs(); if (shininess != null) { - material.setMetallicFactor(shininess / 128f); + metallicRoughness.setMetallicFactor(shininess / 128f); } + material.setPbrMetallicRoughnessModel(metallicRoughness); material.setDoubleSided(true); return material; @@ -118,21 +123,35 @@ private MaterialModel createMaterialWithTexture(Mtl mtl) TextureModel textureModel = textureModelHandler.getTextureModel(imageUri); - MaterialModelV2 material = new MaterialModelV2(); - material.setBaseColorTexture(textureModel); - material.setMetallicFactor(0.0f); + DefaultPbrMaterialModel material = new DefaultPbrMaterialModel(); + DefaultPbrMetallicRoughnessModel metallicRoughness = + new DefaultPbrMetallicRoughnessModel(); + material.setPbrMetallicRoughnessModel(metallicRoughness); + + DefaultTextureInfoModel textureInfo = new DefaultTextureInfoModel(); + textureInfo.setTextureModel(textureModel); + metallicRoughness.setBaseColorTexture(textureInfo); + + metallicRoughness.setMetallicFactor(0.0f); + metallicRoughness.setRoughnessFactor(1.0f); + material.setDoubleSided(true); return material; } @Override - public MaterialModelV2 createMaterialWithColor( + public DefaultPbrMaterialModel createMaterialWithColor( boolean withNormals, double r, double g, double b) { - MaterialModelV2 material = new MaterialModelV2(); - material.setRoughnessFactor(0.0f); - material.setMetallicFactor(0.0f); - material.setBaseColorFactor(new double[] { r, g, b, 1.0f }); + DefaultPbrMaterialModel material = new DefaultPbrMaterialModel(); + + DefaultPbrMetallicRoughnessModel metallicRoughness = + new DefaultPbrMetallicRoughnessModel(); + material.setPbrMetallicRoughnessModel(metallicRoughness); + + metallicRoughness.setMetallicFactor(0.0f); + metallicRoughness.setRoughnessFactor(1.0f); + metallicRoughness.setBaseColorFactor(new double[] { r, g, b, 1.0f }); material.setDoubleSided(true); return material; } diff --git a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialValues.java b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialValues.java index f2b7261e..9f2ea9f5 100644 --- a/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialValues.java +++ b/jgltf-obj/src/main/java/de/javagl/jgltf/obj/model/MtlMaterialValues.java @@ -35,19 +35,19 @@ import de.javagl.jgltf.model.TextureModel; import de.javagl.jgltf.model.gl.TechniqueModel; -import de.javagl.jgltf.model.v1.MaterialModelV1; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.obj.FloatTuple; import de.javagl.obj.FloatTuples; import de.javagl.obj.Mtl; /** - * Methods to create the {@link MaterialModelV1#getValues() material values} + * Methods to create the {@link DefaultTechniqueMaterialModel#getValues() material values} * from an MTL */ class MtlMaterialValues { /** - * Create the {@link MaterialModelV1#getValues() material values} for the + * Create the {@link DefaultTechniqueMaterialModel#getValues() material values} for the * given MTL data, matching to the {@link TechniqueModel} instances that * are contained in the {@link ObjTechniqueModels} * diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java index e3efe264..150c4cf0 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/DefaultRenderedGltfModel.java @@ -57,9 +57,9 @@ import de.javagl.jgltf.model.gl.TechniqueStatesFunctionsModel; import de.javagl.jgltf.model.gl.TechniqueStatesModel; import de.javagl.jgltf.model.gl.impl.TechniqueStatesModels; -import de.javagl.jgltf.model.v1.MaterialModelV1; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; +import de.javagl.jgltf.model.impl.DefaultTechniqueMaterialModel; import de.javagl.jgltf.model.v1.gl.DefaultModels; -import de.javagl.jgltf.model.v2.MaterialModelV2; import de.javagl.jgltf.viewer.Morphing.MorphableAttribute; /** @@ -279,25 +279,25 @@ private RenderedMaterial obtainRenderedMaterial( { if (materialModel == null) { - MaterialModelV1 defaultMaterialModel = - (MaterialModelV1) DefaultModels.getDefaultMaterialModel(); + DefaultTechniqueMaterialModel defaultMaterialModel = + (DefaultTechniqueMaterialModel) DefaultModels.getDefaultMaterialModel(); TechniqueModel techniqueModel = defaultMaterialModel.getTechniqueModel(); Map values = defaultMaterialModel.getValues(); return new DefaultRenderedMaterial(techniqueModel, values); } - if (materialModel instanceof MaterialModelV1) + if (materialModel instanceof DefaultTechniqueMaterialModel) { - MaterialModelV1 materialModelV1 = (MaterialModelV1)materialModel; + DefaultTechniqueMaterialModel materialModelV1 = (DefaultTechniqueMaterialModel)materialModel; TechniqueModel techniqueModel = materialModelV1.getTechniqueModel(); Map values = materialModelV1.getValues(); return new DefaultRenderedMaterial(techniqueModel, values); } - if (materialModel instanceof MaterialModelV2) + if (materialModel instanceof DefaultPbrMaterialModel) { - MaterialModelV2 materialModelV2 = (MaterialModelV2)materialModel; + DefaultPbrMaterialModel DefaultPbrMaterialModel = (DefaultPbrMaterialModel)materialModel; SkinModel skinModel = nodeModel.getSkinModel(); int numJoints = 0; if (skinModel != null) @@ -305,7 +305,7 @@ private RenderedMaterial obtainRenderedMaterial( numJoints = skinModel.getJoints().size(); } return materialModelHandler.createRenderedMaterial( - materialModelV2, numJoints); + DefaultPbrMaterialModel, numJoints); } logger.severe("Unknown material model type: " + materialModel); return null; diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MaterialStructure.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MaterialStructure.java index 5c71d010..e8b55e4f 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MaterialStructure.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/MaterialStructure.java @@ -28,7 +28,11 @@ import java.util.Objects; -import de.javagl.jgltf.model.v2.MaterialModelV2; +import de.javagl.jgltf.model.Optionals; +import de.javagl.jgltf.model.PbrMaterialModel; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; +import de.javagl.jgltf.model.TextureInfoModel; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; /** * A simple (package-private!) class describing the structure of a material. @@ -71,10 +75,10 @@ class MaterialStructure /** * Default constructor * - * @param material The {@link MaterialModelV2} + * @param material The {@link DefaultPbrMaterialModel} * @param numJoints The number of joints */ - MaterialStructure(MaterialModelV2 material, int numJoints) + MaterialStructure(PbrMaterialModel material, int numJoints) { this.baseColorTexCoordSemantic = getTexCoordSemantic(material.getBaseColorTexcoord()); diff --git a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedMaterialHandler.java b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedMaterialHandler.java index 58d8a76a..f94812e8 100644 --- a/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedMaterialHandler.java +++ b/jgltf-viewer/src/main/java/de/javagl/jgltf/viewer/RenderedMaterialHandler.java @@ -37,6 +37,9 @@ import de.javagl.jgltf.model.GltfConstants; import de.javagl.jgltf.model.NodeModel; +import de.javagl.jgltf.model.NormalTextureInfoModel; +import de.javagl.jgltf.model.OcclusionTextureInfoModel; +import de.javagl.jgltf.model.PbrMetallicRoughnessModel; import de.javagl.jgltf.model.TextureModel; import de.javagl.jgltf.model.gl.ProgramModel; import de.javagl.jgltf.model.gl.ShaderModel; @@ -49,13 +52,13 @@ import de.javagl.jgltf.model.gl.impl.DefaultTechniqueModel; import de.javagl.jgltf.model.gl.impl.DefaultTechniqueParametersModel; import de.javagl.jgltf.model.gl.impl.TechniqueStatesModels; +import de.javagl.jgltf.model.impl.DefaultPbrMaterialModel; import de.javagl.jgltf.model.io.Buffers; import de.javagl.jgltf.model.io.IO; -import de.javagl.jgltf.model.v2.MaterialModelV2; /** * A class for creating the {@link RenderedMaterial} instances for glTF 2.0 - * {@link MaterialModelV2} objects.
+ * {@link DefaultPbrMaterialModel} objects.
*
* It will lazily create the internal {@link TechniqueModel}, * {@link ProgramModel} and {@link ShaderModel} instances that @@ -246,14 +249,14 @@ private TechniqueModel createTechniqueModel( /** * Create a {@link RenderedMaterial} instance for the given - * {@link MaterialModelV2} + * {@link DefaultPbrMaterialModel} * - * @param material The {@link MaterialModelV2} + * @param material The {@link DefaultPbrMaterialModel} * @param numJoints The number of joints * @return The {@link RenderedMaterial} */ RenderedMaterial createRenderedMaterial( - MaterialModelV2 material, int numJoints) + DefaultPbrMaterialModel material, int numJoints) { MaterialStructure materialStructure = new MaterialStructure(material, numJoints); @@ -271,6 +274,7 @@ RenderedMaterial createRenderedMaterial( values.put("isDoubleSided", 0); } + TextureModel baseColorTexture = material.getBaseColorTexture(); if (baseColorTexture != null) @@ -284,8 +288,15 @@ RenderedMaterial createRenderedMaterial( { values.put("hasBaseColorTexture", 0); } - double[] baseColorFactor = material.getBaseColorFactor(); - values.put("baseColorFactor", baseColorFactor); + + double[] baseColorFactor = new double[] { 1.0, 1.0, 1.0, 1.0 }; + PbrMetallicRoughnessModel pbrMetallicRoughness = + material.getPbrMetallicRoughnessModel(); + if (pbrMetallicRoughness != null) + { + baseColorFactor = pbrMetallicRoughness.getBaseColorFactor(); + values.put("baseColorFactor", baseColorFactor); + } TextureModel metallicRoughnessTexture = @@ -301,10 +312,14 @@ RenderedMaterial createRenderedMaterial( { values.put("hasMetallicRoughnessTexture", 0); } - double metallicFactor = material.getMetallicFactor(); + double metallicFactor = 1.0; + double roughnessFactor = 1.0; + if (pbrMetallicRoughness != null) + { + metallicFactor = pbrMetallicRoughness.getMetallicFactor(); + roughnessFactor = pbrMetallicRoughness.getRoughnessFactor(); + } values.put("metallicFactor", metallicFactor); - - double roughnessFactor = material.getRoughnessFactor(); values.put("roughnessFactor", roughnessFactor); @@ -317,7 +332,9 @@ RenderedMaterial createRenderedMaterial( materialStructure.getNormalTexCoordSemantic()); values.put("normalTexture", normalTexture); - double normalScale = material.getNormalScale(); + NormalTextureInfoModel normalTextureInfo = + material.getNormalTextureInfoModel(); + double normalScale = normalTextureInfo.getScale(); values.put("normalScale", normalScale); } else @@ -335,7 +352,9 @@ RenderedMaterial createRenderedMaterial( materialStructure.getOcclusionTexCoordSemantic()); values.put("occlusionTexture", occlusionTexture); - double occlusionStrength = material.getOcclusionStrength(); + OcclusionTextureInfoModel occlusionTextureInfo = + material.getOcclusionTextureInfoModel(); + double occlusionStrength = occlusionTextureInfo.getStrength(); values.put("occlusionStrength", occlusionStrength); } else