forked from jMonkeyEngine/jmonkeyengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGltfNormal.java
More file actions
89 lines (73 loc) · 3.35 KB
/
TestGltfNormal.java
File metadata and controls
89 lines (73 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package jme3test.model;
import com.jme3.app.*;
import com.jme3.asset.TextureKey;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.light.AmbientLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.*;
import com.jme3.scene.plugins.gltf.GltfModelKey;
import com.jme3.system.AppSettings;
import com.jme3.util.TangentBinormalGenerator;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;
public class TestGltfNormal extends SimpleApplication {
Node probeNode;
PointLight light;
boolean flipTextures = !false;
public static void main(String[] args) {
AppSettings sett = new AppSettings(true);
sett.setWidth(1024);
sett.setHeight(768);
TestGltfNormal app = new TestGltfNormal();
app.setSettings(sett);
app.start();
}
@Override
public void simpleInitApp() {
assetManager.registerLocator(System.getProperty("user.home")+"/Downloads", FileLocator.class);
assetManager.registerLocator(System.getProperty("user.home")+"/java/prj/JmeUtils/assets/Models", FileLocator.class);
rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
probeNode = (Node) assetManager.loadModel("Scenes/defaultProbe.j3o");
//probeNode = new Node();
rootNode.attachChild(probeNode);
setPauseOnLostFocus(false);
//flyCam.setEnabled(false);
flyCam.setMoveSpeed(20);
viewPort.setBackgroundColor(new ColorRGBA().setAsSrgb(0.2f, 0.2f, 0.2f, 1.0f));
loadModel("NormalTangentMirrorTest_FromObj.j3o", new Vector3f(0, 0, 0), 3);
probeNode.addLight(new AmbientLight(ColorRGBA.Gray));
light = new PointLight(new Vector3f(-1f, 1f, 10f), ColorRGBA.White, 1000f);
rootNode.addLight(light);
}
@Override
public void simpleUpdate(float tpf) {
light.setPosition(cam.getLocation());
}
private void loadModel(String path, Vector3f offset, float scale) {
GltfModelKey k = new GltfModelKey(path);
Spatial s = assetManager.loadModel(k);
s.scale(scale);
s.move(offset);
s.setMaterial(createPBRLightingMat());
//s.setMaterial(createSPLightingMat());
//TangentBinormalGenerator.generate(s);
MikktspaceTangentGenerator.generate(s);
probeNode.attachChild(s);
}
private Material createPBRLightingMat() {
Material mat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
mat.setTexture("BaseColorMap", assetManager.loadTexture(new TextureKey("NormalTangentMirrorTest_BaseColor.png", flipTextures)));
mat.setTexture("NormalMap", assetManager.loadTexture(new TextureKey("NormalTangentTest_Normal.png", flipTextures)));
return mat;
}
private Material createSPLightingMat() {
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", assetManager.loadTexture(new TextureKey("NormalTangentMirrorTest_BaseColor.png", flipTextures)));
mat.setTexture("NormalMap", assetManager.loadTexture(new TextureKey("NormalTangentTest_Normal.png", flipTextures)));
mat.setBoolean("VertexLighting", false);
return mat;
}
}