Skip to content

Commit 62dc29b

Browse files
authored
Gltf unlit (#1463)
* Adds support for the Unlit material in the GLTF loader. * Adds some author information. * Removes an unnecessary test. It was left over from development and inevitably fails. TestGLTFUnlit serves as a good enough test anyway. * Adds the copyright notice to TestGltfUnlit.
1 parent 73cf6c3 commit 62dc29b

File tree

8 files changed

+460
-1
lines changed

8 files changed

+460
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2009-2019 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package jme3test.light;
33+
34+
import com.jme3.app.SimpleApplication;
35+
import com.jme3.input.controls.ActionListener;
36+
import com.jme3.math.ColorRGBA;
37+
import com.jme3.math.Vector3f;
38+
39+
/**
40+
* Tests the GLTF scene containing an unlit material. If it works, it should use the
41+
* Common/MatDefs/Misc/Unshaded.j3md material definition for those objects.
42+
*
43+
* @author Markil 3
44+
* @version 3.3.0-SNAPSHOT
45+
*/
46+
public class TestGltfUnlit extends SimpleApplication implements ActionListener {
47+
public static void main(String[] args) {
48+
TestGltfUnlit testUnlit = new TestGltfUnlit();
49+
testUnlit.start();
50+
}
51+
52+
@Override
53+
public void simpleInitApp() {
54+
55+
ColorRGBA skyColor = new ColorRGBA(0.5f, 0.6f, 0.7f, 0.0f);
56+
57+
flyCam.setMoveSpeed(20);
58+
viewPort.setBackgroundColor(skyColor.mult(0.9f));
59+
60+
this.cam.setLocation(new Vector3f(0, 10, 20));
61+
this.rootNode.attachChild(this.getAssetManager().loadModel("jme3test/scenes/unlit.gltf"));
62+
}
63+
64+
@Override
65+
public void onAction(String name, boolean isPressed, float tpf) {
66+
}
67+
}
6.86 KB
Binary file not shown.
783 KB
Binary file not shown.
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
{
2+
"asset" : {
3+
"generator" : "Khronos glTF Blender I/O v1.4.40",
4+
"version" : "2.0",
5+
"author" : "Markil 3"
6+
},
7+
"extensionsUsed" : [
8+
"KHR_materials_unlit"
9+
],
10+
"scene" : 0,
11+
"scenes" : [
12+
{
13+
"name" : "Scene",
14+
"nodes" : [
15+
0,
16+
1,
17+
2,
18+
3
19+
]
20+
}
21+
],
22+
"nodes" : [
23+
{
24+
"name" : "Light",
25+
"rotation" : [
26+
0.16907575726509094,
27+
0.7558803558349609,
28+
-0.27217137813568115,
29+
0.570947527885437
30+
],
31+
"translation" : [
32+
0.851825475692749,
33+
8.599525451660156,
34+
-0.8687540292739868
35+
]
36+
},
37+
{
38+
"name" : "Camera",
39+
"rotation" : [
40+
0.483536034822464,
41+
0.33687159419059753,
42+
-0.20870360732078552,
43+
0.7804827094078064
44+
],
45+
"translation" : [
46+
7.358891487121582,
47+
4.958309173583984,
48+
6.925790786743164
49+
]
50+
},
51+
{
52+
"mesh" : 0,
53+
"name" : "Plane",
54+
"scale" : [
55+
13.14516544342041,
56+
13.14516544342041,
57+
13.14516544342041
58+
]
59+
},
60+
{
61+
"mesh" : 1,
62+
"name" : "Cylinder",
63+
"translation" : [
64+
0,
65+
5.575394630432129,
66+
0
67+
]
68+
}
69+
],
70+
"materials" : [
71+
{
72+
"doubleSided" : true,
73+
"extensions" : {
74+
"KHR_materials_unlit" : {}
75+
},
76+
"name" : "Shadeless",
77+
"pbrMetallicRoughness" : {
78+
"baseColorFactor" : [
79+
1,
80+
0.012044749222695827,
81+
0,
82+
1
83+
],
84+
"metallicFactor" : 0,
85+
"roughnessFactor" : 0.9
86+
}
87+
}
88+
],
89+
"meshes" : [
90+
{
91+
"name" : "Plane",
92+
"primitives" : [
93+
{
94+
"attributes" : {
95+
"POSITION" : 0,
96+
"NORMAL" : 1,
97+
"TEXCOORD_0" : 2
98+
},
99+
"indices" : 3
100+
}
101+
]
102+
},
103+
{
104+
"name" : "Cylinder",
105+
"primitives" : [
106+
{
107+
"attributes" : {
108+
"POSITION" : 4,
109+
"NORMAL" : 5,
110+
"TEXCOORD_0" : 6
111+
},
112+
"indices" : 7,
113+
"material" : 0
114+
}
115+
]
116+
}
117+
],
118+
"accessors" : [
119+
{
120+
"bufferView" : 0,
121+
"componentType" : 5126,
122+
"count" : 4,
123+
"max" : [
124+
1,
125+
0,
126+
1
127+
],
128+
"min" : [
129+
-1,
130+
0,
131+
-1
132+
],
133+
"type" : "VEC3"
134+
},
135+
{
136+
"bufferView" : 1,
137+
"componentType" : 5126,
138+
"count" : 4,
139+
"type" : "VEC3"
140+
},
141+
{
142+
"bufferView" : 2,
143+
"componentType" : 5126,
144+
"count" : 4,
145+
"type" : "VEC2"
146+
},
147+
{
148+
"bufferView" : 3,
149+
"componentType" : 5123,
150+
"count" : 6,
151+
"type" : "SCALAR"
152+
},
153+
{
154+
"bufferView" : 4,
155+
"componentType" : 5126,
156+
"count" : 192,
157+
"max" : [
158+
1,
159+
1,
160+
1
161+
],
162+
"min" : [
163+
-1,
164+
-1,
165+
-1
166+
],
167+
"type" : "VEC3"
168+
},
169+
{
170+
"bufferView" : 5,
171+
"componentType" : 5126,
172+
"count" : 192,
173+
"type" : "VEC3"
174+
},
175+
{
176+
"bufferView" : 6,
177+
"componentType" : 5126,
178+
"count" : 192,
179+
"type" : "VEC2"
180+
},
181+
{
182+
"bufferView" : 7,
183+
"componentType" : 5123,
184+
"count" : 372,
185+
"type" : "SCALAR"
186+
}
187+
],
188+
"bufferViews" : [
189+
{
190+
"buffer" : 0,
191+
"byteLength" : 48,
192+
"byteOffset" : 0
193+
},
194+
{
195+
"buffer" : 0,
196+
"byteLength" : 48,
197+
"byteOffset" : 48
198+
},
199+
{
200+
"buffer" : 0,
201+
"byteLength" : 32,
202+
"byteOffset" : 96
203+
},
204+
{
205+
"buffer" : 0,
206+
"byteLength" : 12,
207+
"byteOffset" : 128
208+
},
209+
{
210+
"buffer" : 0,
211+
"byteLength" : 2304,
212+
"byteOffset" : 140
213+
},
214+
{
215+
"buffer" : 0,
216+
"byteLength" : 2304,
217+
"byteOffset" : 2444
218+
},
219+
{
220+
"buffer" : 0,
221+
"byteLength" : 1536,
222+
"byteOffset" : 4748
223+
},
224+
{
225+
"buffer" : 0,
226+
"byteLength" : 744,
227+
"byteOffset" : 6284
228+
}
229+
],
230+
"buffers" : [
231+
{
232+
"byteLength" : 7028,
233+
"uri" : "unlit.bin"
234+
}
235+
]
236+
}

jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/CustomContentManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class CustomContentManager {
5555

5656
static {
5757
defaultExtensionLoaders.put("KHR_materials_pbrSpecularGlossiness", new PBRSpecGlossExtensionLoader());
58+
defaultExtensionLoaders.put("KHR_materials_unlit", new UnlitExtensionLoader());
5859
}
5960

6061
void init(GltfLoader gltfLoader) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2009-2020 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.scene.plugins.gltf;
33+
34+
import com.google.gson.JsonElement;
35+
import com.jme3.asset.AssetKey;
36+
37+
import java.io.IOException;
38+
39+
import static com.jme3.scene.plugins.gltf.GltfUtils.getAsColor;
40+
import static com.jme3.scene.plugins.gltf.GltfUtils.getAsFloat;
41+
42+
/**
43+
* Material adapter for the Unlit pipeline
44+
* @author Markil 3
45+
*/
46+
public class UnlitExtensionLoader implements ExtensionLoader {
47+
48+
private final UnlitMaterialAdapter materialAdapter = new UnlitMaterialAdapter();
49+
50+
@Override
51+
public Object handleExtension(GltfLoader loader, String parentName, JsonElement parent, JsonElement extension, Object input) {
52+
MaterialAdapter adapter = materialAdapter;
53+
AssetKey key = loader.getInfo().getKey();
54+
//check for a custom adapter for spec/gloss pipeline
55+
if (key instanceof GltfModelKey) {
56+
GltfModelKey gltfKey = (GltfModelKey) key;
57+
MaterialAdapter ma = gltfKey.getAdapterForMaterial("unlit");
58+
if (ma != null) {
59+
adapter = ma;
60+
}
61+
}
62+
63+
adapter.init(loader.getInfo().getManager());
64+
65+
return adapter;
66+
}
67+
}

0 commit comments

Comments
 (0)