@@ -11,6 +11,7 @@
|
|
11
11
|
import { isDevEnvironment, showBalloonWarning } from "./debug/index.js";
|
12
12
|
import { destroy } from "./engine_gameobject.js";
|
13
13
|
import { hasCommercialLicense } from "./engine_license.js";
|
14
|
+
import { VERSION } from "./engine_constants.js";
|
14
15
|
|
15
16
|
//
|
16
17
|
// registering loader here too to make sure it's imported when using engine via vanilla js
|
@@ -184,6 +185,10 @@
|
|
184
185
|
if (loadId !== this._loadId) return;
|
185
186
|
this.onLoad();
|
186
187
|
}, 1);
|
188
|
+
|
189
|
+
if (VERSION?.length) {
|
190
|
+
this.setAttribute("version", VERSION);
|
191
|
+
}
|
187
192
|
}
|
188
193
|
|
189
194
|
disconnectedCallback() {
|
@@ -39,7 +39,7 @@
|
|
39
39
|
// TODO should the loader be cached here?
|
40
40
|
const loader = new EXRLoader(parser.options.manager);
|
41
41
|
|
42
|
-
if (debug) console.log("EXT_texture_exr.loadTexture", extension
|
42
|
+
if (debug) console.log("EXT_texture_exr.loadTexture", extension);
|
43
43
|
|
44
44
|
const promise = parser.loadTextureImage(textureIndex, extension.source, loader) as Promise<Texture>;
|
45
45
|
return promise;
|
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
export async function resolveReferences(parser: GLTFParser, obj) {
|
30
30
|
if(debug) console.log(parser, obj);
|
31
|
-
const arr: Promise<
|
31
|
+
const arr: Promise<any>[] = [];
|
32
32
|
internalResolve(defaultDependencies, parser, obj, arr);
|
33
33
|
const res = await Promise.all(arr);
|
34
34
|
if (typeof obj === "string" && res.length === 1) return res[0];
|
@@ -36,7 +36,7 @@
|
|
36
36
|
}
|
37
37
|
|
38
38
|
|
39
|
-
function internalResolve(paths: DependencyInfo[], parser: GLTFParser, obj, promises: Promise<
|
39
|
+
function internalResolve(paths: DependencyInfo[], parser: GLTFParser, obj, promises: Promise<any>[]) {
|
40
40
|
if (typeof obj === "object" && obj !== undefined && obj !== null) {
|
41
41
|
for (const key of Object.keys(obj)) {
|
42
42
|
const val = obj[key];
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { ILightDataRegistry } from "../engine_lightdata.js";
|
2
|
-
import { FloatType, HalfFloatType, LinearEncoding, LinearSRGBColorSpace, SRGBColorSpace, sRGBEncoding, Texture } from "three";
|
2
|
+
import { FloatType, HalfFloatType, LinearEncoding, LinearSRGBColorSpace, SRGBColorSpace, sRGBEncoding, Texture, TextureLoader } from "three";
|
3
3
|
import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
|
4
4
|
import { SourceIdentifier } from "../engine_types.js";
|
5
5
|
import { resolveReferences } from "./extension_utils.js";
|
6
|
-
import { getParam } from "../engine_utils.js";
|
6
|
+
import { getParam, resolveUrl } from "../engine_utils.js";
|
7
|
+
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
|
8
|
+
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js";
|
7
9
|
|
8
10
|
// the lightmap extension is aimed to also export export skyboxes and custom reflection maps
|
9
11
|
// should we rename it?
|
@@ -62,30 +64,29 @@
|
|
62
64
|
const dependencies: Array<Promise<any>> = [];
|
63
65
|
for (const entry of arr) {
|
64
66
|
if (entry.pointer) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
dependencies.push(res);
|
67
|
+
let res: Promise<any> | null = null;
|
68
|
+
// Check if the pointer is a json pointer:
|
69
|
+
if (entry.pointer.startsWith("/textures/")) {
|
70
|
+
if (debug) console.log("Load texture from gltf", entry.pointer);
|
71
|
+
res = resolveReferences(this.parser, entry.pointer).then(res => this.resolveTexture(entry, res));
|
72
|
+
}
|
73
|
+
// The pointer can be a string to a file on disc
|
74
|
+
else if (typeof entry.pointer === "string") {
|
75
|
+
if (debug) console.log("Load texture from path", entry.pointer);
|
76
|
+
const path = resolveUrl(this.source, entry.pointer);
|
77
|
+
let loader: TextureLoader | EXRLoader | RGBELoader;
|
78
|
+
if (path.endsWith(".exr"))
|
79
|
+
loader = new EXRLoader(this.parser.options.manager);
|
80
|
+
else if (path.endsWith(".hdr"))
|
81
|
+
loader = new RGBELoader(this.parser.options.manager);
|
82
|
+
else
|
83
|
+
loader = new TextureLoader(this.parser.options.manager);
|
84
|
+
res = loader.loadAsync(path, undefined).then(res => this.resolveTexture(entry, res));
|
85
|
+
}
|
86
|
+
else if (entry.pointer === undefined) {
|
87
|
+
// data is missing?
|
88
|
+
}
|
89
|
+
if (res) dependencies.push(res);
|
89
90
|
}
|
90
91
|
}
|
91
92
|
await Promise.all(dependencies);
|
@@ -96,4 +97,28 @@
|
|
96
97
|
return null;
|
97
98
|
}
|
98
99
|
|
100
|
+
private resolveTexture(entry: LightmapInfo, res: any) {
|
101
|
+
const tex: Texture = res as unknown as Texture;
|
102
|
+
if (debug) console.log("Lightmap loaded:", tex);
|
103
|
+
if (tex?.isTexture) {
|
104
|
+
if (!this.registry)
|
105
|
+
console.log(LightmapType[entry.type], entry.pointer, tex);
|
106
|
+
else {
|
107
|
+
// TODO this is most likely wrong for floating point textures
|
108
|
+
if (entry.type !== LightmapType.Lightmap)
|
109
|
+
tex.colorSpace = SRGBColorSpace;
|
110
|
+
else
|
111
|
+
tex.colorSpace = LinearSRGBColorSpace;
|
112
|
+
|
113
|
+
|
114
|
+
// Dont flip skybox textures anymore - previously we exported them flipped when baking in Unity but now we allow to pass through export without re-baking exisitng skybox textures if they use default values. So we expect textures to be NOT flipped anymore
|
115
|
+
// if (entry.type === LightmapType.Skybox) {
|
116
|
+
// if (tex.type == FloatType || tex.type == HalfFloatType)
|
117
|
+
// tex.flipY = true;
|
118
|
+
// }
|
119
|
+
|
120
|
+
this.registry.registerTexture(this.source, entry.type, tex, entry.index);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
99
124
|
}
|