-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Gltf unlit #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Gltf unlit #1463
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
jme3-examples/src/main/java/jme3test/light/TestGltfUnlit.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2009-2019 jMonkeyEngine | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
| * may be used to endorse or promote products derived from this software | ||
| * without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package jme3test.light; | ||
|
|
||
| import com.jme3.app.SimpleApplication; | ||
| import com.jme3.input.controls.ActionListener; | ||
| import com.jme3.math.ColorRGBA; | ||
| import com.jme3.math.Vector3f; | ||
|
|
||
| /** | ||
| * Tests the GLTF scene containing an unlit material. If it works, it should use the | ||
| * Common/MatDefs/Misc/Unshaded.j3md material definition for those objects. | ||
| * | ||
| * @author Markil 3 | ||
| * @version 3.3.0-SNAPSHOT | ||
| */ | ||
| public class TestGltfUnlit extends SimpleApplication implements ActionListener { | ||
| public static void main(String[] args) { | ||
| TestGltfUnlit testUnlit = new TestGltfUnlit(); | ||
| testUnlit.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void simpleInitApp() { | ||
|
|
||
| ColorRGBA skyColor = new ColorRGBA(0.5f, 0.6f, 0.7f, 0.0f); | ||
|
|
||
| flyCam.setMoveSpeed(20); | ||
| viewPort.setBackgroundColor(skyColor.mult(0.9f)); | ||
|
|
||
| this.cam.setLocation(new Vector3f(0, 10, 20)); | ||
| this.rootNode.attachChild(this.getAssetManager().loadModel("jme3test/scenes/unlit.gltf")); | ||
| } | ||
|
|
||
| @Override | ||
| public void onAction(String name, boolean isPressed, float tpf) { | ||
| } | ||
| } | ||
Binary file not shown.
Binary file not shown.
236 changes: 236 additions & 0 deletions
236
jme3-examples/src/main/resources/jme3test/scenes/unlit.gltf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| { | ||
| "asset" : { | ||
| "generator" : "Khronos glTF Blender I/O v1.4.40", | ||
| "version" : "2.0", | ||
| "author" : "Markil 3" | ||
| }, | ||
| "extensionsUsed" : [ | ||
| "KHR_materials_unlit" | ||
| ], | ||
| "scene" : 0, | ||
| "scenes" : [ | ||
| { | ||
| "name" : "Scene", | ||
| "nodes" : [ | ||
| 0, | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ] | ||
| } | ||
| ], | ||
| "nodes" : [ | ||
| { | ||
| "name" : "Light", | ||
| "rotation" : [ | ||
| 0.16907575726509094, | ||
| 0.7558803558349609, | ||
| -0.27217137813568115, | ||
| 0.570947527885437 | ||
| ], | ||
| "translation" : [ | ||
| 0.851825475692749, | ||
| 8.599525451660156, | ||
| -0.8687540292739868 | ||
| ] | ||
| }, | ||
| { | ||
| "name" : "Camera", | ||
| "rotation" : [ | ||
| 0.483536034822464, | ||
| 0.33687159419059753, | ||
| -0.20870360732078552, | ||
| 0.7804827094078064 | ||
| ], | ||
| "translation" : [ | ||
| 7.358891487121582, | ||
| 4.958309173583984, | ||
| 6.925790786743164 | ||
| ] | ||
| }, | ||
| { | ||
| "mesh" : 0, | ||
| "name" : "Plane", | ||
| "scale" : [ | ||
| 13.14516544342041, | ||
| 13.14516544342041, | ||
| 13.14516544342041 | ||
| ] | ||
| }, | ||
| { | ||
| "mesh" : 1, | ||
| "name" : "Cylinder", | ||
| "translation" : [ | ||
| 0, | ||
| 5.575394630432129, | ||
| 0 | ||
| ] | ||
| } | ||
| ], | ||
| "materials" : [ | ||
| { | ||
| "doubleSided" : true, | ||
| "extensions" : { | ||
| "KHR_materials_unlit" : {} | ||
| }, | ||
| "name" : "Shadeless", | ||
| "pbrMetallicRoughness" : { | ||
| "baseColorFactor" : [ | ||
| 1, | ||
| 0.012044749222695827, | ||
| 0, | ||
| 1 | ||
| ], | ||
| "metallicFactor" : 0, | ||
| "roughnessFactor" : 0.9 | ||
| } | ||
| } | ||
| ], | ||
| "meshes" : [ | ||
| { | ||
| "name" : "Plane", | ||
| "primitives" : [ | ||
| { | ||
| "attributes" : { | ||
| "POSITION" : 0, | ||
| "NORMAL" : 1, | ||
| "TEXCOORD_0" : 2 | ||
| }, | ||
| "indices" : 3 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "name" : "Cylinder", | ||
| "primitives" : [ | ||
| { | ||
| "attributes" : { | ||
| "POSITION" : 4, | ||
| "NORMAL" : 5, | ||
| "TEXCOORD_0" : 6 | ||
| }, | ||
| "indices" : 7, | ||
| "material" : 0 | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "accessors" : [ | ||
| { | ||
| "bufferView" : 0, | ||
| "componentType" : 5126, | ||
| "count" : 4, | ||
| "max" : [ | ||
| 1, | ||
| 0, | ||
| 1 | ||
| ], | ||
| "min" : [ | ||
| -1, | ||
| 0, | ||
| -1 | ||
| ], | ||
| "type" : "VEC3" | ||
| }, | ||
| { | ||
| "bufferView" : 1, | ||
| "componentType" : 5126, | ||
| "count" : 4, | ||
| "type" : "VEC3" | ||
| }, | ||
| { | ||
| "bufferView" : 2, | ||
| "componentType" : 5126, | ||
| "count" : 4, | ||
| "type" : "VEC2" | ||
| }, | ||
| { | ||
| "bufferView" : 3, | ||
| "componentType" : 5123, | ||
| "count" : 6, | ||
| "type" : "SCALAR" | ||
| }, | ||
| { | ||
| "bufferView" : 4, | ||
| "componentType" : 5126, | ||
| "count" : 192, | ||
| "max" : [ | ||
| 1, | ||
| 1, | ||
| 1 | ||
| ], | ||
| "min" : [ | ||
| -1, | ||
| -1, | ||
| -1 | ||
| ], | ||
| "type" : "VEC3" | ||
| }, | ||
| { | ||
| "bufferView" : 5, | ||
| "componentType" : 5126, | ||
| "count" : 192, | ||
| "type" : "VEC3" | ||
| }, | ||
| { | ||
| "bufferView" : 6, | ||
| "componentType" : 5126, | ||
| "count" : 192, | ||
| "type" : "VEC2" | ||
| }, | ||
| { | ||
| "bufferView" : 7, | ||
| "componentType" : 5123, | ||
| "count" : 372, | ||
| "type" : "SCALAR" | ||
| } | ||
| ], | ||
| "bufferViews" : [ | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 48, | ||
| "byteOffset" : 0 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 48, | ||
| "byteOffset" : 48 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 32, | ||
| "byteOffset" : 96 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 12, | ||
| "byteOffset" : 128 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 2304, | ||
| "byteOffset" : 140 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 2304, | ||
| "byteOffset" : 2444 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 1536, | ||
| "byteOffset" : 4748 | ||
| }, | ||
| { | ||
| "buffer" : 0, | ||
| "byteLength" : 744, | ||
| "byteOffset" : 6284 | ||
| } | ||
| ], | ||
| "buffers" : [ | ||
| { | ||
| "byteLength" : 7028, | ||
| "uri" : "unlit.bin" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/UnlitExtensionLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2009-2020 jMonkeyEngine | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
| * may be used to endorse or promote products derived from this software | ||
| * without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.jme3.scene.plugins.gltf; | ||
|
|
||
| import com.google.gson.JsonElement; | ||
| import com.jme3.asset.AssetKey; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static com.jme3.scene.plugins.gltf.GltfUtils.getAsColor; | ||
| import static com.jme3.scene.plugins.gltf.GltfUtils.getAsFloat; | ||
|
|
||
| /** | ||
| * Material adapter for the Unlit pipeline | ||
| * @author Markil 3 | ||
| */ | ||
| public class UnlitExtensionLoader implements ExtensionLoader { | ||
|
|
||
| private final UnlitMaterialAdapter materialAdapter = new UnlitMaterialAdapter(); | ||
|
|
||
| @Override | ||
| public Object handleExtension(GltfLoader loader, String parentName, JsonElement parent, JsonElement extension, Object input) { | ||
| MaterialAdapter adapter = materialAdapter; | ||
| AssetKey key = loader.getInfo().getKey(); | ||
| //check for a custom adapter for spec/gloss pipeline | ||
| if (key instanceof GltfModelKey) { | ||
| GltfModelKey gltfKey = (GltfModelKey) key; | ||
| MaterialAdapter ma = gltfKey.getAdapterForMaterial("unlit"); | ||
| if (ma != null) { | ||
| adapter = ma; | ||
| } | ||
| } | ||
|
|
||
| adapter.init(loader.getInfo().getManager()); | ||
|
|
||
| return adapter; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.