@luma.gl/gltf 9.0.0-alpha.54 → 9.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +3643 -15000
- package/dist/dist.min.js +393 -0
- package/dist/gltf/create-gltf-model.d.ts +1 -1
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +34 -51
- package/dist/gltf/create-gltf-objects.d.ts +2 -2
- package/dist/gltf/create-gltf-objects.d.ts.map +1 -1
- package/dist/gltf/create-gltf-objects.js +4 -8
- package/dist/gltf/gltf-animator.d.ts.map +1 -1
- package/dist/gltf/gltf-animator.js +167 -202
- package/dist/gltf/gltf-instantiator.d.ts +3 -4
- package/dist/gltf/gltf-instantiator.d.ts.map +1 -1
- package/dist/gltf/gltf-instantiator.js +170 -161
- package/dist/index.cjs +62 -63
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/pbr/parse-pbr-material.d.ts +1 -1
- package/dist/pbr/parse-pbr-material.d.ts.map +1 -1
- package/dist/pbr/parse-pbr-material.js +320 -135
- package/dist/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/pbr/pbr-environment.js +56 -59
- package/dist.min.js +4 -1215
- package/package.json +14 -15
- package/src/gltf/create-gltf-model.ts +4 -4
- package/src/gltf/gltf-animator.ts +3 -3
- package/src/gltf/gltf-instantiator.ts +45 -30
- package/src/index.ts +0 -1
- package/src/pbr/parse-pbr-material.ts +15 -12
- package/src/pbr/pbr-environment.ts +18 -11
- package/dist/gltf/create-gltf-model.js.map +0 -1
- package/dist/gltf/create-gltf-objects.js.map +0 -1
- package/dist/gltf/gltf-animator.js.map +0 -1
- package/dist/gltf/gltf-instantiator.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pbr/parse-pbr-material.js.map +0 -1
- package/dist/pbr/pbr-environment.js.map +0 -1
|
@@ -1,181 +1,190 @@
|
|
|
1
1
|
import { Geometry, GroupNode } from '@luma.gl/engine';
|
|
2
|
-
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
2
|
import { Matrix4 } from '@math.gl/core';
|
|
4
3
|
import { GLTFAnimator } from "./gltf-animator.js";
|
|
5
4
|
import { createGLTFModel } from "./create-gltf-model.js";
|
|
6
5
|
const DEFAULT_OPTIONS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
modelOptions: {},
|
|
7
|
+
pbrDebug: false,
|
|
8
|
+
imageBasedLightingEnvironment: null,
|
|
9
|
+
lights: true,
|
|
10
|
+
useTangents: false
|
|
12
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* GLTF instantiator for luma.gl
|
|
14
|
+
* Walks the parsed and resolved glTF structure and builds a luma.gl scenegraph
|
|
15
|
+
*/
|
|
13
16
|
export class GLTFInstantiator {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.options = {
|
|
21
|
-
...DEFAULT_OPTIONS,
|
|
22
|
-
...options
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
instantiate(gltf) {
|
|
26
|
-
this.gltf = gltf;
|
|
27
|
-
const scenes = (gltf.scenes || []).map(scene => this.createScene(scene));
|
|
28
|
-
return scenes;
|
|
29
|
-
}
|
|
30
|
-
createAnimator() {
|
|
31
|
-
if (Array.isArray(this.gltf.animations)) {
|
|
32
|
-
return new GLTFAnimator(this.gltf);
|
|
17
|
+
device;
|
|
18
|
+
options;
|
|
19
|
+
gltf;
|
|
20
|
+
constructor(device, options = {}) {
|
|
21
|
+
this.device = device;
|
|
22
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
33
23
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
return scene;
|
|
44
|
-
}
|
|
45
|
-
createNode(gltfNode) {
|
|
46
|
-
if (!gltfNode._node) {
|
|
47
|
-
const gltfChildren = gltfNode.children || [];
|
|
48
|
-
const children = gltfChildren.map(child => this.createNode(child));
|
|
49
|
-
if (gltfNode.mesh) {
|
|
50
|
-
children.push(this.createMesh(gltfNode.mesh));
|
|
51
|
-
}
|
|
52
|
-
const node = new GroupNode({
|
|
53
|
-
id: gltfNode.name || gltfNode.id,
|
|
54
|
-
children
|
|
55
|
-
});
|
|
56
|
-
if (gltfNode.matrix) {
|
|
57
|
-
node.setMatrix(gltfNode.matrix);
|
|
58
|
-
} else {
|
|
59
|
-
node.matrix.identity();
|
|
60
|
-
if (gltfNode.translation) {
|
|
61
|
-
node.matrix.translate(gltfNode.translation);
|
|
24
|
+
instantiate(gltf) {
|
|
25
|
+
this.gltf = gltf;
|
|
26
|
+
const scenes = (gltf.scenes || []).map(scene => this.createScene(scene));
|
|
27
|
+
return scenes;
|
|
28
|
+
}
|
|
29
|
+
createAnimator() {
|
|
30
|
+
if (Array.isArray(this.gltf.animations)) {
|
|
31
|
+
return new GLTFAnimator(this.gltf);
|
|
62
32
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
createScene(gltfScene) {
|
|
36
|
+
const gltfNodes = gltfScene.nodes || [];
|
|
37
|
+
const nodes = gltfNodes.map(node => this.createNode(node));
|
|
38
|
+
const scene = new GroupNode({
|
|
39
|
+
id: gltfScene.name || gltfScene.id,
|
|
40
|
+
children: nodes
|
|
41
|
+
});
|
|
42
|
+
return scene;
|
|
43
|
+
}
|
|
44
|
+
createNode(gltfNode) {
|
|
45
|
+
if (!gltfNode._node) {
|
|
46
|
+
const gltfChildren = gltfNode.children || [];
|
|
47
|
+
const children = gltfChildren.map(child => this.createNode(child));
|
|
48
|
+
// Node can have children nodes and meshes at the same time
|
|
49
|
+
if (gltfNode.mesh) {
|
|
50
|
+
children.push(this.createMesh(gltfNode.mesh));
|
|
51
|
+
}
|
|
52
|
+
const node = new GroupNode({
|
|
53
|
+
id: gltfNode.name || gltfNode.id,
|
|
54
|
+
children
|
|
55
|
+
});
|
|
56
|
+
if (gltfNode.matrix) {
|
|
57
|
+
node.setMatrix(gltfNode.matrix);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
node.matrix.identity();
|
|
61
|
+
if (gltfNode.translation) {
|
|
62
|
+
node.matrix.translate(gltfNode.translation);
|
|
63
|
+
}
|
|
64
|
+
if (gltfNode.rotation) {
|
|
65
|
+
const rotationMatrix = new Matrix4().fromQuaternion(gltfNode.rotation);
|
|
66
|
+
node.matrix.multiplyRight(rotationMatrix);
|
|
67
|
+
}
|
|
68
|
+
if (gltfNode.scale) {
|
|
69
|
+
node.matrix.scale(gltfNode.scale);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
gltfNode._node = node;
|
|
66
73
|
}
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
return gltfNode._node;
|
|
75
|
+
}
|
|
76
|
+
createMesh(gltfMesh) {
|
|
77
|
+
// TODO: avoid changing the gltf
|
|
78
|
+
if (!gltfMesh._mesh) {
|
|
79
|
+
const gltfPrimitives = gltfMesh.primitives || [];
|
|
80
|
+
const primitives = gltfPrimitives.map((gltfPrimitive, i) => this.createPrimitive(gltfPrimitive, i, gltfMesh));
|
|
81
|
+
const mesh = new GroupNode({
|
|
82
|
+
id: gltfMesh.name || gltfMesh.id,
|
|
83
|
+
children: primitives
|
|
84
|
+
});
|
|
85
|
+
gltfMesh._mesh = mesh;
|
|
69
86
|
}
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
return gltfMesh._mesh;
|
|
88
|
+
}
|
|
89
|
+
createPrimitive(gltfPrimitive, i, gltfMesh) {
|
|
90
|
+
const id = gltfPrimitive.name || `${gltfMesh.name || gltfMesh.id}-primitive-${i}`;
|
|
91
|
+
const topology = convertGLDrawModeToTopology(gltfPrimitive.mode || 4);
|
|
92
|
+
const vertexCount = gltfPrimitive.indices
|
|
93
|
+
? gltfPrimitive.indices.count
|
|
94
|
+
: this.getVertexCount(gltfPrimitive.attributes);
|
|
95
|
+
const modelNode = createGLTFModel(this.device, {
|
|
96
|
+
id,
|
|
97
|
+
geometry: this.createGeometry(id, gltfPrimitive, topology),
|
|
98
|
+
material: gltfPrimitive.material,
|
|
99
|
+
materialOptions: this.options,
|
|
100
|
+
modelOptions: this.options.modelOptions,
|
|
101
|
+
vertexCount
|
|
102
|
+
});
|
|
103
|
+
modelNode.bounds = [
|
|
104
|
+
gltfPrimitive.attributes.POSITION.min,
|
|
105
|
+
gltfPrimitive.attributes.POSITION.max
|
|
106
|
+
];
|
|
107
|
+
// TODO this holds on to all the CPU side texture and attribute data
|
|
108
|
+
// modelNode.material = gltfPrimitive.material;
|
|
109
|
+
return modelNode;
|
|
72
110
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
createMesh(gltfMesh) {
|
|
76
|
-
if (!gltfMesh._mesh) {
|
|
77
|
-
const gltfPrimitives = gltfMesh.primitives || [];
|
|
78
|
-
const primitives = gltfPrimitives.map((gltfPrimitive, i) => this.createPrimitive(gltfPrimitive, i, gltfMesh));
|
|
79
|
-
const mesh = new GroupNode({
|
|
80
|
-
id: gltfMesh.name || gltfMesh.id,
|
|
81
|
-
children: primitives
|
|
82
|
-
});
|
|
83
|
-
gltfMesh._mesh = mesh;
|
|
111
|
+
getVertexCount(attributes) {
|
|
112
|
+
throw new Error('getVertexCount not implemented');
|
|
84
113
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
vertexCount
|
|
98
|
-
});
|
|
99
|
-
modelNode.bounds = [gltfPrimitive.attributes.POSITION.min, gltfPrimitive.attributes.POSITION.max];
|
|
100
|
-
return modelNode;
|
|
101
|
-
}
|
|
102
|
-
getVertexCount(attributes) {
|
|
103
|
-
throw new Error('getVertexCount not implemented');
|
|
104
|
-
}
|
|
105
|
-
createGeometry(id, gltfPrimitive, topology) {
|
|
106
|
-
const attributes = {};
|
|
107
|
-
for (const [attributeName, attribute] of Object.entries(gltfPrimitive.attributes)) {
|
|
108
|
-
const {
|
|
109
|
-
components,
|
|
110
|
-
size,
|
|
111
|
-
value
|
|
112
|
-
} = attribute;
|
|
113
|
-
attributes[attributeName] = {
|
|
114
|
-
size: size !== null && size !== void 0 ? size : components,
|
|
115
|
-
value
|
|
116
|
-
};
|
|
114
|
+
createGeometry(id, gltfPrimitive, topology) {
|
|
115
|
+
const attributes = {};
|
|
116
|
+
for (const [attributeName, attribute] of Object.entries(gltfPrimitive.attributes)) {
|
|
117
|
+
const { components, size, value } = attribute;
|
|
118
|
+
attributes[attributeName] = { size: size ?? components, value };
|
|
119
|
+
}
|
|
120
|
+
return new Geometry({
|
|
121
|
+
id,
|
|
122
|
+
topology,
|
|
123
|
+
indices: gltfPrimitive.indices.value,
|
|
124
|
+
attributes
|
|
125
|
+
});
|
|
117
126
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
createBuffer(attribute, usage) {
|
|
128
|
+
if (!attribute.bufferView) {
|
|
129
|
+
// Draco decoded files do not have a bufferView
|
|
130
|
+
attribute.bufferView = {};
|
|
131
|
+
}
|
|
132
|
+
const { bufferView } = attribute;
|
|
133
|
+
if (!bufferView.lumaBuffers) {
|
|
134
|
+
bufferView.lumaBuffers = {};
|
|
135
|
+
}
|
|
136
|
+
if (!bufferView.lumaBuffers[usage]) {
|
|
137
|
+
bufferView.lumaBuffers[usage] = this.device.createBuffer({
|
|
138
|
+
id: `from-${bufferView.id}`,
|
|
139
|
+
// Draco decoded files have attribute.value
|
|
140
|
+
data: bufferView.data || attribute.value
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return bufferView.lumaBuffers[usage];
|
|
129
144
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (!bufferView.lumaBuffers) {
|
|
134
|
-
bufferView.lumaBuffers = {};
|
|
145
|
+
// TODO - create sampler in WebGL2
|
|
146
|
+
createSampler(gltfSampler) {
|
|
147
|
+
return gltfSampler;
|
|
135
148
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
// Helper methods (move to GLTFLoader.resolve...?)
|
|
150
|
+
needsPOT() {
|
|
151
|
+
// Has a wrapping mode (either wrapS or wrapT) equal to REPEAT or MIRRORED_REPEAT, or
|
|
152
|
+
// Has a minification filter (minFilter) that uses mipmapping
|
|
153
|
+
// (NEAREST_MIPMAP_NEAREST, NEAREST_MIPMAP_LINEAR,
|
|
154
|
+
// LINEAR_MIPMAP_NEAREST, or LINEAR_MIPMAP_LINEAR).
|
|
155
|
+
return false;
|
|
141
156
|
}
|
|
142
|
-
return bufferView.lumaBuffers[usage];
|
|
143
|
-
}
|
|
144
|
-
createSampler(gltfSampler) {
|
|
145
|
-
return gltfSampler;
|
|
146
|
-
}
|
|
147
|
-
needsPOT() {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
157
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
// NOTE: Modules other than `@luma.gl/webgl` should not import `GL` from
|
|
159
|
+
// `@luma.gl/constants`. Locally we use `GLEnum` instead of `GL` to avoid
|
|
160
|
+
// conflicts with the `babel-plugin-inline-webgl-constants` plugin.
|
|
161
|
+
var GLEnum;
|
|
162
|
+
(function (GLEnum) {
|
|
163
|
+
GLEnum[GLEnum["POINTS"] = 0] = "POINTS";
|
|
164
|
+
GLEnum[GLEnum["LINES"] = 1] = "LINES";
|
|
165
|
+
GLEnum[GLEnum["LINE_LOOP"] = 2] = "LINE_LOOP";
|
|
166
|
+
GLEnum[GLEnum["LINE_STRIP"] = 3] = "LINE_STRIP";
|
|
167
|
+
GLEnum[GLEnum["TRIANGLES"] = 4] = "TRIANGLES";
|
|
168
|
+
GLEnum[GLEnum["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
|
|
169
|
+
GLEnum[GLEnum["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
|
|
170
|
+
})(GLEnum || (GLEnum = {}));
|
|
161
171
|
export function convertGLDrawModeToTopology(drawMode) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
172
|
+
switch (drawMode) {
|
|
173
|
+
case GLEnum.POINTS:
|
|
174
|
+
return 'point-list';
|
|
175
|
+
case GLEnum.LINES:
|
|
176
|
+
return 'line-list';
|
|
177
|
+
case GLEnum.LINE_STRIP:
|
|
178
|
+
return 'line-strip';
|
|
179
|
+
case GLEnum.LINE_LOOP:
|
|
180
|
+
return 'line-loop-webgl';
|
|
181
|
+
case GLEnum.TRIANGLES:
|
|
182
|
+
return 'triangle-list';
|
|
183
|
+
case GLEnum.TRIANGLE_STRIP:
|
|
184
|
+
return 'triangle-strip';
|
|
185
|
+
case GLEnum.TRIANGLE_FAN:
|
|
186
|
+
return 'triangle-fan-webgl';
|
|
187
|
+
default:
|
|
188
|
+
throw new Error(drawMode);
|
|
189
|
+
}
|
|
180
190
|
}
|
|
181
|
-
//# sourceMappingURL=gltf-instantiator.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -16,18 +16,29 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
19
|
+
// dist/index.js
|
|
20
|
+
var dist_exports = {};
|
|
21
|
+
__export(dist_exports, {
|
|
22
22
|
GLTFAnimator: () => GLTFAnimator,
|
|
23
23
|
createScenegraphsFromGLTF: () => createScenegraphsFromGLTF,
|
|
24
24
|
loadPBREnvironment: () => loadPBREnvironment,
|
|
25
25
|
parsePBRMaterial: () => parsePBRMaterial
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
27
|
+
module.exports = __toCommonJS(dist_exports);
|
|
28
28
|
|
|
29
|
-
//
|
|
29
|
+
// dist/pbr/parse-pbr-material.js
|
|
30
30
|
var import_core = require("@luma.gl/core");
|
|
31
|
+
var GLEnum;
|
|
32
|
+
(function(GLEnum3) {
|
|
33
|
+
GLEnum3[GLEnum3["FUNC_ADD"] = 32774] = "FUNC_ADD";
|
|
34
|
+
GLEnum3[GLEnum3["ONE"] = 1] = "ONE";
|
|
35
|
+
GLEnum3[GLEnum3["SRC_ALPHA"] = 770] = "SRC_ALPHA";
|
|
36
|
+
GLEnum3[GLEnum3["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
|
|
37
|
+
GLEnum3[GLEnum3["TEXTURE_MIN_FILTER"] = 10241] = "TEXTURE_MIN_FILTER";
|
|
38
|
+
GLEnum3[GLEnum3["LINEAR"] = 9729] = "LINEAR";
|
|
39
|
+
GLEnum3[GLEnum3["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
|
|
40
|
+
GLEnum3[GLEnum3["UNPACK_FLIP_Y_WEBGL"] = 37440] = "UNPACK_FLIP_Y_WEBGL";
|
|
41
|
+
})(GLEnum || (GLEnum = {}));
|
|
31
42
|
function parsePBRMaterial(device, material, attributes, options) {
|
|
32
43
|
const parsedMaterial = {
|
|
33
44
|
defines: {
|
|
@@ -47,9 +58,7 @@ function parsePBRMaterial(device, material, attributes, options) {
|
|
|
47
58
|
glParameters: {},
|
|
48
59
|
generatedTextures: []
|
|
49
60
|
};
|
|
50
|
-
|
|
51
|
-
parsedMaterial.defines.USE_TEX_LOD = 1;
|
|
52
|
-
}
|
|
61
|
+
parsedMaterial.defines.USE_TEX_LOD = 1;
|
|
53
62
|
const { imageBasedLightingEnvironment } = options;
|
|
54
63
|
if (imageBasedLightingEnvironment) {
|
|
55
64
|
parsedMaterial.bindings.u_DiffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler;
|
|
@@ -88,24 +97,12 @@ function parseMaterial(device, material, parsedMaterial) {
|
|
|
88
97
|
parsedMaterial.uniforms.u_NormalScale = scale;
|
|
89
98
|
}
|
|
90
99
|
if (material.occlusionTexture) {
|
|
91
|
-
addTexture(
|
|
92
|
-
device,
|
|
93
|
-
material.occlusionTexture,
|
|
94
|
-
"u_OcclusionSampler",
|
|
95
|
-
"HAS_OCCLUSIONMAP",
|
|
96
|
-
parsedMaterial
|
|
97
|
-
);
|
|
100
|
+
addTexture(device, material.occlusionTexture, "u_OcclusionSampler", "HAS_OCCLUSIONMAP", parsedMaterial);
|
|
98
101
|
const { strength = 1 } = material.occlusionTexture;
|
|
99
102
|
parsedMaterial.uniforms.u_OcclusionStrength = strength;
|
|
100
103
|
}
|
|
101
104
|
if (material.emissiveTexture) {
|
|
102
|
-
addTexture(
|
|
103
|
-
device,
|
|
104
|
-
material.emissiveTexture,
|
|
105
|
-
"u_EmissiveSampler",
|
|
106
|
-
"HAS_EMISSIVEMAP",
|
|
107
|
-
parsedMaterial
|
|
108
|
-
);
|
|
105
|
+
addTexture(device, material.emissiveTexture, "u_EmissiveSampler", "HAS_EMISSIVEMAP", parsedMaterial);
|
|
109
106
|
parsedMaterial.uniforms.u_EmissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
110
107
|
}
|
|
111
108
|
switch (material.alphaMode) {
|
|
@@ -123,30 +120,23 @@ function parseMaterial(device, material, parsedMaterial) {
|
|
|
123
120
|
parsedMaterial.parameters.blendAlphaSrcFactor = "one";
|
|
124
121
|
parsedMaterial.parameters.blendAlphaDstFactor = "one-minus-src-alpha";
|
|
125
122
|
parsedMaterial.glParameters.blend = true;
|
|
126
|
-
parsedMaterial.glParameters.blendEquation =
|
|
127
|
-
parsedMaterial.glParameters.blendFunc = [
|
|
123
|
+
parsedMaterial.glParameters.blendEquation = GLEnum.FUNC_ADD;
|
|
124
|
+
parsedMaterial.glParameters.blendFunc = [
|
|
125
|
+
GLEnum.SRC_ALPHA,
|
|
126
|
+
GLEnum.ONE_MINUS_SRC_ALPHA,
|
|
127
|
+
GLEnum.ONE,
|
|
128
|
+
GLEnum.ONE_MINUS_SRC_ALPHA
|
|
129
|
+
];
|
|
128
130
|
break;
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
function parsePbrMetallicRoughness(device, pbrMetallicRoughness, parsedMaterial) {
|
|
132
134
|
if (pbrMetallicRoughness.baseColorTexture) {
|
|
133
|
-
addTexture(
|
|
134
|
-
device,
|
|
135
|
-
pbrMetallicRoughness.baseColorTexture,
|
|
136
|
-
"u_BaseColorSampler",
|
|
137
|
-
"HAS_BASECOLORMAP",
|
|
138
|
-
parsedMaterial
|
|
139
|
-
);
|
|
135
|
+
addTexture(device, pbrMetallicRoughness.baseColorTexture, "u_BaseColorSampler", "HAS_BASECOLORMAP", parsedMaterial);
|
|
140
136
|
}
|
|
141
137
|
parsedMaterial.uniforms.u_BaseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
142
138
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
143
|
-
addTexture(
|
|
144
|
-
device,
|
|
145
|
-
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
146
|
-
"u_MetallicRoughnessSampler",
|
|
147
|
-
"HAS_METALROUGHNESSMAP",
|
|
148
|
-
parsedMaterial
|
|
149
|
-
);
|
|
139
|
+
addTexture(device, pbrMetallicRoughness.metallicRoughnessTexture, "u_MetallicRoughnessSampler", "HAS_METALROUGHNESSMAP", parsedMaterial);
|
|
150
140
|
}
|
|
151
141
|
const { metallicFactor = 1, roughnessFactor = 1 } = pbrMetallicRoughness;
|
|
152
142
|
parsedMaterial.uniforms.u_MetallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
@@ -160,7 +150,7 @@ function addTexture(device, gltfTexture, uniformName, define = null, parsedMater
|
|
|
160
150
|
if (image.compressed) {
|
|
161
151
|
textureOptions = image;
|
|
162
152
|
specialTextureParameters = {
|
|
163
|
-
[
|
|
153
|
+
[GLEnum.TEXTURE_MIN_FILTER]: image.data.length > 1 ? GLEnum.LINEAR_MIPMAP_NEAREST : GLEnum.LINEAR
|
|
164
154
|
};
|
|
165
155
|
} else {
|
|
166
156
|
textureOptions = { data: image };
|
|
@@ -172,7 +162,7 @@ function addTexture(device, gltfTexture, uniformName, define = null, parsedMater
|
|
|
172
162
|
...specialTextureParameters
|
|
173
163
|
},
|
|
174
164
|
pixelStore: {
|
|
175
|
-
[
|
|
165
|
+
[GLEnum.UNPACK_FLIP_Y_WEBGL]: false
|
|
176
166
|
},
|
|
177
167
|
...textureOptions
|
|
178
168
|
});
|
|
@@ -182,7 +172,7 @@ function addTexture(device, gltfTexture, uniformName, define = null, parsedMater
|
|
|
182
172
|
parsedMaterial.generatedTextures.push(texture);
|
|
183
173
|
}
|
|
184
174
|
|
|
185
|
-
//
|
|
175
|
+
// dist/pbr/pbr-environment.js
|
|
186
176
|
var import_textures = require("@loaders.gl/textures");
|
|
187
177
|
function loadPBREnvironment(device, props) {
|
|
188
178
|
const brdfLutTexture = device.createTexture({
|
|
@@ -244,12 +234,11 @@ function makeCube(device, { id, getTextureForFace, sampler }) {
|
|
|
244
234
|
});
|
|
245
235
|
}
|
|
246
236
|
|
|
247
|
-
//
|
|
237
|
+
// dist/gltf/gltf-instantiator.js
|
|
248
238
|
var import_engine2 = require("@luma.gl/engine");
|
|
249
|
-
var import_webgl = require("@luma.gl/webgl");
|
|
250
239
|
var import_core5 = require("@math.gl/core");
|
|
251
240
|
|
|
252
|
-
//
|
|
241
|
+
// dist/gltf/gltf-animator.js
|
|
253
242
|
var import_core2 = require("@luma.gl/core");
|
|
254
243
|
var import_core3 = require("@math.gl/core");
|
|
255
244
|
var ATTRIBUTE_TYPE_TO_COMPONENTS = {
|
|
@@ -427,7 +416,7 @@ function interpolate(time, { input, interpolation, output }, target, path) {
|
|
|
427
416
|
}
|
|
428
417
|
}
|
|
429
418
|
|
|
430
|
-
//
|
|
419
|
+
// dist/gltf/create-gltf-model.js
|
|
431
420
|
var import_core4 = require("@luma.gl/core");
|
|
432
421
|
var import_shadertools = require("@luma.gl/shadertools");
|
|
433
422
|
var import_engine = require("@luma.gl/engine");
|
|
@@ -519,11 +508,11 @@ function createGLTFModel(device, options) {
|
|
|
519
508
|
return new import_engine.ModelNode({ managedResources, model });
|
|
520
509
|
}
|
|
521
510
|
function addVersionToShader(device, source) {
|
|
522
|
-
return
|
|
523
|
-
${source}
|
|
511
|
+
return `#version 300 es
|
|
512
|
+
${source}`;
|
|
524
513
|
}
|
|
525
514
|
|
|
526
|
-
//
|
|
515
|
+
// dist/gltf/gltf-instantiator.js
|
|
527
516
|
var DEFAULT_OPTIONS = {
|
|
528
517
|
modelOptions: {},
|
|
529
518
|
pbrDebug: false,
|
|
@@ -532,12 +521,11 @@ var DEFAULT_OPTIONS = {
|
|
|
532
521
|
useTangents: false
|
|
533
522
|
};
|
|
534
523
|
var GLTFInstantiator = class {
|
|
535
|
-
// TODO - replace with Device
|
|
536
524
|
device;
|
|
537
525
|
options;
|
|
538
526
|
gltf;
|
|
539
527
|
constructor(device, options = {}) {
|
|
540
|
-
this.device =
|
|
528
|
+
this.device = device;
|
|
541
529
|
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
542
530
|
}
|
|
543
531
|
instantiate(gltf) {
|
|
@@ -593,9 +581,7 @@ var GLTFInstantiator = class {
|
|
|
593
581
|
createMesh(gltfMesh) {
|
|
594
582
|
if (!gltfMesh._mesh) {
|
|
595
583
|
const gltfPrimitives = gltfMesh.primitives || [];
|
|
596
|
-
const primitives = gltfPrimitives.map(
|
|
597
|
-
(gltfPrimitive, i) => this.createPrimitive(gltfPrimitive, i, gltfMesh)
|
|
598
|
-
);
|
|
584
|
+
const primitives = gltfPrimitives.map((gltfPrimitive, i) => this.createPrimitive(gltfPrimitive, i, gltfMesh));
|
|
599
585
|
const mesh = new import_engine2.GroupNode({
|
|
600
586
|
id: gltfMesh.name || gltfMesh.id,
|
|
601
587
|
children: primitives
|
|
@@ -616,7 +602,10 @@ var GLTFInstantiator = class {
|
|
|
616
602
|
modelOptions: this.options.modelOptions,
|
|
617
603
|
vertexCount
|
|
618
604
|
});
|
|
619
|
-
modelNode.bounds = [
|
|
605
|
+
modelNode.bounds = [
|
|
606
|
+
gltfPrimitive.attributes.POSITION.min,
|
|
607
|
+
gltfPrimitive.attributes.POSITION.max
|
|
608
|
+
];
|
|
620
609
|
return modelNode;
|
|
621
610
|
}
|
|
622
611
|
getVertexCount(attributes) {
|
|
@@ -628,7 +617,6 @@ var GLTFInstantiator = class {
|
|
|
628
617
|
const { components, size, value } = attribute;
|
|
629
618
|
attributes[attributeName] = { size: size ?? components, value };
|
|
630
619
|
}
|
|
631
|
-
;
|
|
632
620
|
return new import_engine2.Geometry({
|
|
633
621
|
id,
|
|
634
622
|
topology,
|
|
@@ -662,31 +650,42 @@ var GLTFInstantiator = class {
|
|
|
662
650
|
return false;
|
|
663
651
|
}
|
|
664
652
|
};
|
|
653
|
+
var GLEnum2;
|
|
654
|
+
(function(GLEnum3) {
|
|
655
|
+
GLEnum3[GLEnum3["POINTS"] = 0] = "POINTS";
|
|
656
|
+
GLEnum3[GLEnum3["LINES"] = 1] = "LINES";
|
|
657
|
+
GLEnum3[GLEnum3["LINE_LOOP"] = 2] = "LINE_LOOP";
|
|
658
|
+
GLEnum3[GLEnum3["LINE_STRIP"] = 3] = "LINE_STRIP";
|
|
659
|
+
GLEnum3[GLEnum3["TRIANGLES"] = 4] = "TRIANGLES";
|
|
660
|
+
GLEnum3[GLEnum3["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
|
|
661
|
+
GLEnum3[GLEnum3["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
|
|
662
|
+
})(GLEnum2 || (GLEnum2 = {}));
|
|
665
663
|
function convertGLDrawModeToTopology(drawMode) {
|
|
666
664
|
switch (drawMode) {
|
|
667
|
-
case
|
|
665
|
+
case GLEnum2.POINTS:
|
|
668
666
|
return "point-list";
|
|
669
|
-
case
|
|
667
|
+
case GLEnum2.LINES:
|
|
670
668
|
return "line-list";
|
|
671
|
-
case
|
|
669
|
+
case GLEnum2.LINE_STRIP:
|
|
672
670
|
return "line-strip";
|
|
673
|
-
case
|
|
671
|
+
case GLEnum2.LINE_LOOP:
|
|
674
672
|
return "line-loop-webgl";
|
|
675
|
-
case
|
|
673
|
+
case GLEnum2.TRIANGLES:
|
|
676
674
|
return "triangle-list";
|
|
677
|
-
case
|
|
675
|
+
case GLEnum2.TRIANGLE_STRIP:
|
|
678
676
|
return "triangle-strip";
|
|
679
|
-
case
|
|
677
|
+
case GLEnum2.TRIANGLE_FAN:
|
|
680
678
|
return "triangle-fan-webgl";
|
|
681
679
|
default:
|
|
682
680
|
throw new Error(drawMode);
|
|
683
681
|
}
|
|
684
682
|
}
|
|
685
683
|
|
|
686
|
-
//
|
|
684
|
+
// dist/gltf/create-gltf-objects.js
|
|
687
685
|
function createScenegraphsFromGLTF(device, gltf, options) {
|
|
688
686
|
const instantiator = new GLTFInstantiator(device, options);
|
|
689
687
|
const scenes = instantiator.instantiate(gltf);
|
|
690
688
|
const animator = instantiator.createAnimator();
|
|
691
689
|
return { scenes, animator };
|
|
692
690
|
}
|
|
691
|
+
//# sourceMappingURL=index.cjs.map
|