@galacean/engine-loader 0.0.0-experimental-animator-additive.1
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/main.js +4511 -0
- package/dist/main.js.map +1 -0
- package/dist/miniprogram.js +4511 -0
- package/dist/module.js +4501 -0
- package/dist/module.js.map +1 -0
- package/package.json +26 -0
- package/types/AnimationClipLoader.d.ts +0 -0
- package/types/AnimatorControllerLoader.d.ts +1 -0
- package/types/BufferLoader.d.ts +1 -0
- package/types/EnvLoader.d.ts +1 -0
- package/types/FontLoader.d.ts +1 -0
- package/types/GLTFContentRestorer.d.ts +85 -0
- package/types/GLTFLoader.d.ts +15 -0
- package/types/HDRLoader.d.ts +1 -0
- package/types/JSONLoader.d.ts +1 -0
- package/types/KTXCubeLoader.d.ts +1 -0
- package/types/KTXLoader.d.ts +4 -0
- package/types/MaterialLoader.d.ts +1 -0
- package/types/MeshLoader.d.ts +1 -0
- package/types/SceneLoader.d.ts +1 -0
- package/types/SourceFontLoader.d.ts +1 -0
- package/types/SpriteAtlasLoader.d.ts +1 -0
- package/types/SpriteLoader.d.ts +1 -0
- package/types/TextLoader.d.ts +1 -0
- package/types/Texture2DContentRestorer.d.ts +14 -0
- package/types/Texture2DLoader.d.ts +10 -0
- package/types/TextureCubeContentRestorer.d.ts +14 -0
- package/types/TextureCubeLoader.d.ts +1 -0
- package/types/compressed-texture/KhronosTextureContainer.d.ts +20 -0
- package/types/compressed-texture/index.d.ts +3 -0
- package/types/compressed-texture/type.d.ts +87 -0
- package/types/gltf/GLTFParser.d.ts +9 -0
- package/types/gltf/GLTFPipeline.d.ts +23 -0
- package/types/gltf/GLTFResource.d.ts +39 -0
- package/types/gltf/GLTFSchema.d.ts +816 -0
- package/types/gltf/GLTFUtil.d.ts +53 -0
- package/types/gltf/Schema.d.ts +814 -0
- package/types/gltf/extensions/ExtensionParser.d.ts +8 -0
- package/types/gltf/extensions/GALACEAN_materials_remap.d.ts +1 -0
- package/types/gltf/extensions/GLTFExtensionParser.d.ts +52 -0
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +149 -0
- package/types/gltf/extensions/KHR_draco_mesh_compression.d.ts +1 -0
- package/types/gltf/extensions/KHR_lights_punctual.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_clearcoat.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_ior.d.ts +0 -0
- package/types/gltf/extensions/KHR_materials_pbrSpecularGlossiness.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_sheen.d.ts +0 -0
- package/types/gltf/extensions/KHR_materials_transmission.d.ts +0 -0
- package/types/gltf/extensions/KHR_materials_unlit.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_variants.d.ts +1 -0
- package/types/gltf/extensions/KHR_materials_volume.d.ts +0 -0
- package/types/gltf/extensions/KHR_mesh_quantization.d.ts +1 -0
- package/types/gltf/extensions/KHR_texture_basisu.d.ts +0 -0
- package/types/gltf/extensions/KHR_texture_transform.d.ts +1 -0
- package/types/gltf/extensions/OASIS_animation.d.ts +1 -0
- package/types/gltf/extensions/OASIS_materials_remap.d.ts +1 -0
- package/types/gltf/extensions/Schema.d.ts +142 -0
- package/types/gltf/extensions/index.d.ts +14 -0
- package/types/gltf/index.d.ts +6 -0
- package/types/gltf/parser/AnimationParser.d.ts +7 -0
- package/types/gltf/parser/BufferParser.d.ts +7 -0
- package/types/gltf/parser/EntityParser.d.ts +9 -0
- package/types/gltf/parser/GLTFAnimationParser.d.ts +12 -0
- package/types/gltf/parser/GLTFBufferParser.d.ts +7 -0
- package/types/gltf/parser/GLTFEntityParser.d.ts +9 -0
- package/types/gltf/parser/GLTFMaterialParser.d.ts +15 -0
- package/types/gltf/parser/GLTFMeshParser.d.ts +19 -0
- package/types/gltf/parser/GLTFParser.d.ts +63 -0
- package/types/gltf/parser/GLTFParserContext.d.ts +48 -0
- package/types/gltf/parser/GLTFSceneParser.d.ts +11 -0
- package/types/gltf/parser/GLTFSkinParser.d.ts +6 -0
- package/types/gltf/parser/GLTFTextureParser.d.ts +8 -0
- package/types/gltf/parser/GLTFValidator.d.ts +6 -0
- package/types/gltf/parser/MaterialParser.d.ts +8 -0
- package/types/gltf/parser/MeshParser.d.ts +13 -0
- package/types/gltf/parser/Parser.d.ts +21 -0
- package/types/gltf/parser/ParserContext.d.ts +46 -0
- package/types/gltf/parser/SceneParser.d.ts +11 -0
- package/types/gltf/parser/SkinParser.d.ts +6 -0
- package/types/gltf/parser/TextureParser.d.ts +8 -0
- package/types/gltf/parser/Validator.d.ts +5 -0
- package/types/gltf/parser/index.d.ts +11 -0
- package/types/index.d.ts +23 -0
- package/types/resource-deserialize/index.d.ts +18 -0
- package/types/resource-deserialize/resources/animationClip/AnimationClipDecoder.d.ts +17 -0
- package/types/resource-deserialize/resources/animationClip/ComponentMap.d.ts +2 -0
- package/types/resource-deserialize/resources/animationClip/type.d.ts +30 -0
- package/types/resource-deserialize/resources/animatorController/AnimatorControllerDecoder.d.ts +6 -0
- package/types/resource-deserialize/resources/animatorController/type.d.ts +0 -0
- package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +9 -0
- package/types/resource-deserialize/resources/mesh/type.d.ts +31 -0
- package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +70 -0
- package/types/resource-deserialize/resources/prefab/PrefabParser.d.ts +5 -0
- package/types/resource-deserialize/resources/prefab/ReflectionParser.d.ts +14 -0
- package/types/resource-deserialize/resources/scene/EditorTextureLoader.d.ts +4 -0
- package/types/resource-deserialize/resources/scene/MeshLoader.d.ts +4 -0
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +28 -0
- package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +13 -0
- package/types/resource-deserialize/resources/texture2D/TextureDecoder.d.ts +5 -0
- package/types/resource-deserialize/utils/BufferReader.d.ts +32 -0
- package/types/resource-deserialize/utils/Decorator.d.ts +11 -0
- package/types/resource-deserialize/utils/FileHeader.d.ts +9 -0
- package/types/resource-deserialize/utils/Utils.d.ts +5 -0
package/dist/module.js
ADDED
|
@@ -0,0 +1,4501 @@
|
|
|
1
|
+
import { resourceLoader, AssetType, AssetPromise, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, AnimatorStateTransition, Loader, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, IndexFormat, VertexElementFormat, DirectLight, PointLight, SpotLight, PBRMaterial, TextureCoordinate, Logger, RenderFace, PBRSpecularMaterial, UnlitMaterial, AnimationClip, InterpolationType, AnimationFloatArrayCurve, Keyframe, AnimationQuaternionCurve, AnimationVector3Curve, SkinnedMeshRenderer, Transform, request, Entity, VertexElement, Buffer, BufferBindFlag, BufferUsage, BlendShape, ModelMesh, Camera, Animator, BlinnPhongMaterial, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, Texture2D, EngineObject, TextureFormat, PBRBaseMaterial, Shader, ParticleRenderer, Script, SpriteMask, SpriteRenderer, TextRenderer, AnimationEvent, AnimationColorCurve, AnimationVector4Curve, AnimationVector2Curve, AnimationArrayCurve, AnimationFloatCurve, Scene, SpriteAtlas, Sprite, BackgroundMode, SkyBoxMaterial, PrimitiveMesh } from '@galacean/engine-core';
|
|
2
|
+
import { SphericalHarmonics3, Vector2, Vector3, Vector4, Color, Quaternion, Matrix, Rect } from '@galacean/engine-math';
|
|
3
|
+
import { DRACODecoder } from '@galacean/engine-draco';
|
|
4
|
+
import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
|
|
5
|
+
|
|
6
|
+
function _extends() {
|
|
7
|
+
_extends = Object.assign || function assign(target) {
|
|
8
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for (var key in source) if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function _set_prototype_of(o, p) {
|
|
20
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
21
|
+
o.__proto__ = p;
|
|
22
|
+
|
|
23
|
+
return o;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return _set_prototype_of(o, p);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _inherits(subClass, superClass) {
|
|
30
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
31
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
|
|
35
|
+
|
|
36
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/******************************************************************************
|
|
40
|
+
Copyright (c) Microsoft Corporation.
|
|
41
|
+
|
|
42
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
43
|
+
purpose with or without fee is hereby granted.
|
|
44
|
+
|
|
45
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
46
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
47
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
48
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
49
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
50
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
51
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
52
|
+
***************************************************************************** */
|
|
53
|
+
|
|
54
|
+
function __decorate(decorators, target, key, desc) {
|
|
55
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
56
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
57
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
58
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function __generator(thisArg, body) {
|
|
62
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
63
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
64
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
65
|
+
function step(op) {
|
|
66
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
67
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
68
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
69
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
70
|
+
switch (op[0]) {
|
|
71
|
+
case 0: case 1: t = op; break;
|
|
72
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
73
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
74
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
75
|
+
default:
|
|
76
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
77
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
78
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
79
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
80
|
+
if (t[2]) _.ops.pop();
|
|
81
|
+
_.trys.pop(); continue;
|
|
82
|
+
}
|
|
83
|
+
op = body.call(thisArg, _);
|
|
84
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
85
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
|
|
90
|
+
_inherits(AnimatorControllerLoader, Loader);
|
|
91
|
+
function AnimatorControllerLoader() {
|
|
92
|
+
return Loader.apply(this, arguments);
|
|
93
|
+
}
|
|
94
|
+
var _proto = AnimatorControllerLoader.prototype;
|
|
95
|
+
_proto.load = function load(item, resourceManager) {
|
|
96
|
+
var _this = this;
|
|
97
|
+
return new AssetPromise(function(resolve, reject) {
|
|
98
|
+
_this.request(item.url, _extends({}, item, {
|
|
99
|
+
type: "json"
|
|
100
|
+
})).then(function(data) {
|
|
101
|
+
var animatorController = new AnimatorController();
|
|
102
|
+
var layers = data.layers;
|
|
103
|
+
var promises = [];
|
|
104
|
+
layers.forEach(function(layerData, layerIndex) {
|
|
105
|
+
var name = layerData.name, blendingMode = layerData.blendingMode, weight = layerData.weight, stateMachineData = layerData.stateMachine;
|
|
106
|
+
var layer = new AnimatorControllerLayer(name);
|
|
107
|
+
layer.blendingMode = blendingMode;
|
|
108
|
+
layer.weight = weight;
|
|
109
|
+
if (stateMachineData) {
|
|
110
|
+
var states = stateMachineData.states;
|
|
111
|
+
var stateMachine = layer.stateMachine = new AnimatorStateMachine();
|
|
112
|
+
states.forEach(function(stateData, stateIndex) {
|
|
113
|
+
var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
|
|
114
|
+
var state = stateMachine.addState(name);
|
|
115
|
+
isDefaultState && (stateMachine.defaultState = state);
|
|
116
|
+
state.speed = speed;
|
|
117
|
+
state.wrapMode = wrapMode;
|
|
118
|
+
state.clipStartTime = clipStartNormalizedTime;
|
|
119
|
+
state.clipEndTime = clipEndNormalizedTime;
|
|
120
|
+
if (clipData) {
|
|
121
|
+
promises.push(new Promise(function(resolve) {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
resourceManager.getResourceByRef(clipData).then(function(clip) {
|
|
124
|
+
resolve({
|
|
125
|
+
layerIndex: layerIndex,
|
|
126
|
+
stateIndex: stateIndex,
|
|
127
|
+
clip: clip
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
states.forEach(function(stateData) {
|
|
134
|
+
var name = stateData.name, transitions = stateData.transitions;
|
|
135
|
+
transitions.forEach(function(transitionData) {
|
|
136
|
+
var targetStateName = transitionData.targetStateName, duration = transitionData.duration, offset = transitionData.offset, exitTime = transitionData.exitTime;
|
|
137
|
+
var sourceState = stateMachine.findStateByName(name);
|
|
138
|
+
var destState = stateMachine.findStateByName(targetStateName);
|
|
139
|
+
var transition = new AnimatorStateTransition();
|
|
140
|
+
transition.destinationState = destState;
|
|
141
|
+
transition.duration = duration;
|
|
142
|
+
transition.exitTime = exitTime;
|
|
143
|
+
transition.offset = offset;
|
|
144
|
+
sourceState.addTransition(transition);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
animatorController.addLayer(layer);
|
|
149
|
+
});
|
|
150
|
+
Promise.all(promises).then(function(clipData) {
|
|
151
|
+
clipData.forEach(function(data) {
|
|
152
|
+
var layerIndex = data.layerIndex, stateIndex = data.stateIndex, clip = data.clip;
|
|
153
|
+
animatorController.layers[layerIndex].stateMachine.states[stateIndex].clip = clip;
|
|
154
|
+
});
|
|
155
|
+
resolve(animatorController);
|
|
156
|
+
});
|
|
157
|
+
}).catch(reject);
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
return AnimatorControllerLoader;
|
|
161
|
+
}(Loader);
|
|
162
|
+
AnimatorControllerLoader = __decorate([
|
|
163
|
+
resourceLoader(AssetType.AnimatorController, [
|
|
164
|
+
"json"
|
|
165
|
+
], false)
|
|
166
|
+
], AnimatorControllerLoader);
|
|
167
|
+
|
|
168
|
+
function isBase64(url) {
|
|
169
|
+
return /^data:(.+?);base64,/.test(url);
|
|
170
|
+
}
|
|
171
|
+
var BufferLoader = /*#__PURE__*/ function(Loader) {
|
|
172
|
+
_inherits(BufferLoader, Loader);
|
|
173
|
+
function BufferLoader() {
|
|
174
|
+
return Loader.apply(this, arguments);
|
|
175
|
+
}
|
|
176
|
+
var _proto = BufferLoader.prototype;
|
|
177
|
+
_proto.load = function load(item) {
|
|
178
|
+
var url = item.url;
|
|
179
|
+
if (isBase64(url)) {
|
|
180
|
+
return new AssetPromise(function(resolve) {
|
|
181
|
+
var base64Str = url.slice(13 + RegExp.$1.length);
|
|
182
|
+
var result = Uint8Array.from(atob(base64Str), function(c) {
|
|
183
|
+
return c.charCodeAt(0);
|
|
184
|
+
});
|
|
185
|
+
resolve(result.buffer);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return this.request(url, _extends({}, item, {
|
|
189
|
+
type: "arraybuffer"
|
|
190
|
+
}));
|
|
191
|
+
};
|
|
192
|
+
return BufferLoader;
|
|
193
|
+
}(Loader);
|
|
194
|
+
BufferLoader = __decorate([
|
|
195
|
+
resourceLoader(AssetType.Buffer, [
|
|
196
|
+
"bin",
|
|
197
|
+
"r3bin"
|
|
198
|
+
], false)
|
|
199
|
+
], BufferLoader);
|
|
200
|
+
|
|
201
|
+
var EnvLoader = /*#__PURE__*/ function(Loader) {
|
|
202
|
+
_inherits(EnvLoader, Loader);
|
|
203
|
+
function EnvLoader() {
|
|
204
|
+
return Loader.apply(this, arguments);
|
|
205
|
+
}
|
|
206
|
+
var _proto = EnvLoader.prototype;
|
|
207
|
+
_proto.load = function load(item, resourceManager) {
|
|
208
|
+
var _this = this;
|
|
209
|
+
return new AssetPromise(function(resolve, reject) {
|
|
210
|
+
_this.request(item.url, {
|
|
211
|
+
type: "arraybuffer"
|
|
212
|
+
}).then(function(arraybuffer) {
|
|
213
|
+
var _ref;
|
|
214
|
+
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
215
|
+
var shByteLength = 27 * 4;
|
|
216
|
+
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
217
|
+
var texture = new TextureCube(resourceManager.engine, size);
|
|
218
|
+
texture.filterMode = TextureFilterMode.Trilinear;
|
|
219
|
+
var mipmapCount = texture.mipmapCount;
|
|
220
|
+
var offset = shByteLength + 2;
|
|
221
|
+
for(var mipLevel = 0; mipLevel < mipmapCount; mipLevel++){
|
|
222
|
+
var mipSize = size >> mipLevel;
|
|
223
|
+
for(var face = 0; face < 6; face++){
|
|
224
|
+
var dataSize = mipSize * mipSize * 4;
|
|
225
|
+
var data = new Uint8Array(arraybuffer, offset, dataSize);
|
|
226
|
+
offset += dataSize;
|
|
227
|
+
texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var ambientLight = new AmbientLight();
|
|
231
|
+
var sh = new SphericalHarmonics3();
|
|
232
|
+
ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
|
|
233
|
+
sh.copyFromArray(shArray);
|
|
234
|
+
ambientLight.diffuseSphericalHarmonics = sh;
|
|
235
|
+
ambientLight.specularTexture = texture;
|
|
236
|
+
ambientLight.specularTextureDecodeRGBM = true;
|
|
237
|
+
resolve(ambientLight);
|
|
238
|
+
}).catch(function(e) {
|
|
239
|
+
reject(e);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
return EnvLoader;
|
|
244
|
+
}(Loader);
|
|
245
|
+
EnvLoader = __decorate([
|
|
246
|
+
resourceLoader(AssetType.Env, [
|
|
247
|
+
"env"
|
|
248
|
+
])
|
|
249
|
+
], EnvLoader);
|
|
250
|
+
|
|
251
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
252
|
+
try {
|
|
253
|
+
var info = gen[key](arg);
|
|
254
|
+
var value = info.value;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
reject(error);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (info.done) resolve(value);
|
|
260
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
261
|
+
}
|
|
262
|
+
function _async_to_generator(fn) {
|
|
263
|
+
return function() {
|
|
264
|
+
var self = this, args = arguments;
|
|
265
|
+
|
|
266
|
+
return new Promise(function(resolve, reject) {
|
|
267
|
+
var gen = fn.apply(self, args);
|
|
268
|
+
|
|
269
|
+
function _next(value) {
|
|
270
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function _throw(err) {
|
|
274
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_next(undefined);
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
var FontLoader = /*#__PURE__*/ function(Loader) {
|
|
283
|
+
_inherits(FontLoader, Loader);
|
|
284
|
+
function FontLoader() {
|
|
285
|
+
return Loader.apply(this, arguments);
|
|
286
|
+
}
|
|
287
|
+
var _proto = FontLoader.prototype;
|
|
288
|
+
_proto.load = function load(item, resourceManager) {
|
|
289
|
+
var _this = this;
|
|
290
|
+
return new AssetPromise(function(resolve, reject) {
|
|
291
|
+
_this.request(item.url, {
|
|
292
|
+
type: "json"
|
|
293
|
+
}).then(function(data) {
|
|
294
|
+
var fontName = data.fontName, fontUrl = data.fontUrl;
|
|
295
|
+
if (fontUrl) {
|
|
296
|
+
_this._registerFont(fontName, fontUrl).then(function() {
|
|
297
|
+
var font = new Font(resourceManager.engine, fontName);
|
|
298
|
+
resolve(font);
|
|
299
|
+
}).catch(function(e) {
|
|
300
|
+
reject("load font " + fontUrl + " fail");
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
var font = new Font(resourceManager.engine, fontName);
|
|
304
|
+
resolve(font);
|
|
305
|
+
}
|
|
306
|
+
}).catch(function(e) {
|
|
307
|
+
reject(e);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
312
|
+
return _async_to_generator(function() {
|
|
313
|
+
var fontFace;
|
|
314
|
+
return __generator(this, function(_state) {
|
|
315
|
+
switch(_state.label){
|
|
316
|
+
case 0:
|
|
317
|
+
fontFace = new FontFace(fontName, "url(" + fontUrl + ")");
|
|
318
|
+
return [
|
|
319
|
+
4,
|
|
320
|
+
fontFace.load()
|
|
321
|
+
];
|
|
322
|
+
case 1:
|
|
323
|
+
_state.sent();
|
|
324
|
+
document.fonts.add(fontFace);
|
|
325
|
+
return [
|
|
326
|
+
2
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
})();
|
|
331
|
+
};
|
|
332
|
+
return FontLoader;
|
|
333
|
+
}(Loader);
|
|
334
|
+
FontLoader = __decorate([
|
|
335
|
+
resourceLoader(AssetType.Font, [
|
|
336
|
+
"font"
|
|
337
|
+
], false)
|
|
338
|
+
], FontLoader);
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @internal
|
|
342
|
+
*/ var ParserContext = /*#__PURE__*/ function() {
|
|
343
|
+
function ParserContext(url) {
|
|
344
|
+
this.hasSkinned = false;
|
|
345
|
+
/** chain asset promise */ this.chainPromises = [];
|
|
346
|
+
this.accessorBufferCache = {};
|
|
347
|
+
this.texturesPromiseInfo = new PromiseInfo();
|
|
348
|
+
this.materialsPromiseInfo = new PromiseInfo();
|
|
349
|
+
this.meshesPromiseInfo = new PromiseInfo();
|
|
350
|
+
this.animationClipsPromiseInfo = new PromiseInfo();
|
|
351
|
+
this.defaultSceneRootPromiseInfo = new PromiseInfo();
|
|
352
|
+
this.masterPromiseInfo = new PromiseInfo();
|
|
353
|
+
this.promiseMap = {};
|
|
354
|
+
var promiseMap = this.promiseMap;
|
|
355
|
+
promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
|
|
356
|
+
promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
|
|
357
|
+
promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
|
|
358
|
+
promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
|
|
359
|
+
promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
|
|
360
|
+
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
361
|
+
}
|
|
362
|
+
var _proto = ParserContext.prototype;
|
|
363
|
+
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
364
|
+
var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
365
|
+
promiseInfo.resolve = resolve;
|
|
366
|
+
promiseInfo.reject = reject;
|
|
367
|
+
promiseInfo.setProgress = setProgress;
|
|
368
|
+
promiseInfo.onCancel = onCancel;
|
|
369
|
+
});
|
|
370
|
+
promiseInfo.promise = promise;
|
|
371
|
+
return promise;
|
|
372
|
+
};
|
|
373
|
+
return ParserContext;
|
|
374
|
+
}();
|
|
375
|
+
/**
|
|
376
|
+
* @internal
|
|
377
|
+
*/ var BufferInfo = function BufferInfo(data, interleaved, stride) {
|
|
378
|
+
this.data = data;
|
|
379
|
+
this.interleaved = interleaved;
|
|
380
|
+
this.stride = stride;
|
|
381
|
+
this.vertexBindingInfos = {};
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* @internal
|
|
385
|
+
*/ var PromiseInfo = function PromiseInfo() {
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Module for glTF 2.0 Interface
|
|
390
|
+
*/ var AccessorComponentType;
|
|
391
|
+
(function(AccessorComponentType) {
|
|
392
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
393
|
+
* Byte
|
|
394
|
+
*/ "BYTE"] = 5120] = "BYTE";
|
|
395
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
396
|
+
* Unsigned Byte
|
|
397
|
+
*/ "UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
|
|
398
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
399
|
+
* Short
|
|
400
|
+
*/ "SHORT"] = 5122] = "SHORT";
|
|
401
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
402
|
+
* Unsigned Short
|
|
403
|
+
*/ "UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
|
|
404
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
405
|
+
* Unsigned Int
|
|
406
|
+
*/ "UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
|
|
407
|
+
AccessorComponentType[AccessorComponentType[/**
|
|
408
|
+
* Float
|
|
409
|
+
*/ "FLOAT"] = 5126] = "FLOAT";
|
|
410
|
+
})(AccessorComponentType || (AccessorComponentType = {}));
|
|
411
|
+
var AccessorType;
|
|
412
|
+
(function(AccessorType) {
|
|
413
|
+
AccessorType[/**
|
|
414
|
+
* Scalar
|
|
415
|
+
*/ "SCALAR"] = "SCALAR";
|
|
416
|
+
AccessorType[/**
|
|
417
|
+
* Vector2
|
|
418
|
+
*/ "VEC2"] = "VEC2";
|
|
419
|
+
AccessorType[/**
|
|
420
|
+
* Vector3
|
|
421
|
+
*/ "VEC3"] = "VEC3";
|
|
422
|
+
AccessorType[/**
|
|
423
|
+
* Vector4
|
|
424
|
+
*/ "VEC4"] = "VEC4";
|
|
425
|
+
AccessorType[/**
|
|
426
|
+
* Matrix2x2
|
|
427
|
+
*/ "MAT2"] = "MAT2";
|
|
428
|
+
AccessorType[/**
|
|
429
|
+
* Matrix3x3
|
|
430
|
+
*/ "MAT3"] = "MAT3";
|
|
431
|
+
AccessorType[/**
|
|
432
|
+
* Matrix4x4
|
|
433
|
+
*/ "MAT4"] = "MAT4";
|
|
434
|
+
})(AccessorType || (AccessorType = {}));
|
|
435
|
+
var AnimationChannelTargetPath;
|
|
436
|
+
(function(AnimationChannelTargetPath) {
|
|
437
|
+
AnimationChannelTargetPath[/**
|
|
438
|
+
* Translation
|
|
439
|
+
*/ "TRANSLATION"] = "translation";
|
|
440
|
+
AnimationChannelTargetPath[/**
|
|
441
|
+
* Rotation
|
|
442
|
+
*/ "ROTATION"] = "rotation";
|
|
443
|
+
AnimationChannelTargetPath[/**
|
|
444
|
+
* Scale
|
|
445
|
+
*/ "SCALE"] = "scale";
|
|
446
|
+
AnimationChannelTargetPath[/**
|
|
447
|
+
* Weights
|
|
448
|
+
*/ "WEIGHTS"] = "weights";
|
|
449
|
+
})(AnimationChannelTargetPath || (AnimationChannelTargetPath = {}));
|
|
450
|
+
var AnimationSamplerInterpolation;
|
|
451
|
+
(function(AnimationSamplerInterpolation) {
|
|
452
|
+
AnimationSamplerInterpolation[/**
|
|
453
|
+
* The animated values are linearly interpolated between keyframes
|
|
454
|
+
*/ "Linear"] = "LINEAR";
|
|
455
|
+
AnimationSamplerInterpolation[/**
|
|
456
|
+
* The animated values remain constant to the output of the first keyframe, until the next keyframe
|
|
457
|
+
*/ "Step"] = "STEP";
|
|
458
|
+
AnimationSamplerInterpolation[/**
|
|
459
|
+
* The animation's interpolation is computed using a cubic spline with specified tangents
|
|
460
|
+
*/ "CubicSpine"] = "CUBICSPLINE";
|
|
461
|
+
})(AnimationSamplerInterpolation || (AnimationSamplerInterpolation = {}));
|
|
462
|
+
var CameraType;
|
|
463
|
+
(function(CameraType) {
|
|
464
|
+
CameraType[/**
|
|
465
|
+
* A perspective camera containing properties to create a perspective projection matrix
|
|
466
|
+
*/ "PERSPECTIVE"] = "perspective";
|
|
467
|
+
CameraType[/**
|
|
468
|
+
* An orthographic camera containing properties to create an orthographic projection matrix
|
|
469
|
+
*/ "ORTHOGRAPHIC"] = "orthographic";
|
|
470
|
+
})(CameraType || (CameraType = {}));
|
|
471
|
+
var ImageMimeType;
|
|
472
|
+
(function(ImageMimeType) {
|
|
473
|
+
ImageMimeType[/**
|
|
474
|
+
* JPEG Mime-type
|
|
475
|
+
*/ "JPEG"] = "image/jpeg";
|
|
476
|
+
ImageMimeType[/**
|
|
477
|
+
* PNG Mime-type
|
|
478
|
+
*/ "PNG"] = "image/png";
|
|
479
|
+
})(ImageMimeType || (ImageMimeType = {}));
|
|
480
|
+
var MaterialAlphaMode;
|
|
481
|
+
(function(MaterialAlphaMode) {
|
|
482
|
+
MaterialAlphaMode[/**
|
|
483
|
+
* The alpha value is ignored and the rendered output is fully opaque
|
|
484
|
+
*/ "OPAQUE"] = "OPAQUE";
|
|
485
|
+
MaterialAlphaMode[/**
|
|
486
|
+
* The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value
|
|
487
|
+
*/ "MASK"] = "MASK";
|
|
488
|
+
MaterialAlphaMode[/**
|
|
489
|
+
* The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator)
|
|
490
|
+
*/ "BLEND"] = "BLEND";
|
|
491
|
+
})(MaterialAlphaMode || (MaterialAlphaMode = {}));
|
|
492
|
+
var TextureMagFilter;
|
|
493
|
+
(function(TextureMagFilter) {
|
|
494
|
+
TextureMagFilter[TextureMagFilter[/**
|
|
495
|
+
* Nearest
|
|
496
|
+
*/ "NEAREST"] = 9728] = "NEAREST";
|
|
497
|
+
TextureMagFilter[TextureMagFilter[/**
|
|
498
|
+
* Linear
|
|
499
|
+
*/ "LINEAR"] = 9729] = "LINEAR";
|
|
500
|
+
})(TextureMagFilter || (TextureMagFilter = {}));
|
|
501
|
+
var TextureMinFilter;
|
|
502
|
+
(function(TextureMinFilter) {
|
|
503
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
504
|
+
* Nearest
|
|
505
|
+
*/ "NEAREST"] = 9728] = "NEAREST";
|
|
506
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
507
|
+
* Linear
|
|
508
|
+
*/ "LINEAR"] = 9729] = "LINEAR";
|
|
509
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
510
|
+
* Nearest Mip-Map Nearest
|
|
511
|
+
*/ "NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
|
|
512
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
513
|
+
* Linear Mipmap Nearest
|
|
514
|
+
*/ "LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
|
|
515
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
516
|
+
* Nearest Mipmap Linear
|
|
517
|
+
*/ "NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
|
|
518
|
+
TextureMinFilter[TextureMinFilter[/**
|
|
519
|
+
* Linear Mipmap Linear
|
|
520
|
+
*/ "LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
|
|
521
|
+
})(TextureMinFilter || (TextureMinFilter = {}));
|
|
522
|
+
var TextureWrapMode;
|
|
523
|
+
(function(TextureWrapMode) {
|
|
524
|
+
TextureWrapMode[TextureWrapMode[/**
|
|
525
|
+
* Clamp to Edge
|
|
526
|
+
*/ "CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
|
|
527
|
+
TextureWrapMode[TextureWrapMode[/**
|
|
528
|
+
* Mirrored Repeat
|
|
529
|
+
*/ "MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
|
|
530
|
+
TextureWrapMode[TextureWrapMode[/**
|
|
531
|
+
* Repeat
|
|
532
|
+
*/ "REPEAT"] = 10497] = "REPEAT";
|
|
533
|
+
})(TextureWrapMode || (TextureWrapMode = {}));
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @internal
|
|
537
|
+
*/ var GLTFUtil = /*#__PURE__*/ function() {
|
|
538
|
+
function GLTFUtil() {}
|
|
539
|
+
GLTFUtil.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
|
|
540
|
+
var bufferLen = buffer.length;
|
|
541
|
+
var array = new Array(bufferLen / 2);
|
|
542
|
+
for(var i = 0; i < bufferLen; i += 2){
|
|
543
|
+
array[i / 2] = new Vector2(buffer[i], buffer[i + 1]);
|
|
544
|
+
}
|
|
545
|
+
return array;
|
|
546
|
+
};
|
|
547
|
+
GLTFUtil.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
|
|
548
|
+
var bufferLen = buffer.length;
|
|
549
|
+
var array = new Array(bufferLen / 3);
|
|
550
|
+
for(var i = 0; i < bufferLen; i += 3){
|
|
551
|
+
array[i / 3] = new Vector3(buffer[i], buffer[i + 1], buffer[i + 2]);
|
|
552
|
+
}
|
|
553
|
+
return array;
|
|
554
|
+
};
|
|
555
|
+
GLTFUtil.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
|
|
556
|
+
var bufferLen = buffer.length;
|
|
557
|
+
var array = new Array(bufferLen / 4);
|
|
558
|
+
for(var i = 0; i < bufferLen; i += 4){
|
|
559
|
+
array[i / 4] = new Vector4(buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3]);
|
|
560
|
+
}
|
|
561
|
+
return array;
|
|
562
|
+
};
|
|
563
|
+
GLTFUtil.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
|
|
564
|
+
var bufferLen = buffer.length;
|
|
565
|
+
var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
|
|
566
|
+
if (isColor3) {
|
|
567
|
+
for(var i = 0; i < bufferLen; i += 3){
|
|
568
|
+
colors[i / 3] = new Color(buffer[i], buffer[i + 1], buffer[i + 2], 1.0);
|
|
569
|
+
}
|
|
570
|
+
} else {
|
|
571
|
+
for(var i1 = 0; i1 < bufferLen; i1 += 4){
|
|
572
|
+
colors[i1 / 4] = new Color(buffer[i1], buffer[i1 + 1], buffer[i1 + 2], buffer[i1 + 3]);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return colors;
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* Parse binary text for glb loader.
|
|
579
|
+
*/ GLTFUtil.decodeText = function decodeText(array) {
|
|
580
|
+
if (typeof TextDecoder !== "undefined") {
|
|
581
|
+
return new TextDecoder().decode(array);
|
|
582
|
+
}
|
|
583
|
+
// TextDecoder polyfill
|
|
584
|
+
var s = "";
|
|
585
|
+
for(var i = 0, il = array.length; i < il; i++){
|
|
586
|
+
s += String.fromCharCode(array[i]);
|
|
587
|
+
}
|
|
588
|
+
return decodeURIComponent(encodeURIComponent(s));
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Get the number of bytes occupied by accessor type.
|
|
592
|
+
*/ GLTFUtil.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
|
|
593
|
+
switch(accessorType){
|
|
594
|
+
case AccessorType.SCALAR:
|
|
595
|
+
return 1;
|
|
596
|
+
case AccessorType.VEC2:
|
|
597
|
+
return 2;
|
|
598
|
+
case AccessorType.VEC3:
|
|
599
|
+
return 3;
|
|
600
|
+
case AccessorType.VEC4:
|
|
601
|
+
return 4;
|
|
602
|
+
case AccessorType.MAT2:
|
|
603
|
+
return 4;
|
|
604
|
+
case AccessorType.MAT3:
|
|
605
|
+
return 9;
|
|
606
|
+
case AccessorType.MAT4:
|
|
607
|
+
return 16;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* Get the TypedArray corresponding to the component type.
|
|
612
|
+
*/ GLTFUtil.getComponentType = function getComponentType(componentType) {
|
|
613
|
+
switch(componentType){
|
|
614
|
+
case AccessorComponentType.BYTE:
|
|
615
|
+
return Int8Array;
|
|
616
|
+
case AccessorComponentType.UNSIGNED_BYTE:
|
|
617
|
+
return Uint8Array;
|
|
618
|
+
case AccessorComponentType.SHORT:
|
|
619
|
+
return Int16Array;
|
|
620
|
+
case AccessorComponentType.UNSIGNED_SHORT:
|
|
621
|
+
return Uint16Array;
|
|
622
|
+
case AccessorComponentType.UNSIGNED_INT:
|
|
623
|
+
return Uint32Array;
|
|
624
|
+
case AccessorComponentType.FLOAT:
|
|
625
|
+
return Float32Array;
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
GLTFUtil.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
|
|
629
|
+
// Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
|
|
630
|
+
switch(componentType){
|
|
631
|
+
case AccessorComponentType.BYTE:
|
|
632
|
+
return 1 / 127;
|
|
633
|
+
case AccessorComponentType.UNSIGNED_BYTE:
|
|
634
|
+
return 1 / 255;
|
|
635
|
+
case AccessorComponentType.SHORT:
|
|
636
|
+
return 1 / 32767;
|
|
637
|
+
case AccessorComponentType.UNSIGNED_SHORT:
|
|
638
|
+
return 1 / 65535;
|
|
639
|
+
default:
|
|
640
|
+
throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
|
|
644
|
+
var buffers = context.buffers;
|
|
645
|
+
var bufferViews = gltf.bufferViews;
|
|
646
|
+
var componentType = accessor.componentType;
|
|
647
|
+
var bufferView = bufferViews[accessor.bufferView];
|
|
648
|
+
var buffer = buffers[bufferView.buffer];
|
|
649
|
+
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
650
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
651
|
+
var TypedArray = GLTFUtil.getComponentType(componentType);
|
|
652
|
+
var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
653
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
654
|
+
var elementStride = dataElmentSize * dataElementBytes;
|
|
655
|
+
var accessorCount = accessor.count;
|
|
656
|
+
var bufferStride = bufferView.byteStride;
|
|
657
|
+
var bufferInfo;
|
|
658
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
659
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
660
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
661
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
662
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
663
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
664
|
+
if (!bufferInfo) {
|
|
665
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
666
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
667
|
+
var data = new TypedArray(buffer, offset, count);
|
|
668
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
669
|
+
}
|
|
670
|
+
} else {
|
|
671
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
672
|
+
var count1 = accessorCount * dataElmentSize;
|
|
673
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
674
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
675
|
+
}
|
|
676
|
+
if (accessor.sparse) {
|
|
677
|
+
var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
|
|
678
|
+
bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
|
|
679
|
+
}
|
|
680
|
+
return bufferInfo;
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* @deprecated
|
|
684
|
+
* Get accessor data.
|
|
685
|
+
*/ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
|
|
686
|
+
var bufferViews = gltf.bufferViews;
|
|
687
|
+
var bufferView = bufferViews[accessor.bufferView];
|
|
688
|
+
var arrayBuffer = buffers[bufferView.buffer];
|
|
689
|
+
var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
|
|
690
|
+
var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
|
|
691
|
+
var byteOffset = accessorByteOffset + bufferViewByteOffset;
|
|
692
|
+
var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
693
|
+
var length = accessorTypeSize * accessor.count;
|
|
694
|
+
var _bufferView_byteStride;
|
|
695
|
+
var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
|
|
696
|
+
var arrayType = GLTFUtil.getComponentType(accessor.componentType);
|
|
697
|
+
var uint8Array;
|
|
698
|
+
if (byteStride) {
|
|
699
|
+
var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
|
|
700
|
+
uint8Array = new Uint8Array(accessor.count * accessorByteSize);
|
|
701
|
+
var originalBufferView = new Uint8Array(arrayBuffer, bufferViewByteOffset, bufferView.byteLength);
|
|
702
|
+
for(var i = 0; i < accessor.count; i++){
|
|
703
|
+
for(var j = 0; j < accessorByteSize; j++){
|
|
704
|
+
uint8Array[i * accessorByteSize + j] = originalBufferView[i * byteStride + accessorByteOffset + j];
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
} else {
|
|
708
|
+
uint8Array = new Uint8Array(arrayBuffer.slice(byteOffset, byteOffset + length * arrayType.BYTES_PER_ELEMENT));
|
|
709
|
+
}
|
|
710
|
+
var typedArray = new arrayType(uint8Array.buffer);
|
|
711
|
+
if (accessor.sparse) {
|
|
712
|
+
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
713
|
+
var indicesBufferView = bufferViews[indices.bufferView];
|
|
714
|
+
var valuesBufferView = bufferViews[values.bufferView];
|
|
715
|
+
var indicesArrayBuffer = buffers[indicesBufferView.buffer];
|
|
716
|
+
var valuesArrayBuffer = buffers[valuesBufferView.buffer];
|
|
717
|
+
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
718
|
+
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
719
|
+
var indicesByteLength = indicesBufferView.byteLength;
|
|
720
|
+
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
721
|
+
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
722
|
+
var valuesByteLength = valuesBufferView.byteLength;
|
|
723
|
+
var indicesType = GLTFUtil.getComponentType(indices.componentType);
|
|
724
|
+
var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
|
|
725
|
+
var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
|
|
726
|
+
for(var i1 = 0; i1 < count; i1++){
|
|
727
|
+
var replaceIndex = indicesArray[i1];
|
|
728
|
+
for(var j1 = 0; j1 < accessorTypeSize; j1++){
|
|
729
|
+
typedArray[replaceIndex * accessorTypeSize + j1] = valuesArray[i1 * accessorTypeSize + j1];
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return typedArray;
|
|
734
|
+
};
|
|
735
|
+
GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
|
|
736
|
+
var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
|
|
737
|
+
var arrayBuffer = buffers[buffer];
|
|
738
|
+
return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
739
|
+
};
|
|
740
|
+
/**
|
|
741
|
+
* Get accessor data.
|
|
742
|
+
*/ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
|
|
743
|
+
var bufferViews = gltf.bufferViews;
|
|
744
|
+
var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
745
|
+
var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
|
|
746
|
+
var data = originData.slice();
|
|
747
|
+
var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
|
|
748
|
+
var indicesBufferView = bufferViews[indices.bufferView];
|
|
749
|
+
var valuesBufferView = bufferViews[values.bufferView];
|
|
750
|
+
var indicesArrayBuffer = buffers[indicesBufferView.buffer];
|
|
751
|
+
var valuesArrayBuffer = buffers[valuesBufferView.buffer];
|
|
752
|
+
var _indices_byteOffset, _indicesBufferView_byteOffset;
|
|
753
|
+
var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
|
|
754
|
+
var indicesByteLength = indicesBufferView.byteLength;
|
|
755
|
+
var _values_byteOffset, _valuesBufferView_byteOffset;
|
|
756
|
+
var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
|
|
757
|
+
var valuesByteLength = valuesBufferView.byteLength;
|
|
758
|
+
var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
|
|
759
|
+
var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
|
|
760
|
+
var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
|
|
761
|
+
for(var i = 0; i < count; i++){
|
|
762
|
+
var replaceIndex = indicesArray[i];
|
|
763
|
+
for(var j = 0; j < accessorTypeSize; j++){
|
|
764
|
+
data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return data;
|
|
768
|
+
};
|
|
769
|
+
GLTFUtil.getIndexFormat = function getIndexFormat(type) {
|
|
770
|
+
switch(type){
|
|
771
|
+
case AccessorComponentType.UNSIGNED_BYTE:
|
|
772
|
+
return IndexFormat.UInt8;
|
|
773
|
+
case AccessorComponentType.UNSIGNED_SHORT:
|
|
774
|
+
return IndexFormat.UInt16;
|
|
775
|
+
case AccessorComponentType.UNSIGNED_INT:
|
|
776
|
+
return IndexFormat.UInt32;
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
GLTFUtil.getElementFormat = function getElementFormat(type, size, normalized) {
|
|
780
|
+
if (normalized === void 0) normalized = false;
|
|
781
|
+
if (type == AccessorComponentType.FLOAT) {
|
|
782
|
+
switch(size){
|
|
783
|
+
case 1:
|
|
784
|
+
return VertexElementFormat.Float;
|
|
785
|
+
case 2:
|
|
786
|
+
return VertexElementFormat.Vector2;
|
|
787
|
+
case 3:
|
|
788
|
+
return VertexElementFormat.Vector3;
|
|
789
|
+
case 4:
|
|
790
|
+
return VertexElementFormat.Vector4;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (type == AccessorComponentType.SHORT) {
|
|
794
|
+
switch(size){
|
|
795
|
+
case 2:
|
|
796
|
+
return normalized ? VertexElementFormat.NormalizedShort2 : VertexElementFormat.Short2;
|
|
797
|
+
case 3:
|
|
798
|
+
case 4:
|
|
799
|
+
return normalized ? VertexElementFormat.NormalizedShort4 : VertexElementFormat.Short4;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (type == AccessorComponentType.UNSIGNED_SHORT) {
|
|
803
|
+
switch(size){
|
|
804
|
+
case 2:
|
|
805
|
+
return normalized ? VertexElementFormat.NormalizedUShort2 : VertexElementFormat.UShort2;
|
|
806
|
+
case 3:
|
|
807
|
+
case 4:
|
|
808
|
+
return normalized ? VertexElementFormat.NormalizedUShort4 : VertexElementFormat.UShort4;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (type == AccessorComponentType.BYTE) {
|
|
812
|
+
switch(size){
|
|
813
|
+
case 2:
|
|
814
|
+
case 3:
|
|
815
|
+
case 4:
|
|
816
|
+
return normalized ? VertexElementFormat.NormalizedByte4 : VertexElementFormat.Byte4;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (type == AccessorComponentType.UNSIGNED_BYTE) {
|
|
820
|
+
switch(size){
|
|
821
|
+
case 2:
|
|
822
|
+
case 3:
|
|
823
|
+
case 4:
|
|
824
|
+
return normalized ? VertexElementFormat.NormalizedUByte4 : VertexElementFormat.UByte4;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Load image buffer
|
|
830
|
+
*/ GLTFUtil.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
|
|
831
|
+
return new Promise(function(resolve, reject) {
|
|
832
|
+
var blob = new window.Blob([
|
|
833
|
+
imageBuffer
|
|
834
|
+
], {
|
|
835
|
+
type: type
|
|
836
|
+
});
|
|
837
|
+
var img = new Image();
|
|
838
|
+
img.onerror = function() {
|
|
839
|
+
reject(new Error("Failed to load image buffer"));
|
|
840
|
+
};
|
|
841
|
+
img.onload = function() {
|
|
842
|
+
// Call requestAnimationFrame to avoid iOS's bug.
|
|
843
|
+
requestAnimationFrame(function() {
|
|
844
|
+
resolve(img);
|
|
845
|
+
img.onload = null;
|
|
846
|
+
img.onerror = null;
|
|
847
|
+
img.onabort = null;
|
|
848
|
+
});
|
|
849
|
+
};
|
|
850
|
+
img.crossOrigin = "anonymous";
|
|
851
|
+
img.src = URL.createObjectURL(blob);
|
|
852
|
+
});
|
|
853
|
+
};
|
|
854
|
+
GLTFUtil.isAbsoluteUrl = function isAbsoluteUrl(url) {
|
|
855
|
+
return /^(?:http|blob|data:|\/)/.test(url);
|
|
856
|
+
};
|
|
857
|
+
GLTFUtil.parseRelativeUrl = function parseRelativeUrl(baseUrl, relativeUrl) {
|
|
858
|
+
if (GLTFUtil.isAbsoluteUrl(relativeUrl)) {
|
|
859
|
+
return relativeUrl;
|
|
860
|
+
}
|
|
861
|
+
return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + GLTFUtil._formatRelativePath(relativeUrl);
|
|
862
|
+
};
|
|
863
|
+
/**
|
|
864
|
+
* Parse the glb format.
|
|
865
|
+
*/ GLTFUtil.parseGLB = function parseGLB(glb) {
|
|
866
|
+
var UINT32_LENGTH = 4;
|
|
867
|
+
var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
|
|
868
|
+
var GLB_HEADER_LENGTH = 12;
|
|
869
|
+
var GLB_CHUNK_TYPES = {
|
|
870
|
+
JSON: 0x4e4f534a,
|
|
871
|
+
BIN: 0x004e4942
|
|
872
|
+
};
|
|
873
|
+
var dataView = new DataView(glb);
|
|
874
|
+
// read header
|
|
875
|
+
var header = {
|
|
876
|
+
magic: dataView.getUint32(0, true),
|
|
877
|
+
version: dataView.getUint32(UINT32_LENGTH, true),
|
|
878
|
+
length: dataView.getUint32(2 * UINT32_LENGTH, true)
|
|
879
|
+
};
|
|
880
|
+
if (header.magic !== GLB_HEADER_MAGIC) {
|
|
881
|
+
console.error("Invalid glb magic number. Expected 0x46546C67, found 0x" + header.magic.toString(16));
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
// read main data
|
|
885
|
+
var chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true);
|
|
886
|
+
var chunkType = dataView.getUint32(GLB_HEADER_LENGTH + UINT32_LENGTH, true);
|
|
887
|
+
// read glTF json
|
|
888
|
+
if (chunkType !== GLB_CHUNK_TYPES.JSON) {
|
|
889
|
+
console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16));
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
|
|
893
|
+
var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
|
|
894
|
+
// read all buffers
|
|
895
|
+
var buffers = [];
|
|
896
|
+
var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
|
|
897
|
+
while(byteOffset < header.length){
|
|
898
|
+
chunkLength = dataView.getUint32(byteOffset, true);
|
|
899
|
+
chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
|
|
900
|
+
if (chunkType !== GLB_CHUNK_TYPES.BIN) {
|
|
901
|
+
console.error("Invalid glb chunk type. Expected 0x004E4942, found 0x" + chunkType.toString(16));
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
var currentOffset = byteOffset + 2 * UINT32_LENGTH;
|
|
905
|
+
var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
|
|
906
|
+
buffers.push(buffer);
|
|
907
|
+
byteOffset += chunkLength + 2 * UINT32_LENGTH;
|
|
908
|
+
}
|
|
909
|
+
return {
|
|
910
|
+
gltf: gltf,
|
|
911
|
+
buffers: buffers
|
|
912
|
+
};
|
|
913
|
+
};
|
|
914
|
+
GLTFUtil._formatRelativePath = function _formatRelativePath(path) {
|
|
915
|
+
// For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
|
|
916
|
+
return path.split("/").filter(Boolean).reduce(function(acc, cur) {
|
|
917
|
+
if (cur === "..") acc.pop();
|
|
918
|
+
else if (cur !== ".") acc.push(cur);
|
|
919
|
+
return acc;
|
|
920
|
+
}, []).join("/");
|
|
921
|
+
};
|
|
922
|
+
return GLTFUtil;
|
|
923
|
+
}();
|
|
924
|
+
|
|
925
|
+
function _array_like_to_array(arr, len) {
|
|
926
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
927
|
+
|
|
928
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
929
|
+
|
|
930
|
+
return arr2;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
function _array_without_holes(arr) {
|
|
934
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function _iterable_to_array(iter) {
|
|
938
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
939
|
+
return Array.from(iter);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function _non_iterable_spread() {
|
|
944
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
948
|
+
if (!o) return;
|
|
949
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
950
|
+
|
|
951
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
952
|
+
|
|
953
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
954
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
955
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function _to_consumable_array(arr) {
|
|
959
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
var Parser = /*#__PURE__*/ function() {
|
|
963
|
+
function Parser() {}
|
|
964
|
+
Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
|
|
965
|
+
for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
|
|
966
|
+
extra[_key - 4] = arguments[_key];
|
|
967
|
+
}
|
|
968
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
969
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
970
|
+
for(var i = 0; i < parsers.length; i++){
|
|
971
|
+
var _parsers_i;
|
|
972
|
+
(_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
|
|
973
|
+
extensionSchema,
|
|
974
|
+
parseResource,
|
|
975
|
+
context
|
|
976
|
+
].concat(_to_consumable_array(extra)));
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
|
|
981
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
982
|
+
extra[_key - 3] = arguments[_key];
|
|
983
|
+
}
|
|
984
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
985
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
986
|
+
var _parsers_;
|
|
987
|
+
return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
|
|
988
|
+
extensionSchema,
|
|
989
|
+
context
|
|
990
|
+
].concat(_to_consumable_array(extra)));
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
|
|
994
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
995
|
+
return !!(parsers == null ? void 0 : parsers.length);
|
|
996
|
+
};
|
|
997
|
+
Parser.initialize = function initialize(extensionName) {
|
|
998
|
+
var parsers = Parser._extensionParsers[extensionName];
|
|
999
|
+
if (parsers == null ? void 0 : parsers.length) {
|
|
1000
|
+
for(var i = 0; i < parsers.length; i++){
|
|
1001
|
+
parsers[i].initialize();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* @internal
|
|
1007
|
+
*/ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
|
|
1008
|
+
if (!Parser._extensionParsers[extensionName]) {
|
|
1009
|
+
Parser._extensionParsers[extensionName] = [];
|
|
1010
|
+
}
|
|
1011
|
+
Parser._extensionParsers[extensionName].push(extensionParser);
|
|
1012
|
+
};
|
|
1013
|
+
return Parser;
|
|
1014
|
+
}();
|
|
1015
|
+
(function() {
|
|
1016
|
+
Parser._extensionParsers = {};
|
|
1017
|
+
})();
|
|
1018
|
+
/**
|
|
1019
|
+
* Declare ExtensionParser's decorator.
|
|
1020
|
+
* @param extensionName - Extension name
|
|
1021
|
+
*/ function registerExtension(extensionName) {
|
|
1022
|
+
return function(parser) {
|
|
1023
|
+
var extensionParser = new parser();
|
|
1024
|
+
Parser._addExtensionParser(extensionName, extensionParser);
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
var ExtensionParser = /*#__PURE__*/ function() {
|
|
1029
|
+
function ExtensionParser() {}
|
|
1030
|
+
var _proto = ExtensionParser.prototype;
|
|
1031
|
+
_proto.initialize = function initialize() {};
|
|
1032
|
+
_proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
|
|
1033
|
+
for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
|
|
1034
|
+
extra[_key - 3] = arguments[_key];
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1038
|
+
for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
1039
|
+
extra[_key - 2] = arguments[_key];
|
|
1040
|
+
}
|
|
1041
|
+
return null;
|
|
1042
|
+
};
|
|
1043
|
+
return ExtensionParser;
|
|
1044
|
+
}();
|
|
1045
|
+
|
|
1046
|
+
var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
|
|
1047
|
+
_inherits(KHR_draco_mesh_compression1, ExtensionParser);
|
|
1048
|
+
function KHR_draco_mesh_compression1() {
|
|
1049
|
+
return ExtensionParser.apply(this, arguments);
|
|
1050
|
+
}
|
|
1051
|
+
var _proto = KHR_draco_mesh_compression1.prototype;
|
|
1052
|
+
_proto.initialize = function initialize() {
|
|
1053
|
+
if (!KHR_draco_mesh_compression._decoder) {
|
|
1054
|
+
KHR_draco_mesh_compression._decoder = new DRACODecoder();
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
_proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
|
|
1058
|
+
var gltf = context.gltf, buffers = context.buffers;
|
|
1059
|
+
var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
|
|
1060
|
+
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
1061
|
+
var attributeMap = {};
|
|
1062
|
+
var attributeTypeMap = {};
|
|
1063
|
+
for(var attributeName in gltfAttributeMap){
|
|
1064
|
+
attributeMap[attributeName] = gltfAttributeMap[attributeName];
|
|
1065
|
+
}
|
|
1066
|
+
for(var attributeName1 in gltfPrimitive.attributes){
|
|
1067
|
+
if (gltfAttributeMap[attributeName1] !== undefined) {
|
|
1068
|
+
var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
|
|
1069
|
+
attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
var indexAccessor = accessors[gltfPrimitive.indices];
|
|
1073
|
+
var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
|
|
1074
|
+
var taskConfig = {
|
|
1075
|
+
attributeIDs: attributeMap,
|
|
1076
|
+
attributeTypes: attributeTypeMap,
|
|
1077
|
+
useUniqueIDs: true,
|
|
1078
|
+
indexType: indexType
|
|
1079
|
+
};
|
|
1080
|
+
var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
1081
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
|
|
1082
|
+
return parsedGeometry;
|
|
1083
|
+
});
|
|
1084
|
+
};
|
|
1085
|
+
return KHR_draco_mesh_compression1;
|
|
1086
|
+
}(ExtensionParser);
|
|
1087
|
+
KHR_draco_mesh_compression = __decorate([
|
|
1088
|
+
registerExtension("KHR_draco_mesh_compression")
|
|
1089
|
+
], KHR_draco_mesh_compression);
|
|
1090
|
+
|
|
1091
|
+
function _instanceof(left, right) {
|
|
1092
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1093
|
+
return !!right[Symbol.hasInstance](left);
|
|
1094
|
+
} else return left instanceof right;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
|
|
1098
|
+
_inherits(KHR_lights_punctual, ExtensionParser);
|
|
1099
|
+
function KHR_lights_punctual() {
|
|
1100
|
+
return ExtensionParser.apply(this, arguments);
|
|
1101
|
+
}
|
|
1102
|
+
var _proto = KHR_lights_punctual.prototype;
|
|
1103
|
+
_proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
|
|
1104
|
+
var color = schema.color, _schema_intensity = schema.intensity, intensity = _schema_intensity === void 0 ? 1 : _schema_intensity, type = schema.type, range = schema.range, spot = schema.spot;
|
|
1105
|
+
var glTFResource = context.glTFResource;
|
|
1106
|
+
var light;
|
|
1107
|
+
if (type === "directional") {
|
|
1108
|
+
light = entity.addComponent(DirectLight);
|
|
1109
|
+
} else if (type === "point") {
|
|
1110
|
+
light = entity.addComponent(PointLight);
|
|
1111
|
+
} else if (type === "spot") {
|
|
1112
|
+
light = entity.addComponent(SpotLight);
|
|
1113
|
+
}
|
|
1114
|
+
if (color) {
|
|
1115
|
+
light.color.set(color[0], color[1], color[2], 1);
|
|
1116
|
+
}
|
|
1117
|
+
light.intensity = intensity;
|
|
1118
|
+
if (range && !_instanceof(light, DirectLight)) {
|
|
1119
|
+
light.distance = range;
|
|
1120
|
+
}
|
|
1121
|
+
if (spot && _instanceof(light, SpotLight)) {
|
|
1122
|
+
var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
|
|
1123
|
+
light.angle = innerConeAngle;
|
|
1124
|
+
light.penumbra = outerConeAngle - innerConeAngle;
|
|
1125
|
+
}
|
|
1126
|
+
if (!glTFResource.lights) glTFResource.lights = [];
|
|
1127
|
+
glTFResource.lights.push(light);
|
|
1128
|
+
};
|
|
1129
|
+
return KHR_lights_punctual;
|
|
1130
|
+
}(ExtensionParser);
|
|
1131
|
+
KHR_lights_punctual = __decorate([
|
|
1132
|
+
registerExtension("KHR_lights_punctual")
|
|
1133
|
+
], KHR_lights_punctual);
|
|
1134
|
+
|
|
1135
|
+
var MaterialParser = /*#__PURE__*/ function(Parser1) {
|
|
1136
|
+
_inherits(MaterialParser, Parser1);
|
|
1137
|
+
function MaterialParser() {
|
|
1138
|
+
return Parser1.apply(this, arguments);
|
|
1139
|
+
}
|
|
1140
|
+
var _proto = MaterialParser.prototype;
|
|
1141
|
+
_proto.parse = function parse(context) {
|
|
1142
|
+
var gltf = context.gltf, glTFResource = context.glTFResource;
|
|
1143
|
+
var engine = glTFResource.engine, textures = glTFResource.textures;
|
|
1144
|
+
if (!gltf.materials) return;
|
|
1145
|
+
var materialsPromiseInfo = context.materialsPromiseInfo;
|
|
1146
|
+
var materials = [];
|
|
1147
|
+
for(var i = 0; i < gltf.materials.length; i++){
|
|
1148
|
+
var _gltf_materials_i = gltf.materials[i], _gltf_materials_i_extensions = _gltf_materials_i.extensions, extensions = _gltf_materials_i_extensions === void 0 ? {} : _gltf_materials_i_extensions, pbrMetallicRoughness = _gltf_materials_i.pbrMetallicRoughness, normalTexture = _gltf_materials_i.normalTexture, occlusionTexture = _gltf_materials_i.occlusionTexture, emissiveTexture = _gltf_materials_i.emissiveTexture, emissiveFactor = _gltf_materials_i.emissiveFactor, alphaMode = _gltf_materials_i.alphaMode, alphaCutoff = _gltf_materials_i.alphaCutoff, doubleSided = _gltf_materials_i.doubleSided, _gltf_materials_i_name = _gltf_materials_i.name, name = _gltf_materials_i_name === void 0 ? "" : _gltf_materials_i_name;
|
|
1149
|
+
var KHR_materials_unlit = extensions.KHR_materials_unlit, KHR_materials_pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness, KHR_materials_clearcoat = extensions.KHR_materials_clearcoat, OASIS_materials_remap = extensions.OASIS_materials_remap;
|
|
1150
|
+
var material = null;
|
|
1151
|
+
if (KHR_materials_unlit) {
|
|
1152
|
+
material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
|
|
1153
|
+
} else if (KHR_materials_pbrSpecularGlossiness) {
|
|
1154
|
+
material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
|
|
1155
|
+
} else {
|
|
1156
|
+
material = new PBRMaterial(engine);
|
|
1157
|
+
}
|
|
1158
|
+
material.name = name;
|
|
1159
|
+
if (KHR_materials_clearcoat) {
|
|
1160
|
+
Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
|
|
1161
|
+
}
|
|
1162
|
+
if (pbrMetallicRoughness) {
|
|
1163
|
+
var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
|
|
1164
|
+
if (baseColorFactor) {
|
|
1165
|
+
material.baseColor = new Color(Color.linearToGammaSpace(baseColorFactor[0]), Color.linearToGammaSpace(baseColorFactor[1]), Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
|
|
1166
|
+
}
|
|
1167
|
+
if (baseColorTexture) {
|
|
1168
|
+
material.baseTexture = textures[baseColorTexture.index];
|
|
1169
|
+
MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
|
|
1170
|
+
}
|
|
1171
|
+
if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
|
|
1172
|
+
var m = material;
|
|
1173
|
+
m.metallic = metallicFactor != null ? metallicFactor : 1;
|
|
1174
|
+
m.roughness = roughnessFactor != null ? roughnessFactor : 1;
|
|
1175
|
+
if (metallicRoughnessTexture) {
|
|
1176
|
+
m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
|
|
1177
|
+
MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (!KHR_materials_unlit) {
|
|
1182
|
+
var m1 = material;
|
|
1183
|
+
if (emissiveTexture) {
|
|
1184
|
+
m1.emissiveTexture = textures[emissiveTexture.index];
|
|
1185
|
+
MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
|
|
1186
|
+
}
|
|
1187
|
+
if (emissiveFactor) {
|
|
1188
|
+
m1.emissiveColor = new Color(Color.linearToGammaSpace(emissiveFactor[0]), Color.linearToGammaSpace(emissiveFactor[1]), Color.linearToGammaSpace(emissiveFactor[2]));
|
|
1189
|
+
}
|
|
1190
|
+
if (normalTexture) {
|
|
1191
|
+
var index = normalTexture.index, scale = normalTexture.scale;
|
|
1192
|
+
m1.normalTexture = textures[index];
|
|
1193
|
+
MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
|
|
1194
|
+
if (scale !== undefined) {
|
|
1195
|
+
m1.normalTextureIntensity = scale;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
if (occlusionTexture) {
|
|
1199
|
+
var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
|
|
1200
|
+
m1.occlusionTexture = textures[index1];
|
|
1201
|
+
MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
|
|
1202
|
+
if (strength !== undefined) {
|
|
1203
|
+
m1.occlusionTextureIntensity = strength;
|
|
1204
|
+
}
|
|
1205
|
+
if (texCoord === TextureCoordinate.UV1) {
|
|
1206
|
+
m1.occlusionTextureCoord = TextureCoordinate.UV1;
|
|
1207
|
+
} else if (texCoord > TextureCoordinate.UV1) {
|
|
1208
|
+
Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
if (OASIS_materials_remap) {
|
|
1213
|
+
var _gltf_extensions;
|
|
1214
|
+
gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
|
|
1215
|
+
var _gltf_extensions_OASIS_materials_remap;
|
|
1216
|
+
gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
|
|
1217
|
+
gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
|
|
1218
|
+
}
|
|
1219
|
+
if (doubleSided) {
|
|
1220
|
+
material.renderFace = RenderFace.Double;
|
|
1221
|
+
} else {
|
|
1222
|
+
material.renderFace = RenderFace.Front;
|
|
1223
|
+
}
|
|
1224
|
+
switch(alphaMode){
|
|
1225
|
+
case MaterialAlphaMode.OPAQUE:
|
|
1226
|
+
material.isTransparent = false;
|
|
1227
|
+
break;
|
|
1228
|
+
case MaterialAlphaMode.BLEND:
|
|
1229
|
+
material.isTransparent = true;
|
|
1230
|
+
break;
|
|
1231
|
+
case MaterialAlphaMode.MASK:
|
|
1232
|
+
material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
materials[i] = material;
|
|
1236
|
+
}
|
|
1237
|
+
glTFResource.materials = materials;
|
|
1238
|
+
materialsPromiseInfo.resolve(materials);
|
|
1239
|
+
return materialsPromiseInfo.promise;
|
|
1240
|
+
};
|
|
1241
|
+
/** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
|
|
1242
|
+
if (extensions === void 0) extensions = {};
|
|
1243
|
+
var schema = extensions.KHR_texture_transform;
|
|
1244
|
+
if (schema) {
|
|
1245
|
+
Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
return MaterialParser;
|
|
1249
|
+
}(Parser);
|
|
1250
|
+
|
|
1251
|
+
var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
|
|
1252
|
+
_inherits(KHR_materials_clearcoat, ExtensionParser);
|
|
1253
|
+
function KHR_materials_clearcoat() {
|
|
1254
|
+
return ExtensionParser.apply(this, arguments);
|
|
1255
|
+
}
|
|
1256
|
+
var _proto = KHR_materials_clearcoat.prototype;
|
|
1257
|
+
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1258
|
+
var textures = context.glTFResource.textures;
|
|
1259
|
+
var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
|
|
1260
|
+
material.clearCoat = clearcoatFactor;
|
|
1261
|
+
material.clearCoatRoughness = clearcoatRoughnessFactor;
|
|
1262
|
+
if (clearcoatTexture) {
|
|
1263
|
+
material.clearCoatTexture = textures[clearcoatTexture.index];
|
|
1264
|
+
MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
|
|
1265
|
+
}
|
|
1266
|
+
if (clearcoatRoughnessTexture) {
|
|
1267
|
+
material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
|
|
1268
|
+
MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
|
|
1269
|
+
}
|
|
1270
|
+
if (clearcoatNormalTexture) {
|
|
1271
|
+
material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
|
|
1272
|
+
MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
return KHR_materials_clearcoat;
|
|
1276
|
+
}(ExtensionParser);
|
|
1277
|
+
KHR_materials_clearcoat = __decorate([
|
|
1278
|
+
registerExtension("KHR_materials_clearcoat")
|
|
1279
|
+
], KHR_materials_clearcoat);
|
|
1280
|
+
|
|
1281
|
+
var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
|
|
1282
|
+
_inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
|
|
1283
|
+
function KHR_materials_pbrSpecularGlossiness() {
|
|
1284
|
+
return ExtensionParser.apply(this, arguments);
|
|
1285
|
+
}
|
|
1286
|
+
var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
|
|
1287
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1288
|
+
var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
|
|
1289
|
+
var material = new PBRSpecularMaterial(engine);
|
|
1290
|
+
var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
|
|
1291
|
+
if (diffuseFactor) {
|
|
1292
|
+
material.baseColor = new Color(Color.linearToGammaSpace(diffuseFactor[0]), Color.linearToGammaSpace(diffuseFactor[1]), Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
|
|
1293
|
+
}
|
|
1294
|
+
if (diffuseTexture) {
|
|
1295
|
+
material.baseTexture = textures[diffuseTexture.index];
|
|
1296
|
+
MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
|
|
1297
|
+
}
|
|
1298
|
+
if (specularFactor) {
|
|
1299
|
+
material.specularColor = new Color(Color.linearToGammaSpace(specularFactor[0]), Color.linearToGammaSpace(specularFactor[1]), Color.linearToGammaSpace(specularFactor[2]));
|
|
1300
|
+
}
|
|
1301
|
+
if (glossinessFactor !== undefined) {
|
|
1302
|
+
material.glossiness = glossinessFactor;
|
|
1303
|
+
}
|
|
1304
|
+
if (specularGlossinessTexture) {
|
|
1305
|
+
material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
|
|
1306
|
+
MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
|
|
1307
|
+
}
|
|
1308
|
+
return material;
|
|
1309
|
+
};
|
|
1310
|
+
return KHR_materials_pbrSpecularGlossiness;
|
|
1311
|
+
}(ExtensionParser);
|
|
1312
|
+
KHR_materials_pbrSpecularGlossiness = __decorate([
|
|
1313
|
+
registerExtension("KHR_materials_pbrSpecularGlossiness")
|
|
1314
|
+
], KHR_materials_pbrSpecularGlossiness);
|
|
1315
|
+
|
|
1316
|
+
var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
|
|
1317
|
+
_inherits(KHR_materials_unlit, ExtensionParser);
|
|
1318
|
+
function KHR_materials_unlit() {
|
|
1319
|
+
return ExtensionParser.apply(this, arguments);
|
|
1320
|
+
}
|
|
1321
|
+
var _proto = KHR_materials_unlit.prototype;
|
|
1322
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1323
|
+
var engine = context.glTFResource.engine;
|
|
1324
|
+
var material = new UnlitMaterial(engine);
|
|
1325
|
+
return material;
|
|
1326
|
+
};
|
|
1327
|
+
return KHR_materials_unlit;
|
|
1328
|
+
}(ExtensionParser);
|
|
1329
|
+
KHR_materials_unlit = __decorate([
|
|
1330
|
+
registerExtension("KHR_materials_unlit")
|
|
1331
|
+
], KHR_materials_unlit);
|
|
1332
|
+
|
|
1333
|
+
var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
|
|
1334
|
+
_inherits(KHR_materials_variants, ExtensionParser);
|
|
1335
|
+
function KHR_materials_variants() {
|
|
1336
|
+
return ExtensionParser.apply(this, arguments);
|
|
1337
|
+
}
|
|
1338
|
+
var _proto = KHR_materials_variants.prototype;
|
|
1339
|
+
_proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
|
|
1340
|
+
var _context_gltf = context.gltf, _context_gltf_extensions = _context_gltf.extensions, _context_gltf_extensions_KHR_materials_variants = _context_gltf_extensions.KHR_materials_variants, variantNames = _context_gltf_extensions_KHR_materials_variants.variants, glTFResource = context.glTFResource;
|
|
1341
|
+
var mappings = schema.mappings;
|
|
1342
|
+
for(var i = 0; i < mappings.length; i++){
|
|
1343
|
+
var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
|
|
1344
|
+
if (!glTFResource.variants) glTFResource.variants = [];
|
|
1345
|
+
glTFResource.variants.push({
|
|
1346
|
+
renderer: renderer,
|
|
1347
|
+
material: glTFResource.materials[material],
|
|
1348
|
+
variants: variants.map(function(index) {
|
|
1349
|
+
return variantNames[index].name;
|
|
1350
|
+
})
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
return KHR_materials_variants;
|
|
1355
|
+
}(ExtensionParser);
|
|
1356
|
+
KHR_materials_variants = __decorate([
|
|
1357
|
+
registerExtension("KHR_materials_variants")
|
|
1358
|
+
], KHR_materials_variants);
|
|
1359
|
+
|
|
1360
|
+
var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
|
|
1361
|
+
_inherits(KHR_mesh_quantization, ExtensionParser);
|
|
1362
|
+
function KHR_mesh_quantization() {
|
|
1363
|
+
return ExtensionParser.apply(this, arguments);
|
|
1364
|
+
}
|
|
1365
|
+
return KHR_mesh_quantization;
|
|
1366
|
+
}(ExtensionParser);
|
|
1367
|
+
KHR_mesh_quantization = __decorate([
|
|
1368
|
+
registerExtension("KHR_mesh_quantization")
|
|
1369
|
+
], KHR_mesh_quantization);
|
|
1370
|
+
|
|
1371
|
+
var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
|
|
1372
|
+
_inherits(KHR_texture_transform, ExtensionParser);
|
|
1373
|
+
function KHR_texture_transform() {
|
|
1374
|
+
return ExtensionParser.apply(this, arguments);
|
|
1375
|
+
}
|
|
1376
|
+
var _proto = KHR_texture_transform.prototype;
|
|
1377
|
+
_proto.parseEngineResource = function parseEngineResource(schema, material, context) {
|
|
1378
|
+
var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
|
|
1379
|
+
if (offset) {
|
|
1380
|
+
material.tilingOffset.z = offset[0];
|
|
1381
|
+
material.tilingOffset.w = offset[1];
|
|
1382
|
+
}
|
|
1383
|
+
if (scale) {
|
|
1384
|
+
material.tilingOffset.x = scale[0];
|
|
1385
|
+
material.tilingOffset.y = scale[1];
|
|
1386
|
+
}
|
|
1387
|
+
if (rotation) {
|
|
1388
|
+
Logger.warn("rotation in KHR_texture_transform is not supported now");
|
|
1389
|
+
}
|
|
1390
|
+
if (texCoord) {
|
|
1391
|
+
Logger.warn("texCoord in KHR_texture_transform is not supported now");
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
return KHR_texture_transform;
|
|
1395
|
+
}(ExtensionParser);
|
|
1396
|
+
KHR_texture_transform = __decorate([
|
|
1397
|
+
registerExtension("KHR_texture_transform")
|
|
1398
|
+
], KHR_texture_transform);
|
|
1399
|
+
|
|
1400
|
+
var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
|
|
1401
|
+
_inherits(GalaceanMaterialsRemap, ExtensionParser);
|
|
1402
|
+
function GalaceanMaterialsRemap() {
|
|
1403
|
+
return ExtensionParser.apply(this, arguments);
|
|
1404
|
+
}
|
|
1405
|
+
var _proto = GalaceanMaterialsRemap.prototype;
|
|
1406
|
+
_proto.createEngineResource = function createEngineResource(schema, context) {
|
|
1407
|
+
var engine = context.glTFResource.engine;
|
|
1408
|
+
// @ts-ignore
|
|
1409
|
+
return engine.resourceManager.getResourceByRef(schema);
|
|
1410
|
+
};
|
|
1411
|
+
return GalaceanMaterialsRemap;
|
|
1412
|
+
}(ExtensionParser);
|
|
1413
|
+
GalaceanMaterialsRemap = __decorate([
|
|
1414
|
+
registerExtension("OASIS_materials_remap")
|
|
1415
|
+
], GalaceanMaterialsRemap);
|
|
1416
|
+
|
|
1417
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
1418
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
1419
|
+
|
|
1420
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
1421
|
+
// Fallback for engines without symbol support
|
|
1422
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
1423
|
+
if (it) o = it;
|
|
1424
|
+
|
|
1425
|
+
var i = 0;
|
|
1426
|
+
|
|
1427
|
+
return function() {
|
|
1428
|
+
if (i >= o.length) return { done: true };
|
|
1429
|
+
|
|
1430
|
+
return { done: false, value: o[i++] };
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
var AnimationParser = /*#__PURE__*/ function(Parser) {
|
|
1438
|
+
_inherits(AnimationParser, Parser);
|
|
1439
|
+
function AnimationParser() {
|
|
1440
|
+
return Parser.apply(this, arguments);
|
|
1441
|
+
}
|
|
1442
|
+
var _proto = AnimationParser.prototype;
|
|
1443
|
+
_proto.parse = function parse(context) {
|
|
1444
|
+
var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
|
|
1445
|
+
var entities = glTFResource.entities;
|
|
1446
|
+
var animations = gltf.animations, accessors = gltf.accessors;
|
|
1447
|
+
if (!animations) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
|
|
1451
|
+
var animationClipCount = animations.length;
|
|
1452
|
+
var animationClips = new Array(animationClipCount);
|
|
1453
|
+
var animationsIndices = new Array(animationClipCount);
|
|
1454
|
+
for(var i = 0; i < animationClipCount; i++){
|
|
1455
|
+
var gltfAnimation = animations[i];
|
|
1456
|
+
var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
|
|
1457
|
+
var animationClip = new AnimationClip(name);
|
|
1458
|
+
var sampleDataCollection = new Array();
|
|
1459
|
+
// parse samplers
|
|
1460
|
+
for(var j = 0, m = samplers.length; j < m; j++){
|
|
1461
|
+
var gltfSampler = samplers[j];
|
|
1462
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
1463
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
1464
|
+
var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
|
|
1465
|
+
var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
|
|
1466
|
+
if (outputAccessor.normalized) {
|
|
1467
|
+
var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
|
|
1468
|
+
var scaled = new Float32Array(output.length);
|
|
1469
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
1470
|
+
scaled[k] = output[k] * scale;
|
|
1471
|
+
}
|
|
1472
|
+
output = scaled;
|
|
1473
|
+
}
|
|
1474
|
+
var outputStride = output.length / input.length;
|
|
1475
|
+
var _gltfSampler_interpolation;
|
|
1476
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
1477
|
+
var samplerInterpolation = void 0;
|
|
1478
|
+
switch(interpolation){
|
|
1479
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
1480
|
+
samplerInterpolation = InterpolationType.CubicSpine;
|
|
1481
|
+
break;
|
|
1482
|
+
case AnimationSamplerInterpolation.Step:
|
|
1483
|
+
samplerInterpolation = InterpolationType.Step;
|
|
1484
|
+
break;
|
|
1485
|
+
case AnimationSamplerInterpolation.Linear:
|
|
1486
|
+
samplerInterpolation = InterpolationType.Linear;
|
|
1487
|
+
break;
|
|
1488
|
+
}
|
|
1489
|
+
input[input.length - 1];
|
|
1490
|
+
sampleDataCollection.push({
|
|
1491
|
+
type: outputAccessor.type,
|
|
1492
|
+
interpolation: samplerInterpolation,
|
|
1493
|
+
input: input,
|
|
1494
|
+
output: output,
|
|
1495
|
+
outputSize: outputStride
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
1499
|
+
var gltfChannel = channels[j1];
|
|
1500
|
+
var target = gltfChannel.target;
|
|
1501
|
+
var channelTargetEntity = entities[target.node];
|
|
1502
|
+
var relativePath = "";
|
|
1503
|
+
var entity = channelTargetEntity;
|
|
1504
|
+
while(entity.parent){
|
|
1505
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
1506
|
+
entity = entity.parent;
|
|
1507
|
+
}
|
|
1508
|
+
var ComponentType = void 0;
|
|
1509
|
+
var propertyName = void 0;
|
|
1510
|
+
switch(target.path){
|
|
1511
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1512
|
+
ComponentType = Transform;
|
|
1513
|
+
propertyName = "position";
|
|
1514
|
+
break;
|
|
1515
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1516
|
+
ComponentType = Transform;
|
|
1517
|
+
propertyName = "rotationQuaternion";
|
|
1518
|
+
break;
|
|
1519
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1520
|
+
ComponentType = Transform;
|
|
1521
|
+
propertyName = "scale";
|
|
1522
|
+
break;
|
|
1523
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1524
|
+
ComponentType = SkinnedMeshRenderer;
|
|
1525
|
+
propertyName = "blendShapeWeights";
|
|
1526
|
+
break;
|
|
1527
|
+
}
|
|
1528
|
+
var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
1529
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
1530
|
+
}
|
|
1531
|
+
animationClips[i] = animationClip;
|
|
1532
|
+
animationsIndices[i] = {
|
|
1533
|
+
name: name,
|
|
1534
|
+
index: i
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
glTFResource.animations = animationClips;
|
|
1538
|
+
// @ts-ignore for editor
|
|
1539
|
+
glTFResource._animationsIndices = animationsIndices;
|
|
1540
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
1541
|
+
return animationClipsPromiseInfo.promise;
|
|
1542
|
+
};
|
|
1543
|
+
_proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
1544
|
+
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
1545
|
+
var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
|
|
1546
|
+
switch(animationchannelTargetPath){
|
|
1547
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
1548
|
+
case AnimationChannelTargetPath.SCALE:
|
|
1549
|
+
{
|
|
1550
|
+
var curve = new AnimationVector3Curve();
|
|
1551
|
+
var interpolation = curve.interpolation = sampleData.interpolation;
|
|
1552
|
+
var offset = 0;
|
|
1553
|
+
for(var i = 0, n = input.length; i < n; i++){
|
|
1554
|
+
var keyframe = new Keyframe();
|
|
1555
|
+
keyframe.time = input[i];
|
|
1556
|
+
if (interpolation === InterpolationType.CubicSpine) {
|
|
1557
|
+
keyframe.inTangent = new Vector3(output[offset++], output[offset++], output[offset++]);
|
|
1558
|
+
keyframe.value = new Vector3(output[offset++], output[offset++], output[offset++]);
|
|
1559
|
+
keyframe.outTangent = new Vector3(output[offset++], output[offset++], output[offset++]);
|
|
1560
|
+
} else {
|
|
1561
|
+
keyframe.value = new Vector3(output[offset++], output[offset++], output[offset++]);
|
|
1562
|
+
}
|
|
1563
|
+
curve.addKey(keyframe);
|
|
1564
|
+
}
|
|
1565
|
+
return curve;
|
|
1566
|
+
}
|
|
1567
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
1568
|
+
{
|
|
1569
|
+
var curve1 = new AnimationQuaternionCurve();
|
|
1570
|
+
var interpolation1 = curve1.interpolation = sampleData.interpolation;
|
|
1571
|
+
var offset1 = 0;
|
|
1572
|
+
for(var i1 = 0, n1 = input.length; i1 < n1; i1++){
|
|
1573
|
+
var keyframe1 = new Keyframe();
|
|
1574
|
+
keyframe1.time = input[i1];
|
|
1575
|
+
if (interpolation1 === InterpolationType.CubicSpine) {
|
|
1576
|
+
keyframe1.inTangent = new Vector4(output[offset1++], output[offset1++], output[offset1++], output[offset1++]);
|
|
1577
|
+
keyframe1.value = new Quaternion(output[offset1++], output[offset1++], output[offset1++], output[offset1++]);
|
|
1578
|
+
keyframe1.outTangent = new Vector4(output[offset1++], output[offset1++], output[offset1++], output[offset1++]);
|
|
1579
|
+
} else {
|
|
1580
|
+
keyframe1.value = new Quaternion(output[offset1++], output[offset1++], output[offset1++], output[offset1++]);
|
|
1581
|
+
}
|
|
1582
|
+
curve1.addKey(keyframe1);
|
|
1583
|
+
}
|
|
1584
|
+
return curve1;
|
|
1585
|
+
}
|
|
1586
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
1587
|
+
{
|
|
1588
|
+
var curve2 = new AnimationFloatArrayCurve();
|
|
1589
|
+
curve2.interpolation = sampleData.interpolation;
|
|
1590
|
+
var offset2 = 0;
|
|
1591
|
+
for(var i2 = 0, n2 = input.length; i2 < n2; i2++){
|
|
1592
|
+
var keyframe2 = new Keyframe();
|
|
1593
|
+
keyframe2.time = input[i2];
|
|
1594
|
+
if (curve2.interpolation === InterpolationType.CubicSpine) {
|
|
1595
|
+
keyframe2.inTangent = Array.from(output.subarray(offset2, offset2 + outputSize));
|
|
1596
|
+
offset2 += outputSize;
|
|
1597
|
+
keyframe2.value = output.subarray(offset2, offset2 + outputSize);
|
|
1598
|
+
offset2 += outputSize;
|
|
1599
|
+
keyframe2.outTangent = Array.from(output.subarray(offset2, offset2 + outputSize));
|
|
1600
|
+
offset2 += outputSize;
|
|
1601
|
+
} else {
|
|
1602
|
+
keyframe2.value = output.subarray(offset2, offset2 + outputSize);
|
|
1603
|
+
offset2 += outputSize;
|
|
1604
|
+
}
|
|
1605
|
+
curve2.addKey(keyframe2);
|
|
1606
|
+
}
|
|
1607
|
+
return curve2;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
return AnimationParser;
|
|
1612
|
+
}(Parser);
|
|
1613
|
+
|
|
1614
|
+
var BufferParser = /*#__PURE__*/ function(Parser) {
|
|
1615
|
+
_inherits(BufferParser, Parser);
|
|
1616
|
+
function BufferParser() {
|
|
1617
|
+
return Parser.apply(this, arguments);
|
|
1618
|
+
}
|
|
1619
|
+
var _proto = BufferParser.prototype;
|
|
1620
|
+
_proto.parse = function parse(context) {
|
|
1621
|
+
var glTFResource = context.glTFResource;
|
|
1622
|
+
var url = glTFResource.url;
|
|
1623
|
+
if (this._isGLB(url)) {
|
|
1624
|
+
return request(url, {
|
|
1625
|
+
type: "arraybuffer"
|
|
1626
|
+
}).then(GLTFUtil.parseGLB).then(function(param) {
|
|
1627
|
+
var gltf = param.gltf, buffers = param.buffers;
|
|
1628
|
+
context.gltf = gltf;
|
|
1629
|
+
context.buffers = buffers;
|
|
1630
|
+
});
|
|
1631
|
+
} else {
|
|
1632
|
+
return request(url, {
|
|
1633
|
+
type: "json"
|
|
1634
|
+
}).then(function(gltf) {
|
|
1635
|
+
context.gltf = gltf;
|
|
1636
|
+
return Promise.all(gltf.buffers.map(function(buffer) {
|
|
1637
|
+
return request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
|
|
1638
|
+
type: "arraybuffer"
|
|
1639
|
+
});
|
|
1640
|
+
})).then(function(buffers) {
|
|
1641
|
+
context.buffers = buffers;
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
_proto._isGLB = function _isGLB(url) {
|
|
1647
|
+
var index = url.lastIndexOf(".");
|
|
1648
|
+
return url.substring(index + 1, index + 4) === "glb";
|
|
1649
|
+
};
|
|
1650
|
+
return BufferParser;
|
|
1651
|
+
}(Parser);
|
|
1652
|
+
|
|
1653
|
+
var EntityParser = /*#__PURE__*/ function(Parser) {
|
|
1654
|
+
_inherits(EntityParser, Parser);
|
|
1655
|
+
function EntityParser() {
|
|
1656
|
+
return Parser.apply(this, arguments);
|
|
1657
|
+
}
|
|
1658
|
+
var _proto = EntityParser.prototype;
|
|
1659
|
+
_proto.parse = function parse(context) {
|
|
1660
|
+
var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
|
|
1661
|
+
var engine = glTFResource.engine;
|
|
1662
|
+
if (!nodes) return;
|
|
1663
|
+
var entities = [];
|
|
1664
|
+
for(var i = 0; i < nodes.length; i++){
|
|
1665
|
+
var gltfNode = nodes[i];
|
|
1666
|
+
var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
|
|
1667
|
+
var entity = new Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
|
|
1668
|
+
var transform = entity.transform;
|
|
1669
|
+
if (matrix) {
|
|
1670
|
+
var localMatrix = transform.localMatrix;
|
|
1671
|
+
localMatrix.copyFromArray(matrix);
|
|
1672
|
+
transform.localMatrix = localMatrix;
|
|
1673
|
+
} else {
|
|
1674
|
+
if (translation) {
|
|
1675
|
+
transform.setPosition(translation[0], translation[1], translation[2]);
|
|
1676
|
+
}
|
|
1677
|
+
if (rotation) {
|
|
1678
|
+
transform.setRotationQuaternion(rotation[0], rotation[1], rotation[2], rotation[3]);
|
|
1679
|
+
}
|
|
1680
|
+
if (scale) {
|
|
1681
|
+
transform.setScale(scale[0], scale[1], scale[2]);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
entities[i] = entity;
|
|
1685
|
+
}
|
|
1686
|
+
glTFResource.entities = entities;
|
|
1687
|
+
this._buildEntityTree(context, glTFResource);
|
|
1688
|
+
this._createSceneRoots(context, glTFResource);
|
|
1689
|
+
};
|
|
1690
|
+
_proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
|
|
1691
|
+
var nodes = context.gltf.nodes;
|
|
1692
|
+
var entities = glTFResource.entities;
|
|
1693
|
+
for(var i = 0; i < nodes.length; i++){
|
|
1694
|
+
var children = nodes[i].children;
|
|
1695
|
+
var entity = entities[i];
|
|
1696
|
+
if (children) {
|
|
1697
|
+
for(var j = 0; j < children.length; j++){
|
|
1698
|
+
var childEntity = entities[children[j]];
|
|
1699
|
+
entity.addChild(childEntity);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1704
|
+
_proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
|
|
1705
|
+
var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
|
|
1706
|
+
var engine = glTFResource.engine, entities = glTFResource.entities;
|
|
1707
|
+
if (!scenes) return;
|
|
1708
|
+
var sceneRoots = [];
|
|
1709
|
+
for(var i = 0; i < scenes.length; i++){
|
|
1710
|
+
var nodes = scenes[i].nodes;
|
|
1711
|
+
if (!nodes) continue;
|
|
1712
|
+
if (nodes.length === 1) {
|
|
1713
|
+
sceneRoots[i] = entities[nodes[0]];
|
|
1714
|
+
} else {
|
|
1715
|
+
var rootEntity = new Entity(engine, "GLTF_ROOT");
|
|
1716
|
+
for(var j = 0; j < nodes.length; j++){
|
|
1717
|
+
rootEntity.addChild(entities[nodes[j]]);
|
|
1718
|
+
}
|
|
1719
|
+
sceneRoots[i] = rootEntity;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
glTFResource.sceneRoots = sceneRoots;
|
|
1723
|
+
glTFResource.defaultSceneRoot = sceneRoots[sceneID];
|
|
1724
|
+
};
|
|
1725
|
+
return EntityParser;
|
|
1726
|
+
}(Parser);
|
|
1727
|
+
(function() {
|
|
1728
|
+
/** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
|
|
1729
|
+
})();
|
|
1730
|
+
|
|
1731
|
+
var MeshParser = /*#__PURE__*/ function(Parser1) {
|
|
1732
|
+
_inherits(MeshParser, Parser1);
|
|
1733
|
+
function MeshParser() {
|
|
1734
|
+
return Parser1.apply(this, arguments);
|
|
1735
|
+
}
|
|
1736
|
+
var _proto = MeshParser.prototype;
|
|
1737
|
+
_proto.parse = function parse(context) {
|
|
1738
|
+
var _loop = function(i) {
|
|
1739
|
+
var _loop = function(j) {
|
|
1740
|
+
var gltfPrimitive = gltfMesh.primitives[j];
|
|
1741
|
+
var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
|
|
1742
|
+
var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
|
|
1743
|
+
primitivePromises[j] = new Promise(function(resolve) {
|
|
1744
|
+
var mesh = new ModelMesh(engine, gltfMesh.name || j + "");
|
|
1745
|
+
if (KHR_draco_mesh_compression) {
|
|
1746
|
+
Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
|
|
1747
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1748
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
1749
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
1750
|
+
return decodedGeometry.attributes[j].array;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
return null;
|
|
1754
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
1755
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
1756
|
+
}, function() {
|
|
1757
|
+
return decodedGeometry.index.array;
|
|
1758
|
+
}, context.keepMeshData);
|
|
1759
|
+
}).then(resolve);
|
|
1760
|
+
} else {
|
|
1761
|
+
_this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
|
|
1762
|
+
return null;
|
|
1763
|
+
}, function(attributeName, shapeIndex) {
|
|
1764
|
+
var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
|
|
1765
|
+
var attributeAccessorIdx = shapeAccessorIdx[attributeName];
|
|
1766
|
+
if (attributeAccessorIdx) {
|
|
1767
|
+
var accessor = gltf.accessors[attributeAccessorIdx];
|
|
1768
|
+
return GLTFUtil.getAccessorData(gltf, accessor, buffers);
|
|
1769
|
+
} else {
|
|
1770
|
+
return null;
|
|
1771
|
+
}
|
|
1772
|
+
}, function() {
|
|
1773
|
+
var indexAccessor = gltf.accessors[gltfPrimitive.indices];
|
|
1774
|
+
return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
|
|
1775
|
+
}, context.keepMeshData).then(resolve);
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
};
|
|
1779
|
+
var gltfMesh = gltf.meshes[i];
|
|
1780
|
+
var primitivePromises = [];
|
|
1781
|
+
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
1782
|
+
meshPromises[i] = Promise.all(primitivePromises);
|
|
1783
|
+
};
|
|
1784
|
+
var _this = this;
|
|
1785
|
+
var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
|
|
1786
|
+
var engine = glTFResource.engine;
|
|
1787
|
+
if (!gltf.meshes) return;
|
|
1788
|
+
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
1789
|
+
var meshPromises = [];
|
|
1790
|
+
for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
|
|
1791
|
+
AssetPromise.all(meshPromises).then(function(meshes) {
|
|
1792
|
+
glTFResource.meshes = meshes;
|
|
1793
|
+
meshesPromiseInfo.resolve(meshes);
|
|
1794
|
+
}).catch(meshesPromiseInfo.reject);
|
|
1795
|
+
return meshesPromiseInfo.promise;
|
|
1796
|
+
};
|
|
1797
|
+
_proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1798
|
+
var accessors = gltf.accessors;
|
|
1799
|
+
context.buffers;
|
|
1800
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1801
|
+
var engine = mesh.engine;
|
|
1802
|
+
var vertexElements = new Array();
|
|
1803
|
+
var vertexCount;
|
|
1804
|
+
var bufferBindIndex = 0;
|
|
1805
|
+
var positions;
|
|
1806
|
+
var boneIndices;
|
|
1807
|
+
var boneWeights;
|
|
1808
|
+
if (keepMeshData) {
|
|
1809
|
+
positions = new Array(vertexCount);
|
|
1810
|
+
boneIndices = new Array(vertexCount);
|
|
1811
|
+
boneWeights = new Array(vertexCount);
|
|
1812
|
+
}
|
|
1813
|
+
for(var attribute in attributes){
|
|
1814
|
+
var accessor = accessors[attributes[attribute]];
|
|
1815
|
+
var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
|
|
1816
|
+
var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
|
|
1817
|
+
var accessorCount = accessor.count;
|
|
1818
|
+
var vertices = accessorBuffer.data;
|
|
1819
|
+
var vertexElement = void 0;
|
|
1820
|
+
var meshId = mesh.instanceId;
|
|
1821
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
1822
|
+
var elementNormalized = accessor.normalized;
|
|
1823
|
+
var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
1824
|
+
var scaleFactor = void 0;
|
|
1825
|
+
elementNormalized && (scaleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType));
|
|
1826
|
+
var elementOffset = void 0;
|
|
1827
|
+
if (accessorBuffer.interleaved) {
|
|
1828
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
1829
|
+
var stride = accessorBuffer.stride;
|
|
1830
|
+
elementOffset = byteOffset % stride;
|
|
1831
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
1832
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1833
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
1834
|
+
if (!vertexBuffer) {
|
|
1835
|
+
vertexBuffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1836
|
+
vertexBuffer.setData(vertices);
|
|
1837
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
1838
|
+
}
|
|
1839
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
1840
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1841
|
+
} else {
|
|
1842
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
1843
|
+
}
|
|
1844
|
+
} else {
|
|
1845
|
+
elementOffset = 0;
|
|
1846
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
1847
|
+
var vertexBuffer1 = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices.byteLength, BufferUsage.Static);
|
|
1848
|
+
vertexBuffer1.setData(vertices);
|
|
1849
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
1850
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
1851
|
+
}
|
|
1852
|
+
vertexElements.push(vertexElement);
|
|
1853
|
+
if (attribute === "POSITION") {
|
|
1854
|
+
vertexCount = accessorCount;
|
|
1855
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
1856
|
+
if (accessor.min && accessor.max) {
|
|
1857
|
+
min.copyFromArray(accessor.min);
|
|
1858
|
+
max.copyFromArray(accessor.max);
|
|
1859
|
+
if (keepMeshData) {
|
|
1860
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1861
|
+
var stride1 = vertices.length / accessorCount;
|
|
1862
|
+
for(var j = 0; j < accessorCount; j++){
|
|
1863
|
+
var offset = baseOffset + j * stride1;
|
|
1864
|
+
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
1865
|
+
elementNormalized && position.scale(scaleFactor);
|
|
1866
|
+
positions[j] = position;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
} else {
|
|
1870
|
+
var position1 = MeshParser._tempVector3;
|
|
1871
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1872
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1873
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1874
|
+
var stride2 = vertices.length / accessorCount;
|
|
1875
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
1876
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
1877
|
+
position1.copyFromArray(vertices, offset1);
|
|
1878
|
+
Vector3.min(min, position1, min);
|
|
1879
|
+
Vector3.max(max, position1, max);
|
|
1880
|
+
if (keepMeshData) {
|
|
1881
|
+
var clonePosition = position1.clone();
|
|
1882
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
1883
|
+
positions[j1] = clonePosition;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
if (elementNormalized) {
|
|
1888
|
+
min.scale(scaleFactor);
|
|
1889
|
+
max.scale(scaleFactor);
|
|
1890
|
+
}
|
|
1891
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
1892
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1893
|
+
var stride3 = vertices.length / accessorCount;
|
|
1894
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
1895
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
1896
|
+
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
1897
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
1898
|
+
boneIndices[j2] = boneIndex;
|
|
1899
|
+
}
|
|
1900
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
1901
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
1902
|
+
var stride4 = vertices.length / accessorCount;
|
|
1903
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
1904
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
1905
|
+
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
1906
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
1907
|
+
boneWeights[j3] = boneWeight;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
mesh.setVertexElements(vertexElements);
|
|
1912
|
+
// Indices
|
|
1913
|
+
if (indices !== undefined) {
|
|
1914
|
+
var indexAccessor = gltf.accessors[indices];
|
|
1915
|
+
var indexData = getIndexBufferData();
|
|
1916
|
+
mesh.setIndices(indexData);
|
|
1917
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
1918
|
+
} else {
|
|
1919
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
1920
|
+
}
|
|
1921
|
+
// BlendShapes
|
|
1922
|
+
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
1923
|
+
mesh.uploadData(!keepMeshData);
|
|
1924
|
+
//@ts-ignore
|
|
1925
|
+
mesh._positions = positions;
|
|
1926
|
+
//@ts-ignore
|
|
1927
|
+
mesh._boneIndices = boneIndices;
|
|
1928
|
+
//@ts-ignore
|
|
1929
|
+
mesh._boneWeights = boneWeights;
|
|
1930
|
+
return Promise.resolve(mesh);
|
|
1931
|
+
};
|
|
1932
|
+
_proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
1933
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
1934
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
1935
|
+
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
1936
|
+
var deltaPosBuffer = getBlendShapeData("POSITION", i);
|
|
1937
|
+
var deltaNorBuffer = getBlendShapeData("NORMAL", i);
|
|
1938
|
+
var deltaTanBuffer = getBlendShapeData("TANGENT", i);
|
|
1939
|
+
var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
|
|
1940
|
+
var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
|
|
1941
|
+
var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
|
|
1942
|
+
var blendShape = new BlendShape(name);
|
|
1943
|
+
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
1944
|
+
mesh.addBlendShape(blendShape);
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
/**
|
|
1948
|
+
* @deprecated
|
|
1949
|
+
*/ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
1950
|
+
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
1951
|
+
var vertexCount;
|
|
1952
|
+
var accessors = gltf.accessors;
|
|
1953
|
+
var accessor = accessors[attributes["POSITION"]];
|
|
1954
|
+
var positionBuffer = getVertexBufferData("POSITION");
|
|
1955
|
+
var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
|
|
1956
|
+
mesh.setPositions(positions);
|
|
1957
|
+
var bounds = mesh.bounds;
|
|
1958
|
+
vertexCount = accessor.count;
|
|
1959
|
+
if (accessor.min && accessor.max) {
|
|
1960
|
+
bounds.min.copyFromArray(accessor.min);
|
|
1961
|
+
bounds.max.copyFromArray(accessor.max);
|
|
1962
|
+
} else {
|
|
1963
|
+
var position = MeshParser._tempVector3;
|
|
1964
|
+
var min = bounds.min, max = bounds.max;
|
|
1965
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
1966
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
1967
|
+
var stride = positionBuffer.length / vertexCount;
|
|
1968
|
+
for(var j = 0; j < vertexCount; j++){
|
|
1969
|
+
var offset = j * stride;
|
|
1970
|
+
position.copyFromArray(positionBuffer, offset);
|
|
1971
|
+
Vector3.min(min, position, min);
|
|
1972
|
+
Vector3.max(max, position, max);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
for(var attributeSemantic in attributes){
|
|
1976
|
+
if (attributeSemantic === "POSITION") {
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
var bufferData = getVertexBufferData(attributeSemantic);
|
|
1980
|
+
switch(attributeSemantic){
|
|
1981
|
+
case "NORMAL":
|
|
1982
|
+
var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
|
|
1983
|
+
mesh.setNormals(normals);
|
|
1984
|
+
break;
|
|
1985
|
+
case "TEXCOORD_0":
|
|
1986
|
+
var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1987
|
+
mesh.setUVs(texturecoords, 0);
|
|
1988
|
+
break;
|
|
1989
|
+
case "TEXCOORD_1":
|
|
1990
|
+
var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1991
|
+
mesh.setUVs(texturecoords1, 1);
|
|
1992
|
+
break;
|
|
1993
|
+
case "TEXCOORD_2":
|
|
1994
|
+
var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1995
|
+
mesh.setUVs(texturecoords2, 2);
|
|
1996
|
+
break;
|
|
1997
|
+
case "TEXCOORD_3":
|
|
1998
|
+
var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
1999
|
+
mesh.setUVs(texturecoords3, 3);
|
|
2000
|
+
break;
|
|
2001
|
+
case "TEXCOORD_4":
|
|
2002
|
+
var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
2003
|
+
mesh.setUVs(texturecoords4, 4);
|
|
2004
|
+
break;
|
|
2005
|
+
case "TEXCOORD_5":
|
|
2006
|
+
var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
2007
|
+
mesh.setUVs(texturecoords5, 5);
|
|
2008
|
+
break;
|
|
2009
|
+
case "TEXCOORD_6":
|
|
2010
|
+
var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
2011
|
+
mesh.setUVs(texturecoords6, 6);
|
|
2012
|
+
break;
|
|
2013
|
+
case "TEXCOORD_7":
|
|
2014
|
+
var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
|
|
2015
|
+
mesh.setUVs(texturecoords7, 7);
|
|
2016
|
+
break;
|
|
2017
|
+
case "COLOR_0":
|
|
2018
|
+
var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
|
|
2019
|
+
mesh.setColors(colors);
|
|
2020
|
+
break;
|
|
2021
|
+
case "TANGENT":
|
|
2022
|
+
var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
2023
|
+
mesh.setTangents(tangents);
|
|
2024
|
+
break;
|
|
2025
|
+
case "JOINTS_0":
|
|
2026
|
+
var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
2027
|
+
mesh.setBoneIndices(joints);
|
|
2028
|
+
break;
|
|
2029
|
+
case "WEIGHTS_0":
|
|
2030
|
+
var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
|
|
2031
|
+
mesh.setBoneWeights(weights);
|
|
2032
|
+
break;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
// Indices
|
|
2036
|
+
if (indices !== undefined) {
|
|
2037
|
+
var indexAccessor = gltf.accessors[indices];
|
|
2038
|
+
var indexData = getIndexBufferData();
|
|
2039
|
+
mesh.setIndices(indexData);
|
|
2040
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
2041
|
+
} else {
|
|
2042
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
2043
|
+
}
|
|
2044
|
+
// BlendShapes
|
|
2045
|
+
targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
|
|
2046
|
+
mesh.uploadData(!keepMeshData);
|
|
2047
|
+
return Promise.resolve(mesh);
|
|
2048
|
+
};
|
|
2049
|
+
return MeshParser;
|
|
2050
|
+
}(Parser);
|
|
2051
|
+
(function() {
|
|
2052
|
+
MeshParser._tempVector3 = new Vector3();
|
|
2053
|
+
})();
|
|
2054
|
+
|
|
2055
|
+
var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
|
|
2056
|
+
_inherits(SceneParser, Parser1);
|
|
2057
|
+
function SceneParser() {
|
|
2058
|
+
return Parser1.apply(this, arguments);
|
|
2059
|
+
}
|
|
2060
|
+
var _proto = SceneParser.prototype;
|
|
2061
|
+
_proto.parse = function parse(context) {
|
|
2062
|
+
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
2063
|
+
var entities = glTFResource.entities;
|
|
2064
|
+
var nodes = gltf.nodes, gltfCameras = gltf.cameras;
|
|
2065
|
+
if (!nodes) return;
|
|
2066
|
+
var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
|
|
2067
|
+
var promises = [];
|
|
2068
|
+
for(var i = 0; i < nodes.length; i++){
|
|
2069
|
+
var gltfNode = nodes[i];
|
|
2070
|
+
var cameraID = gltfNode.camera, meshID = gltfNode.mesh, _gltfNode_extensions = gltfNode.extensions, extensions = _gltfNode_extensions === void 0 ? {} : _gltfNode_extensions;
|
|
2071
|
+
var KHR_lights_punctual = extensions.KHR_lights_punctual;
|
|
2072
|
+
var entity = entities[i];
|
|
2073
|
+
if (cameraID !== undefined) {
|
|
2074
|
+
this._createCamera(glTFResource, gltfCameras[cameraID], entity);
|
|
2075
|
+
}
|
|
2076
|
+
if (meshID !== undefined) {
|
|
2077
|
+
promises.push(this._createRenderer(context, gltfNode, entity));
|
|
2078
|
+
}
|
|
2079
|
+
if (KHR_lights_punctual) {
|
|
2080
|
+
var lightIndex = KHR_lights_punctual.light;
|
|
2081
|
+
var lights = gltf.extensions.KHR_lights_punctual.lights;
|
|
2082
|
+
Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
if (glTFResource.defaultSceneRoot) {
|
|
2086
|
+
this._createAnimator(context);
|
|
2087
|
+
}
|
|
2088
|
+
gltf.extensions && delete gltf.extensions["OASIS_materials_remap"];
|
|
2089
|
+
AssetPromise.all(promises).then(function() {
|
|
2090
|
+
return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
|
|
2091
|
+
}).catch(defaultSceneRootPromiseInfo.reject);
|
|
2092
|
+
return defaultSceneRootPromiseInfo.promise;
|
|
2093
|
+
};
|
|
2094
|
+
_proto._createCamera = function _createCamera(context, cameraSchema, entity) {
|
|
2095
|
+
var orthographic = cameraSchema.orthographic, perspective = cameraSchema.perspective, type = cameraSchema.type;
|
|
2096
|
+
var camera = entity.addComponent(Camera);
|
|
2097
|
+
if (type === CameraType.ORTHOGRAPHIC) {
|
|
2098
|
+
var xmag = orthographic.xmag, ymag = orthographic.ymag, zfar = orthographic.zfar, znear = orthographic.znear;
|
|
2099
|
+
camera.isOrthographic = true;
|
|
2100
|
+
if (znear !== undefined) {
|
|
2101
|
+
camera.nearClipPlane = znear;
|
|
2102
|
+
}
|
|
2103
|
+
if (zfar !== undefined) {
|
|
2104
|
+
camera.farClipPlane = zfar;
|
|
2105
|
+
}
|
|
2106
|
+
camera.orthographicSize = Math.max(ymag != null ? ymag : 0, xmag != null ? xmag : 0) / 2;
|
|
2107
|
+
} else if (type === CameraType.PERSPECTIVE) {
|
|
2108
|
+
var aspectRatio = perspective.aspectRatio, yfov = perspective.yfov, zfar1 = perspective.zfar, znear1 = perspective.znear;
|
|
2109
|
+
if (aspectRatio !== undefined) {
|
|
2110
|
+
camera.aspectRatio = aspectRatio;
|
|
2111
|
+
}
|
|
2112
|
+
if (yfov !== undefined) {
|
|
2113
|
+
camera.fieldOfView = yfov * 180 / Math.PI;
|
|
2114
|
+
}
|
|
2115
|
+
if (zfar1 !== undefined) {
|
|
2116
|
+
camera.farClipPlane = zfar1;
|
|
2117
|
+
}
|
|
2118
|
+
if (znear1 !== undefined) {
|
|
2119
|
+
camera.nearClipPlane = znear1;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
if (!context.cameras) context.cameras = [];
|
|
2123
|
+
context.cameras.push(camera);
|
|
2124
|
+
// @todo: use engine camera by default
|
|
2125
|
+
camera.enabled = false;
|
|
2126
|
+
};
|
|
2127
|
+
_proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
|
|
2128
|
+
var _loop = function(i) {
|
|
2129
|
+
var mesh = meshes[meshID][i];
|
|
2130
|
+
var renderer = void 0;
|
|
2131
|
+
if (skinID !== undefined || blendShapeWeights) {
|
|
2132
|
+
context.hasSkinned = true;
|
|
2133
|
+
var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
|
|
2134
|
+
skinRenderer.mesh = mesh;
|
|
2135
|
+
if (skinID !== undefined) {
|
|
2136
|
+
skinRenderer.skin = skins[skinID];
|
|
2137
|
+
}
|
|
2138
|
+
if (blendShapeWeights) {
|
|
2139
|
+
skinRenderer.blendShapeWeights = new Float32Array(blendShapeWeights);
|
|
2140
|
+
}
|
|
2141
|
+
renderer = skinRenderer;
|
|
2142
|
+
} else {
|
|
2143
|
+
renderer = entity.addComponent(MeshRenderer);
|
|
2144
|
+
renderer.mesh = mesh;
|
|
2145
|
+
}
|
|
2146
|
+
var materialIndex = gltfMeshPrimitives[i].material;
|
|
2147
|
+
var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
|
|
2148
|
+
if (remapMaterials && remapMaterials[materialIndex]) {
|
|
2149
|
+
promises.push(remapMaterials[materialIndex].then(function(mtl) {
|
|
2150
|
+
renderer.setMaterial(mtl);
|
|
2151
|
+
}));
|
|
2152
|
+
} else {
|
|
2153
|
+
var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
|
|
2154
|
+
renderer.setMaterial(material);
|
|
2155
|
+
}
|
|
2156
|
+
var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
|
|
2157
|
+
var KHR_materials_variants = extensions.KHR_materials_variants;
|
|
2158
|
+
if (KHR_materials_variants) {
|
|
2159
|
+
Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
var glTFResource = context.glTFResource, gltf = context.gltf;
|
|
2163
|
+
var gltfMeshes = gltf.meshes;
|
|
2164
|
+
var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
|
|
2165
|
+
var meshID = gltfNode.mesh, skinID = gltfNode.skin;
|
|
2166
|
+
var glTFMesh = gltfMeshes[meshID];
|
|
2167
|
+
var gltfMeshPrimitives = glTFMesh.primitives;
|
|
2168
|
+
var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
|
|
2169
|
+
var promises = [];
|
|
2170
|
+
for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
|
|
2171
|
+
return Promise.all(promises);
|
|
2172
|
+
};
|
|
2173
|
+
_proto._createAnimator = function _createAnimator(context) {
|
|
2174
|
+
if (!context.hasSkinned && !context.glTFResource.animations) {
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
var _context_glTFResource = context.glTFResource, defaultSceneRoot = _context_glTFResource.defaultSceneRoot, animations = _context_glTFResource.animations;
|
|
2178
|
+
var animator = defaultSceneRoot.addComponent(Animator);
|
|
2179
|
+
var animatorController = new AnimatorController();
|
|
2180
|
+
var layer = new AnimatorControllerLayer("layer");
|
|
2181
|
+
var animatorStateMachine = new AnimatorStateMachine();
|
|
2182
|
+
animatorController.addLayer(layer);
|
|
2183
|
+
animator.animatorController = animatorController;
|
|
2184
|
+
layer.stateMachine = animatorStateMachine;
|
|
2185
|
+
if (animations) {
|
|
2186
|
+
for(var i = 0; i < animations.length; i++){
|
|
2187
|
+
var animationClip = animations[i];
|
|
2188
|
+
var name = animationClip.name;
|
|
2189
|
+
var uniqueName = animatorStateMachine.makeUniqueStateName(name);
|
|
2190
|
+
if (uniqueName !== name) {
|
|
2191
|
+
console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
|
|
2192
|
+
}
|
|
2193
|
+
var animatorState = animatorStateMachine.addState(uniqueName);
|
|
2194
|
+
animatorState.clip = animationClip;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
|
|
2199
|
+
if (!SceneParser._defaultMaterial) {
|
|
2200
|
+
SceneParser._defaultMaterial = new BlinnPhongMaterial(engine);
|
|
2201
|
+
}
|
|
2202
|
+
return SceneParser._defaultMaterial;
|
|
2203
|
+
};
|
|
2204
|
+
return SceneParser;
|
|
2205
|
+
}(Parser);
|
|
2206
|
+
|
|
2207
|
+
var SkinParser = /*#__PURE__*/ function(Parser) {
|
|
2208
|
+
_inherits(SkinParser, Parser);
|
|
2209
|
+
function SkinParser() {
|
|
2210
|
+
return Parser.apply(this, arguments);
|
|
2211
|
+
}
|
|
2212
|
+
var _proto = SkinParser.prototype;
|
|
2213
|
+
_proto.parse = function parse(context) {
|
|
2214
|
+
var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
|
|
2215
|
+
var entities = glTFResource.entities;
|
|
2216
|
+
var gltfSkins = gltf.skins;
|
|
2217
|
+
if (!gltfSkins) return;
|
|
2218
|
+
var count = gltfSkins.length;
|
|
2219
|
+
var skins = new Array(count);
|
|
2220
|
+
for(var i = 0; i < count; i++){
|
|
2221
|
+
var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
|
|
2222
|
+
var jointCount = joints.length;
|
|
2223
|
+
var skin = new Skin(name);
|
|
2224
|
+
skin.inverseBindMatrices.length = jointCount;
|
|
2225
|
+
// parse IBM
|
|
2226
|
+
var accessor = gltf.accessors[inverseBindMatrices];
|
|
2227
|
+
var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
|
|
2228
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
2229
|
+
var inverseBindMatrix = new Matrix();
|
|
2230
|
+
inverseBindMatrix.copyFromArray(buffer, i1 * 16);
|
|
2231
|
+
skin.inverseBindMatrices[i1] = inverseBindMatrix;
|
|
2232
|
+
}
|
|
2233
|
+
// get joints
|
|
2234
|
+
for(var i2 = 0; i2 < jointCount; i2++){
|
|
2235
|
+
var jointIndex = joints[i2];
|
|
2236
|
+
var jointName = entities[jointIndex].name;
|
|
2237
|
+
skin.joints[i2] = jointName;
|
|
2238
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
2239
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
2240
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
2241
|
+
entities[j].name = jointName + "_" + j;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
// get skeleton
|
|
2246
|
+
if (skeleton !== undefined) {
|
|
2247
|
+
skin.skeleton = entities[skeleton].name;
|
|
2248
|
+
} else {
|
|
2249
|
+
var rootBone = this._findSkeletonRootBone(joints, entities);
|
|
2250
|
+
if (rootBone) {
|
|
2251
|
+
skin.skeleton = rootBone.name;
|
|
2252
|
+
} else {
|
|
2253
|
+
throw "Failed to find skeleton root bone.";
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
skins[i] = skin;
|
|
2257
|
+
}
|
|
2258
|
+
glTFResource.skins = skins;
|
|
2259
|
+
};
|
|
2260
|
+
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
2261
|
+
var paths = {};
|
|
2262
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(joints), _step; !(_step = _iterator()).done;){
|
|
2263
|
+
var index = _step.value;
|
|
2264
|
+
var path = new Array();
|
|
2265
|
+
var entity = entities[index];
|
|
2266
|
+
while(entity){
|
|
2267
|
+
path.unshift(entity);
|
|
2268
|
+
entity = entity.parent;
|
|
2269
|
+
}
|
|
2270
|
+
paths[index] = path;
|
|
2271
|
+
}
|
|
2272
|
+
var rootNode = null;
|
|
2273
|
+
for(var i = 0;; i++){
|
|
2274
|
+
var path1 = paths[joints[0]];
|
|
2275
|
+
if (i >= path1.length) {
|
|
2276
|
+
return rootNode;
|
|
2277
|
+
}
|
|
2278
|
+
var entity1 = path1[i];
|
|
2279
|
+
for(var j = 1, m = joints.length; j < m; j++){
|
|
2280
|
+
path1 = paths[joints[j]];
|
|
2281
|
+
if (i >= path1.length || entity1 !== path1[i]) {
|
|
2282
|
+
return rootNode;
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
rootNode = entity1;
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
return SkinParser;
|
|
2289
|
+
}(Parser);
|
|
2290
|
+
|
|
2291
|
+
var TextureParser = /*#__PURE__*/ function(Parser) {
|
|
2292
|
+
_inherits(TextureParser, Parser);
|
|
2293
|
+
function TextureParser() {
|
|
2294
|
+
return Parser.apply(this, arguments);
|
|
2295
|
+
}
|
|
2296
|
+
var _proto = TextureParser.prototype;
|
|
2297
|
+
_proto.parse = function parse(context) {
|
|
2298
|
+
var _this = this;
|
|
2299
|
+
var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
|
|
2300
|
+
var engine = glTFResource.engine, url = glTFResource.url;
|
|
2301
|
+
if (gltf.textures) {
|
|
2302
|
+
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
2303
|
+
AssetPromise.all(gltf.textures.map(function(param, index) {
|
|
2304
|
+
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
2305
|
+
var _gltf_images_source = gltf.images[source], uri = _gltf_images_source.uri, bufferViewIndex = _gltf_images_source.bufferView, mimeType = _gltf_images_source.mimeType, imageName = _gltf_images_source.name;
|
|
2306
|
+
if (uri) {
|
|
2307
|
+
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
2308
|
+
var index1 = uri.lastIndexOf(".");
|
|
2309
|
+
var ext = uri.substring(index1 + 1);
|
|
2310
|
+
var type = ext.startsWith("ktx") ? AssetType.KTX : AssetType.Texture2D;
|
|
2311
|
+
return engine.resourceManager.load({
|
|
2312
|
+
url: GLTFUtil.parseRelativeUrl(url, uri),
|
|
2313
|
+
type: type
|
|
2314
|
+
}).then(function(texture) {
|
|
2315
|
+
if (!texture.name) {
|
|
2316
|
+
texture.name = textureName || imageName || "texture_" + index1;
|
|
2317
|
+
}
|
|
2318
|
+
if (sampler !== undefined) {
|
|
2319
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2320
|
+
}
|
|
2321
|
+
return texture;
|
|
2322
|
+
});
|
|
2323
|
+
} else {
|
|
2324
|
+
var bufferView = gltf.bufferViews[bufferViewIndex];
|
|
2325
|
+
var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
|
|
2326
|
+
return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
|
|
2327
|
+
var texture = new Texture2D(engine, image.width, image.height);
|
|
2328
|
+
texture.setImageSource(image);
|
|
2329
|
+
texture.generateMipmaps();
|
|
2330
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
2331
|
+
if (sampler !== undefined) {
|
|
2332
|
+
_this._parseSampler(texture, gltf.samplers[sampler]);
|
|
2333
|
+
}
|
|
2334
|
+
return texture;
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
})).then(function(textures) {
|
|
2338
|
+
glTFResource.textures = textures;
|
|
2339
|
+
texturesPromiseInfo.resolve(textures);
|
|
2340
|
+
}).catch(texturesPromiseInfo.reject);
|
|
2341
|
+
return texturesPromiseInfo.promise;
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
_proto._parseSampler = function _parseSampler(texture, sampler) {
|
|
2345
|
+
var magFilter = sampler.magFilter, minFilter = sampler.minFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
2346
|
+
if (magFilter || minFilter) {
|
|
2347
|
+
if (magFilter === TextureMagFilter.NEAREST) {
|
|
2348
|
+
texture.filterMode = TextureFilterMode.Point;
|
|
2349
|
+
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
2350
|
+
texture.filterMode = TextureFilterMode.Bilinear;
|
|
2351
|
+
} else {
|
|
2352
|
+
texture.filterMode = TextureFilterMode.Trilinear;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
if (wrapS) {
|
|
2356
|
+
texture.wrapModeU = TextureParser._wrapMap[wrapS];
|
|
2357
|
+
}
|
|
2358
|
+
if (wrapT) {
|
|
2359
|
+
texture.wrapModeV = TextureParser._wrapMap[wrapT];
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
return TextureParser;
|
|
2363
|
+
}(Parser);
|
|
2364
|
+
(function() {
|
|
2365
|
+
var _obj;
|
|
2366
|
+
TextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = TextureWrapMode$1.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = TextureWrapMode$1.Mirror, _obj[TextureWrapMode.REPEAT] = TextureWrapMode$1.Repeat, _obj);
|
|
2367
|
+
})();
|
|
2368
|
+
|
|
2369
|
+
var Validator = /*#__PURE__*/ function(Parser1) {
|
|
2370
|
+
_inherits(Validator, Parser1);
|
|
2371
|
+
function Validator() {
|
|
2372
|
+
return Parser1.apply(this, arguments);
|
|
2373
|
+
}
|
|
2374
|
+
var _proto = Validator.prototype;
|
|
2375
|
+
_proto.parse = function parse(context) {
|
|
2376
|
+
var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
|
|
2377
|
+
var gltfVersion = Number(version);
|
|
2378
|
+
if (!(gltfVersion >= 2 && gltfVersion < 3)) {
|
|
2379
|
+
throw "Only support gltf 2.x.";
|
|
2380
|
+
}
|
|
2381
|
+
if (extensionsUsed) {
|
|
2382
|
+
Logger.info("extensionsUsed: ", extensionsUsed);
|
|
2383
|
+
for(var i = 0; i < extensionsUsed.length; i++){
|
|
2384
|
+
if (!Parser.hasExtensionParser(extensionsUsed[i])) {
|
|
2385
|
+
Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
if (extensionsRequired) {
|
|
2390
|
+
Logger.info("extensionsRequired: " + extensionsRequired);
|
|
2391
|
+
for(var i1 = 0; i1 < extensionsRequired.length; i1++){
|
|
2392
|
+
var extensionRequired = extensionsRequired[i1];
|
|
2393
|
+
if (!Parser.hasExtensionParser(extensionRequired)) {
|
|
2394
|
+
Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
|
|
2395
|
+
} else {
|
|
2396
|
+
Parser.initialize(extensionRequired);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
return Validator;
|
|
2402
|
+
}(Parser);
|
|
2403
|
+
|
|
2404
|
+
var GLTFParser = /*#__PURE__*/ function() {
|
|
2405
|
+
function GLTFParser(pipes) {
|
|
2406
|
+
var _this = this;
|
|
2407
|
+
this._pipes = [];
|
|
2408
|
+
pipes.forEach(function(pipe, index) {
|
|
2409
|
+
_this._pipes[index] = new pipe();
|
|
2410
|
+
});
|
|
2411
|
+
}
|
|
2412
|
+
var _proto = GLTFParser.prototype;
|
|
2413
|
+
_proto.parse = function parse(context) {
|
|
2414
|
+
var _this = this;
|
|
2415
|
+
var glTFResource = context.glTFResource;
|
|
2416
|
+
var lastPipe;
|
|
2417
|
+
return new AssetPromise(function(resolve, reject) {
|
|
2418
|
+
_this._pipes.forEach(function(parser) {
|
|
2419
|
+
if (lastPipe) {
|
|
2420
|
+
lastPipe = lastPipe.then(function() {
|
|
2421
|
+
return parser.parse(context);
|
|
2422
|
+
});
|
|
2423
|
+
if (lastPipe.cancel) {
|
|
2424
|
+
context.chainPromises.push(lastPipe);
|
|
2425
|
+
}
|
|
2426
|
+
} else {
|
|
2427
|
+
lastPipe = parser.parse(context);
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
if (lastPipe) {
|
|
2431
|
+
lastPipe.then(function() {
|
|
2432
|
+
resolve(glTFResource);
|
|
2433
|
+
}).catch(reject);
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2436
|
+
};
|
|
2437
|
+
return GLTFParser;
|
|
2438
|
+
}();
|
|
2439
|
+
(function() {
|
|
2440
|
+
GLTFParser.defaultPipeline = new GLTFParser([
|
|
2441
|
+
BufferParser,
|
|
2442
|
+
Validator,
|
|
2443
|
+
TextureParser,
|
|
2444
|
+
MaterialParser,
|
|
2445
|
+
MeshParser,
|
|
2446
|
+
EntityParser,
|
|
2447
|
+
SkinParser,
|
|
2448
|
+
AnimationParser,
|
|
2449
|
+
SceneParser$1
|
|
2450
|
+
]);
|
|
2451
|
+
})();
|
|
2452
|
+
|
|
2453
|
+
/**
|
|
2454
|
+
* Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
|
|
2455
|
+
*/ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
|
|
2456
|
+
_inherits(GLTFResource, EngineObject);
|
|
2457
|
+
function GLTFResource(engine, url) {
|
|
2458
|
+
var _this;
|
|
2459
|
+
_this = EngineObject.call(this, engine) || this;
|
|
2460
|
+
_this.url = url;
|
|
2461
|
+
return _this;
|
|
2462
|
+
}
|
|
2463
|
+
var _proto = GLTFResource.prototype;
|
|
2464
|
+
/**
|
|
2465
|
+
* @override
|
|
2466
|
+
*/ _proto.destroy = function destroy() {
|
|
2467
|
+
if (this._destroyed) {
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2470
|
+
EngineObject.prototype.destroy.call(this);
|
|
2471
|
+
this.defaultSceneRoot.destroy();
|
|
2472
|
+
this.textures = null;
|
|
2473
|
+
this.materials = null;
|
|
2474
|
+
this.meshes = null;
|
|
2475
|
+
this.skins = null;
|
|
2476
|
+
this.animations = null;
|
|
2477
|
+
this.entities = null;
|
|
2478
|
+
this.cameras = null;
|
|
2479
|
+
this.lights = null;
|
|
2480
|
+
this.sceneRoots = null;
|
|
2481
|
+
this.variants = null;
|
|
2482
|
+
};
|
|
2483
|
+
return GLTFResource;
|
|
2484
|
+
}(EngineObject);
|
|
2485
|
+
|
|
2486
|
+
var GLTFLoader = /*#__PURE__*/ function(Loader) {
|
|
2487
|
+
_inherits(GLTFLoader, Loader);
|
|
2488
|
+
function GLTFLoader() {
|
|
2489
|
+
return Loader.apply(this, arguments);
|
|
2490
|
+
}
|
|
2491
|
+
var _proto = GLTFLoader.prototype;
|
|
2492
|
+
_proto.load = function load(item, resourceManager) {
|
|
2493
|
+
var _item_params;
|
|
2494
|
+
var url = item.url;
|
|
2495
|
+
var context = new ParserContext(url);
|
|
2496
|
+
var glTFResource = new GLTFResource(resourceManager.engine, url);
|
|
2497
|
+
var masterPromiseInfo = context.masterPromiseInfo;
|
|
2498
|
+
context.glTFResource = glTFResource;
|
|
2499
|
+
var _item_params_keepMeshData;
|
|
2500
|
+
context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
|
|
2501
|
+
masterPromiseInfo.onCancel(function() {
|
|
2502
|
+
var chainPromises = context.chainPromises;
|
|
2503
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
|
|
2504
|
+
var promise = _step.value;
|
|
2505
|
+
promise.cancel();
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
|
|
2509
|
+
console.error(e);
|
|
2510
|
+
masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
|
|
2511
|
+
});
|
|
2512
|
+
return context.promiseMap;
|
|
2513
|
+
};
|
|
2514
|
+
return GLTFLoader;
|
|
2515
|
+
}(Loader);
|
|
2516
|
+
GLTFLoader = __decorate([
|
|
2517
|
+
resourceLoader(AssetType.Prefab, [
|
|
2518
|
+
"gltf",
|
|
2519
|
+
"glb"
|
|
2520
|
+
])
|
|
2521
|
+
], GLTFLoader);
|
|
2522
|
+
|
|
2523
|
+
var _HDRLoader;
|
|
2524
|
+
var PI = Math.PI;
|
|
2525
|
+
var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
|
|
2526
|
+
_inherits(HDRLoader1, Loader);
|
|
2527
|
+
function HDRLoader1() {
|
|
2528
|
+
return Loader.apply(this, arguments);
|
|
2529
|
+
}
|
|
2530
|
+
var _proto = HDRLoader1.prototype;
|
|
2531
|
+
_proto.load = function load(item, resourceManager) {
|
|
2532
|
+
var _this = this;
|
|
2533
|
+
return new AssetPromise(function(resolve, reject) {
|
|
2534
|
+
var engine = resourceManager.engine;
|
|
2535
|
+
_this.request(item.url, {
|
|
2536
|
+
type: "arraybuffer"
|
|
2537
|
+
}).then(function(buffer) {
|
|
2538
|
+
var uint8Array = new Uint8Array(buffer);
|
|
2539
|
+
var _HDRLoader__parseHeader = HDRLoader._parseHeader(uint8Array), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
|
|
2540
|
+
var pixels = HDRLoader._readPixels(uint8Array.subarray(dataPosition), width, height);
|
|
2541
|
+
var cubeSize = height >> 1;
|
|
2542
|
+
var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
|
|
2543
|
+
var texture = new TextureCube(engine, cubeSize);
|
|
2544
|
+
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
2545
|
+
texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0);
|
|
2546
|
+
}
|
|
2547
|
+
texture.generateMipmaps();
|
|
2548
|
+
resolve(texture);
|
|
2549
|
+
}).catch(reject);
|
|
2550
|
+
});
|
|
2551
|
+
};
|
|
2552
|
+
HDRLoader1._convertToCubemap = function _convertToCubemap(pixels, inputWidth, inputHeight, size) {
|
|
2553
|
+
if (!pixels) {
|
|
2554
|
+
throw "ConvertPanoramaToCubemap: input cannot be null";
|
|
2555
|
+
}
|
|
2556
|
+
if (pixels.length != inputWidth * inputHeight * 4) {
|
|
2557
|
+
throw "ConvertPanoramaToCubemap: input size is wrong";
|
|
2558
|
+
}
|
|
2559
|
+
var textureRight = this._createCubemapData(size, this._faceRight, pixels, inputWidth, inputHeight);
|
|
2560
|
+
var textureLeft = this._createCubemapData(size, this._faceLeft, pixels, inputWidth, inputHeight);
|
|
2561
|
+
var textureUp = this._createCubemapData(size, this._faceUp, pixels, inputWidth, inputHeight);
|
|
2562
|
+
var textureDown = this._createCubemapData(size, this._faceBottom, pixels, inputWidth, inputHeight);
|
|
2563
|
+
var textureFront = this._createCubemapData(size, this._faceFront, pixels, inputWidth, inputHeight);
|
|
2564
|
+
var textureBack = this._createCubemapData(size, this._faceBack, pixels, inputWidth, inputHeight);
|
|
2565
|
+
return [
|
|
2566
|
+
textureRight,
|
|
2567
|
+
textureLeft,
|
|
2568
|
+
textureUp,
|
|
2569
|
+
textureDown,
|
|
2570
|
+
textureFront,
|
|
2571
|
+
textureBack
|
|
2572
|
+
];
|
|
2573
|
+
};
|
|
2574
|
+
HDRLoader1._createCubemapData = function _createCubemapData(texSize, faceData, pixels, inputWidth, inputHeight) {
|
|
2575
|
+
var textureArray = new Uint8ClampedArray(texSize * texSize * 4);
|
|
2576
|
+
var rotDX1 = this._tempVector3.set(0, 0, 0).add(faceData[1]).subtract(faceData[0]).scale(1 / texSize);
|
|
2577
|
+
var rotDX2 = this._temp2Vector3.set(0, 0, 0).add(faceData[3]).subtract(faceData[2]).scale(1 / texSize);
|
|
2578
|
+
var dy = 1 / texSize;
|
|
2579
|
+
var fy = 0;
|
|
2580
|
+
for(var y = 0; y < texSize; y++){
|
|
2581
|
+
var xv1 = this._temp3Vector3.set(0, 0, 0).add(faceData[0]);
|
|
2582
|
+
var xv2 = this._temp4Vector3.set(0, 0, 0).add(faceData[2]);
|
|
2583
|
+
for(var x = 0; x < texSize; x++){
|
|
2584
|
+
var v = this._temp5Vector3.set(0, 0, 0).add(xv2).subtract(xv1).scale(fy).add(xv1);
|
|
2585
|
+
v.normalize();
|
|
2586
|
+
var color = this._calcProjectionSpherical(v, pixels, inputWidth, inputHeight);
|
|
2587
|
+
this._RGBEToLinear(color);
|
|
2588
|
+
this._linearToRGBM(color, 5);
|
|
2589
|
+
// 4 channels per pixels
|
|
2590
|
+
var index = y * texSize * 4 + x * 4;
|
|
2591
|
+
textureArray[index] = color.r;
|
|
2592
|
+
textureArray[index + 1] = color.g;
|
|
2593
|
+
textureArray[index + 2] = color.b;
|
|
2594
|
+
textureArray[index + 3] = color.a;
|
|
2595
|
+
xv1.add(rotDX1);
|
|
2596
|
+
xv2.add(rotDX2);
|
|
2597
|
+
}
|
|
2598
|
+
fy += dy;
|
|
2599
|
+
}
|
|
2600
|
+
return textureArray;
|
|
2601
|
+
};
|
|
2602
|
+
HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
|
|
2603
|
+
var theta = Math.atan2(vDir.z, -vDir.x);
|
|
2604
|
+
var phi = Math.acos(vDir.y);
|
|
2605
|
+
while(theta < -PI){
|
|
2606
|
+
theta += 2 * PI;
|
|
2607
|
+
}
|
|
2608
|
+
while(theta > PI){
|
|
2609
|
+
theta -= 2 * PI;
|
|
2610
|
+
}
|
|
2611
|
+
var dx = theta / PI;
|
|
2612
|
+
var dy = phi / PI;
|
|
2613
|
+
// recenter.
|
|
2614
|
+
dx = dx * 0.5 + 0.5;
|
|
2615
|
+
var px = Math.round(dx * inputWidth);
|
|
2616
|
+
if (px < 0) {
|
|
2617
|
+
px = 0;
|
|
2618
|
+
} else if (px >= inputWidth) {
|
|
2619
|
+
px = inputWidth - 1;
|
|
2620
|
+
}
|
|
2621
|
+
var py = Math.round(dy * inputHeight);
|
|
2622
|
+
if (py < 0) {
|
|
2623
|
+
py = 0;
|
|
2624
|
+
} else if (py >= inputHeight) {
|
|
2625
|
+
py = inputHeight - 1;
|
|
2626
|
+
}
|
|
2627
|
+
var inputY = inputHeight - py - 1;
|
|
2628
|
+
var index = inputY * inputWidth * 4 + px * 4;
|
|
2629
|
+
var r = pixels[index];
|
|
2630
|
+
var g = pixels[index + 1];
|
|
2631
|
+
var b = pixels[index + 2];
|
|
2632
|
+
var a = pixels[index + 3];
|
|
2633
|
+
return new Color(r, g, b, a);
|
|
2634
|
+
};
|
|
2635
|
+
HDRLoader1._readStringLine = function _readStringLine(uint8array, startIndex) {
|
|
2636
|
+
var line = "";
|
|
2637
|
+
var character = "";
|
|
2638
|
+
for(var i = startIndex; i < uint8array.length - startIndex; i++){
|
|
2639
|
+
character = String.fromCharCode(uint8array[i]);
|
|
2640
|
+
if (character == "\n") {
|
|
2641
|
+
break;
|
|
2642
|
+
}
|
|
2643
|
+
line += character;
|
|
2644
|
+
}
|
|
2645
|
+
return line;
|
|
2646
|
+
};
|
|
2647
|
+
HDRLoader1._parseHeader = function _parseHeader(uint8array) {
|
|
2648
|
+
var height = 0;
|
|
2649
|
+
var width = 0;
|
|
2650
|
+
var line = this._readStringLine(uint8array, 0);
|
|
2651
|
+
if (line[0] != "#" || line[1] != "?") {
|
|
2652
|
+
throw "Bad HDR Format.";
|
|
2653
|
+
}
|
|
2654
|
+
var endOfHeader = false;
|
|
2655
|
+
var findFormat = false;
|
|
2656
|
+
var lineIndex = 0;
|
|
2657
|
+
do {
|
|
2658
|
+
lineIndex += line.length + 1;
|
|
2659
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
2660
|
+
if (line == "FORMAT=32-bit_rle_rgbe") {
|
|
2661
|
+
findFormat = true;
|
|
2662
|
+
} else if (line.length == 0) {
|
|
2663
|
+
endOfHeader = true;
|
|
2664
|
+
}
|
|
2665
|
+
}while (!endOfHeader);
|
|
2666
|
+
if (!findFormat) {
|
|
2667
|
+
throw "HDR Bad header format, unsupported FORMAT";
|
|
2668
|
+
}
|
|
2669
|
+
lineIndex += line.length + 1;
|
|
2670
|
+
line = this._readStringLine(uint8array, lineIndex);
|
|
2671
|
+
var sizeRegexp = /^\-Y (.*) \+X (.*)$/g;
|
|
2672
|
+
var match = sizeRegexp.exec(line);
|
|
2673
|
+
// TODO. Support +Y and -X if needed.
|
|
2674
|
+
if (!match || match.length < 3) {
|
|
2675
|
+
throw "HDR Bad header format, no size";
|
|
2676
|
+
}
|
|
2677
|
+
width = parseInt(match[2]);
|
|
2678
|
+
height = parseInt(match[1]);
|
|
2679
|
+
if (width < 8 || width > 0x7fff) {
|
|
2680
|
+
throw "HDR Bad header format, unsupported size";
|
|
2681
|
+
}
|
|
2682
|
+
lineIndex += line.length + 1;
|
|
2683
|
+
return {
|
|
2684
|
+
height: height,
|
|
2685
|
+
width: width,
|
|
2686
|
+
dataPosition: lineIndex
|
|
2687
|
+
};
|
|
2688
|
+
};
|
|
2689
|
+
HDRLoader1._readPixels = function _readPixels(buffer, width, height) {
|
|
2690
|
+
var scanLineWidth = width;
|
|
2691
|
+
var byteLength = buffer.byteLength;
|
|
2692
|
+
var dataRGBA = new Uint8Array(4 * width * height);
|
|
2693
|
+
var offset = 0, pos = 0;
|
|
2694
|
+
var ptrEnd = 4 * scanLineWidth;
|
|
2695
|
+
var rgbeStart = new Uint8Array(4);
|
|
2696
|
+
var scanLineBuffer = new Uint8Array(ptrEnd);
|
|
2697
|
+
var numScanLines = height; // read in each successive scanLine
|
|
2698
|
+
while(numScanLines > 0 && pos < byteLength){
|
|
2699
|
+
rgbeStart[0] = buffer[pos++];
|
|
2700
|
+
rgbeStart[1] = buffer[pos++];
|
|
2701
|
+
rgbeStart[2] = buffer[pos++];
|
|
2702
|
+
rgbeStart[3] = buffer[pos++];
|
|
2703
|
+
if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanLineWidth) {
|
|
2704
|
+
throw "HDR Bad header format, wrong scan line width";
|
|
2705
|
+
}
|
|
2706
|
+
// read each of the four channels for the scanline into the buffer
|
|
2707
|
+
// first red, then green, then blue, then exponent
|
|
2708
|
+
var ptr = 0, count = void 0;
|
|
2709
|
+
while(ptr < ptrEnd && pos < byteLength){
|
|
2710
|
+
count = buffer[pos++];
|
|
2711
|
+
var isEncodedRun = count > 128;
|
|
2712
|
+
if (isEncodedRun) count -= 128;
|
|
2713
|
+
if (0 === count || ptr + count > ptrEnd) {
|
|
2714
|
+
throw "HDR Bad Format, bad scanline data (run)";
|
|
2715
|
+
}
|
|
2716
|
+
if (isEncodedRun) {
|
|
2717
|
+
// a (encoded) run of the same value
|
|
2718
|
+
var byteValue = buffer[pos++];
|
|
2719
|
+
for(var i = 0; i < count; i++){
|
|
2720
|
+
scanLineBuffer[ptr++] = byteValue;
|
|
2721
|
+
} //ptr += count;
|
|
2722
|
+
} else {
|
|
2723
|
+
// a literal-run
|
|
2724
|
+
scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
|
|
2725
|
+
ptr += count;
|
|
2726
|
+
pos += count;
|
|
2727
|
+
}
|
|
2728
|
+
} // now convert data from buffer into rgba
|
|
2729
|
+
// first red, then green, then blue, then exponent (alpha)
|
|
2730
|
+
var l = scanLineWidth; //scanLine_buffer.byteLength;
|
|
2731
|
+
for(var i1 = 0; i1 < l; i1++){
|
|
2732
|
+
var off = 0;
|
|
2733
|
+
dataRGBA[offset] = scanLineBuffer[i1 + off];
|
|
2734
|
+
off += scanLineWidth;
|
|
2735
|
+
dataRGBA[offset + 1] = scanLineBuffer[i1 + off];
|
|
2736
|
+
off += scanLineWidth;
|
|
2737
|
+
dataRGBA[offset + 2] = scanLineBuffer[i1 + off];
|
|
2738
|
+
off += scanLineWidth;
|
|
2739
|
+
dataRGBA[offset + 3] = scanLineBuffer[i1 + off];
|
|
2740
|
+
offset += 4;
|
|
2741
|
+
}
|
|
2742
|
+
numScanLines--;
|
|
2743
|
+
}
|
|
2744
|
+
return dataRGBA;
|
|
2745
|
+
};
|
|
2746
|
+
HDRLoader1._RGBEToLinear = function _RGBEToLinear(color) {
|
|
2747
|
+
var scaleFactor = Math.pow(2, color.a - 128) / 255;
|
|
2748
|
+
color.r *= scaleFactor;
|
|
2749
|
+
color.g *= scaleFactor;
|
|
2750
|
+
color.b *= scaleFactor;
|
|
2751
|
+
color.a = 1;
|
|
2752
|
+
};
|
|
2753
|
+
HDRLoader1._linearToRGBM = function _linearToRGBM(color, maxRange) {
|
|
2754
|
+
var maxRGB = Math.max(color.r, Math.max(color.g, color.b));
|
|
2755
|
+
var M = Math.min(maxRGB / maxRange, 1);
|
|
2756
|
+
M = Math.ceil(M * 255);
|
|
2757
|
+
var scaleFactor = 65025 / (M * maxRange); // 255 * (255 / (M * maxRange) )
|
|
2758
|
+
color.r *= scaleFactor;
|
|
2759
|
+
color.g *= scaleFactor;
|
|
2760
|
+
color.b *= scaleFactor;
|
|
2761
|
+
color.a *= M;
|
|
2762
|
+
};
|
|
2763
|
+
return HDRLoader1;
|
|
2764
|
+
}(Loader), function() {
|
|
2765
|
+
_HDRLoader._rightBottomBack = new Vector3(1.0, -1.0, -1.0);
|
|
2766
|
+
}(), function() {
|
|
2767
|
+
_HDRLoader._rightBottomFront = new Vector3(1.0, -1.0, 1.0);
|
|
2768
|
+
}(), function() {
|
|
2769
|
+
_HDRLoader._rightUpBack = new Vector3(1.0, 1.0, -1.0);
|
|
2770
|
+
}(), function() {
|
|
2771
|
+
_HDRLoader._rightUpFront = new Vector3(1.0, 1.0, 1.0);
|
|
2772
|
+
}(), function() {
|
|
2773
|
+
_HDRLoader._leftBottomBack = new Vector3(-1.0, -1.0, -1.0);
|
|
2774
|
+
}(), function() {
|
|
2775
|
+
_HDRLoader._leftBottomFront = new Vector3(-1.0, -1.0, 1.0);
|
|
2776
|
+
}(), function() {
|
|
2777
|
+
_HDRLoader._leftUpBack = new Vector3(-1.0, 1.0, -1.0);
|
|
2778
|
+
}(), function() {
|
|
2779
|
+
_HDRLoader._leftUpFront = new Vector3(-1.0, 1.0, 1.0);
|
|
2780
|
+
}(), function() {
|
|
2781
|
+
_HDRLoader._faceRight = [
|
|
2782
|
+
_HDRLoader._rightBottomBack,
|
|
2783
|
+
_HDRLoader._rightBottomFront,
|
|
2784
|
+
_HDRLoader._rightUpBack,
|
|
2785
|
+
_HDRLoader._rightUpFront
|
|
2786
|
+
];
|
|
2787
|
+
}(), function() {
|
|
2788
|
+
_HDRLoader._faceLeft = [
|
|
2789
|
+
_HDRLoader._leftBottomFront,
|
|
2790
|
+
_HDRLoader._leftBottomBack,
|
|
2791
|
+
_HDRLoader._leftUpFront,
|
|
2792
|
+
_HDRLoader._leftUpBack
|
|
2793
|
+
];
|
|
2794
|
+
}(), function() {
|
|
2795
|
+
_HDRLoader._faceUp = [
|
|
2796
|
+
_HDRLoader._leftBottomFront,
|
|
2797
|
+
_HDRLoader._rightBottomFront,
|
|
2798
|
+
_HDRLoader._leftBottomBack,
|
|
2799
|
+
_HDRLoader._rightBottomBack
|
|
2800
|
+
];
|
|
2801
|
+
}(), function() {
|
|
2802
|
+
_HDRLoader._faceBottom = [
|
|
2803
|
+
_HDRLoader._leftUpBack,
|
|
2804
|
+
_HDRLoader._rightUpBack,
|
|
2805
|
+
_HDRLoader._leftUpFront,
|
|
2806
|
+
_HDRLoader._rightUpFront
|
|
2807
|
+
];
|
|
2808
|
+
}(), function() {
|
|
2809
|
+
_HDRLoader._faceFront = [
|
|
2810
|
+
_HDRLoader._leftBottomBack,
|
|
2811
|
+
_HDRLoader._rightBottomBack,
|
|
2812
|
+
_HDRLoader._leftUpBack,
|
|
2813
|
+
_HDRLoader._rightUpBack
|
|
2814
|
+
];
|
|
2815
|
+
}(), function() {
|
|
2816
|
+
_HDRLoader._faceBack = [
|
|
2817
|
+
_HDRLoader._rightBottomFront,
|
|
2818
|
+
_HDRLoader._leftBottomFront,
|
|
2819
|
+
_HDRLoader._rightUpFront,
|
|
2820
|
+
_HDRLoader._leftUpFront
|
|
2821
|
+
];
|
|
2822
|
+
}(), function() {
|
|
2823
|
+
_HDRLoader._tempVector3 = new Vector3();
|
|
2824
|
+
}(), function() {
|
|
2825
|
+
_HDRLoader._temp2Vector3 = new Vector3();
|
|
2826
|
+
}(), function() {
|
|
2827
|
+
_HDRLoader._temp3Vector3 = new Vector3();
|
|
2828
|
+
}(), function() {
|
|
2829
|
+
_HDRLoader._temp4Vector3 = new Vector3();
|
|
2830
|
+
}(), function() {
|
|
2831
|
+
_HDRLoader._temp5Vector3 = new Vector3();
|
|
2832
|
+
}(), _HDRLoader);
|
|
2833
|
+
HDRLoader = __decorate([
|
|
2834
|
+
resourceLoader(AssetType.HDR, [
|
|
2835
|
+
"hdr"
|
|
2836
|
+
])
|
|
2837
|
+
], HDRLoader);
|
|
2838
|
+
|
|
2839
|
+
var JSONLoader = /*#__PURE__*/ function(Loader) {
|
|
2840
|
+
_inherits(JSONLoader, Loader);
|
|
2841
|
+
function JSONLoader() {
|
|
2842
|
+
return Loader.apply(this, arguments);
|
|
2843
|
+
}
|
|
2844
|
+
var _proto = JSONLoader.prototype;
|
|
2845
|
+
_proto.load = function load(item) {
|
|
2846
|
+
return this.request(item.url, _extends({}, item, {
|
|
2847
|
+
type: "json"
|
|
2848
|
+
}));
|
|
2849
|
+
};
|
|
2850
|
+
return JSONLoader;
|
|
2851
|
+
}(Loader);
|
|
2852
|
+
JSONLoader = __decorate([
|
|
2853
|
+
resourceLoader(AssetType.JSON, [
|
|
2854
|
+
"json"
|
|
2855
|
+
], false)
|
|
2856
|
+
], JSONLoader);
|
|
2857
|
+
|
|
2858
|
+
var HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)
|
|
2859
|
+
// load types
|
|
2860
|
+
var COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()
|
|
2861
|
+
function getMipmaps(ktxContainer, loadMipmaps) {
|
|
2862
|
+
var mipmaps = [];
|
|
2863
|
+
// initialize width & height for level 1
|
|
2864
|
+
var dataOffset = HEADER_LEN + ktxContainer.bytesOfKeyValueData;
|
|
2865
|
+
var width = ktxContainer.pixelWidth;
|
|
2866
|
+
var height = ktxContainer.pixelHeight;
|
|
2867
|
+
var mipmapCount = loadMipmaps ? ktxContainer.numberOfMipmapLevels : 1;
|
|
2868
|
+
for(var level = 0; level < mipmapCount; level++){
|
|
2869
|
+
var imageSize = new Int32Array(ktxContainer.buffer, dataOffset, 1)[0]; // size per face, since not supporting array cubemaps
|
|
2870
|
+
dataOffset += 4; // size of the image + 4 for the imageSize field
|
|
2871
|
+
for(var face = 0; face < ktxContainer.numberOfFaces; face++){
|
|
2872
|
+
var byteArray = new Uint8Array(ktxContainer.buffer, dataOffset, imageSize);
|
|
2873
|
+
mipmaps.push({
|
|
2874
|
+
data: byteArray,
|
|
2875
|
+
width: width,
|
|
2876
|
+
height: height
|
|
2877
|
+
});
|
|
2878
|
+
dataOffset += imageSize;
|
|
2879
|
+
dataOffset += 3 - (imageSize + 3) % 4; // add padding for odd sized image
|
|
2880
|
+
}
|
|
2881
|
+
width = Math.max(1.0, width * 0.5);
|
|
2882
|
+
height = Math.max(1.0, height * 0.5);
|
|
2883
|
+
}
|
|
2884
|
+
return mipmaps;
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2887
|
+
* Checks if the given data starts with a KTX file identifier.
|
|
2888
|
+
* @param data the data to check
|
|
2889
|
+
* @returns true if the data is a KTX file or false otherwise
|
|
2890
|
+
*/ function isValid(data) {
|
|
2891
|
+
if (data.byteLength >= 12) {
|
|
2892
|
+
// '«', 'K', 'T', 'X', ' ', '1', '1', '»', '\r', '\n', '\x1A', '\n'
|
|
2893
|
+
var identifier = new Uint8Array(data, 0, 12);
|
|
2894
|
+
if (identifier[0] === 0xab && identifier[1] === 0x4b && identifier[2] === 0x54 && identifier[3] === 0x58 && identifier[4] === 0x20 && identifier[5] === 0x31 && identifier[6] === 0x31 && identifier[7] === 0xbb && identifier[8] === 0x0d && identifier[9] === 0x0a && identifier[10] === 0x1a && identifier[11] === 0x0a) {
|
|
2895
|
+
return true;
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
function getEngineFormat(internalFormat) {
|
|
2901
|
+
switch(internalFormat){
|
|
2902
|
+
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
|
|
2903
|
+
// case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2904
|
+
// break;
|
|
2905
|
+
case GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
|
|
2906
|
+
return TextureFormat.DXT1;
|
|
2907
|
+
case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
|
|
2908
|
+
return TextureFormat.DXT5;
|
|
2909
|
+
case GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
|
|
2910
|
+
return TextureFormat.ETC1_RGB;
|
|
2911
|
+
case GLCompressedTextureInternalFormat.RGB8_ETC2:
|
|
2912
|
+
return TextureFormat.ETC2_RGB;
|
|
2913
|
+
case GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
|
|
2914
|
+
return TextureFormat.ETC2_RGBA5;
|
|
2915
|
+
case GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
|
|
2916
|
+
return TextureFormat.ETC2_RGBA8;
|
|
2917
|
+
case GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
|
|
2918
|
+
return TextureFormat.PVRTC_RGB2;
|
|
2919
|
+
case GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
|
|
2920
|
+
return TextureFormat.PVRTC_RGBA2;
|
|
2921
|
+
case GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
|
|
2922
|
+
return TextureFormat.PVRTC_RGB4;
|
|
2923
|
+
case GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
|
|
2924
|
+
return TextureFormat.PVRTC_RGBA4;
|
|
2925
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
|
|
2926
|
+
return TextureFormat.ASTC_4x4;
|
|
2927
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
|
|
2928
|
+
return TextureFormat.ASTC_5x5;
|
|
2929
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
|
|
2930
|
+
return TextureFormat.ASTC_6x6;
|
|
2931
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
|
|
2932
|
+
return TextureFormat.ASTC_8x8;
|
|
2933
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
|
|
2934
|
+
return TextureFormat.ASTC_10x10;
|
|
2935
|
+
case GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
|
|
2936
|
+
return TextureFormat.ASTC_12x12;
|
|
2937
|
+
default:
|
|
2938
|
+
var formatName = GLCompressedTextureInternalFormat[internalFormat];
|
|
2939
|
+
throw new Error("this format is not supported in Galacean Engine: " + formatName);
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* for description see https://www.khronos.org/opengles/sdk/tools/KTX/
|
|
2944
|
+
* for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
|
|
2945
|
+
*/ var khronosTextureContainerParser = {
|
|
2946
|
+
/**
|
|
2947
|
+
*
|
|
2948
|
+
* @param buffer contents of the KTX container file
|
|
2949
|
+
* @param facesExpected should be either 1 or 6, based whether a cube texture or or
|
|
2950
|
+
* @param threeDExpected provision for indicating that data should be a 3D texture, not implemented
|
|
2951
|
+
* @param textureArrayExpected provision for indicating that data should be a texture array, not implemented
|
|
2952
|
+
* @param mapEngineFormat get Galacean Engine native TextureFormat?
|
|
2953
|
+
*/ parse: function parse(buffer, facesExpected, withMipmaps, mapEngineFormat) {
|
|
2954
|
+
if (mapEngineFormat === void 0) mapEngineFormat = false;
|
|
2955
|
+
if (!isValid(buffer)) {
|
|
2956
|
+
throw new Error("khronosTextureContainerParser: invalid KTX file, texture missing KTX identifier");
|
|
2957
|
+
}
|
|
2958
|
+
// load the reset of the header in native 32 bit uint
|
|
2959
|
+
var dataSize = Uint32Array.BYTES_PER_ELEMENT;
|
|
2960
|
+
var headerDataView = new DataView(buffer, 12, 13 * dataSize);
|
|
2961
|
+
var endianness = headerDataView.getUint32(0, true);
|
|
2962
|
+
var littleEndian = endianness === 0x04030201;
|
|
2963
|
+
var parsedResult = {
|
|
2964
|
+
buffer: buffer,
|
|
2965
|
+
glType: headerDataView.getUint32(1 * dataSize, littleEndian),
|
|
2966
|
+
glTypeSize: headerDataView.getUint32(2 * dataSize, littleEndian),
|
|
2967
|
+
glFormat: headerDataView.getUint32(3 * dataSize, littleEndian),
|
|
2968
|
+
glInternalFormat: headerDataView.getUint32(4 * dataSize, littleEndian),
|
|
2969
|
+
glBaseInternalFormat: headerDataView.getUint32(5 * dataSize, littleEndian),
|
|
2970
|
+
pixelWidth: headerDataView.getUint32(6 * dataSize, littleEndian),
|
|
2971
|
+
pixelHeight: headerDataView.getUint32(7 * dataSize, littleEndian),
|
|
2972
|
+
pixelDepth: headerDataView.getUint32(8 * dataSize, littleEndian),
|
|
2973
|
+
numberOfArrayElements: headerDataView.getUint32(9 * dataSize, littleEndian),
|
|
2974
|
+
numberOfFaces: headerDataView.getUint32(10 * dataSize, littleEndian),
|
|
2975
|
+
numberOfMipmapLevels: headerDataView.getUint32(11 * dataSize, littleEndian),
|
|
2976
|
+
bytesOfKeyValueData: headerDataView.getUint32(12 * dataSize, littleEndian),
|
|
2977
|
+
// would need to make this more elaborate & adjust checks above to support more than one load type
|
|
2978
|
+
loadType: COMPRESSED_2D
|
|
2979
|
+
};
|
|
2980
|
+
// Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing.
|
|
2981
|
+
if (parsedResult.glType !== 0) {
|
|
2982
|
+
throw new Error("only compressed formats currently supported");
|
|
2983
|
+
} else {
|
|
2984
|
+
// value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.
|
|
2985
|
+
parsedResult.numberOfMipmapLevels = Math.max(1, parsedResult.numberOfMipmapLevels);
|
|
2986
|
+
}
|
|
2987
|
+
if (parsedResult.pixelHeight === 0 || parsedResult.pixelDepth !== 0) {
|
|
2988
|
+
throw new Error("only 2D textures currently supported");
|
|
2989
|
+
}
|
|
2990
|
+
if (parsedResult.numberOfArrayElements !== 0) {
|
|
2991
|
+
throw new Error("texture arrays not currently supported");
|
|
2992
|
+
}
|
|
2993
|
+
if (parsedResult.numberOfFaces !== facesExpected) {
|
|
2994
|
+
throw new Error("number of faces expected" + facesExpected + ", but found " + parsedResult.numberOfFaces);
|
|
2995
|
+
}
|
|
2996
|
+
if (withMipmaps) {
|
|
2997
|
+
parsedResult.mipmaps = getMipmaps(parsedResult, true);
|
|
2998
|
+
}
|
|
2999
|
+
if (mapEngineFormat) {
|
|
3000
|
+
parsedResult.engineFormat = getEngineFormat(parsedResult.glInternalFormat);
|
|
3001
|
+
}
|
|
3002
|
+
return parsedResult;
|
|
3003
|
+
}
|
|
3004
|
+
};
|
|
3005
|
+
|
|
3006
|
+
function parseSingleKTX(data) {
|
|
3007
|
+
var ktx = khronosTextureContainerParser.parse(data, 1, true, true);
|
|
3008
|
+
return {
|
|
3009
|
+
mipmaps: ktx.mipmaps,
|
|
3010
|
+
engineFormat: ktx.engineFormat,
|
|
3011
|
+
internalFormat: ktx.glInternalFormat,
|
|
3012
|
+
width: ktx.pixelWidth,
|
|
3013
|
+
height: ktx.pixelHeight
|
|
3014
|
+
};
|
|
3015
|
+
}
|
|
3016
|
+
function parseCubeKTX(dataArray) {
|
|
3017
|
+
var mipmapsFaces = [];
|
|
3018
|
+
var internalFormat;
|
|
3019
|
+
var engineFormat;
|
|
3020
|
+
var width;
|
|
3021
|
+
var height;
|
|
3022
|
+
for(var i = 0; i < dataArray.length; i++){
|
|
3023
|
+
var ktx = khronosTextureContainerParser.parse(dataArray[i], 1, true, true);
|
|
3024
|
+
mipmapsFaces.push(ktx.mipmaps);
|
|
3025
|
+
if (i === 0) {
|
|
3026
|
+
width = ktx.pixelWidth;
|
|
3027
|
+
height = ktx.pixelHeight;
|
|
3028
|
+
internalFormat = ktx.glInternalFormat;
|
|
3029
|
+
engineFormat = ktx.engineFormat;
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
return {
|
|
3033
|
+
mipmapsFaces: mipmapsFaces,
|
|
3034
|
+
engineFormat: engineFormat,
|
|
3035
|
+
internalFormat: internalFormat,
|
|
3036
|
+
width: width,
|
|
3037
|
+
height: height
|
|
3038
|
+
};
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
var KTXCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
3042
|
+
_inherits(KTXCubeLoader, Loader);
|
|
3043
|
+
function KTXCubeLoader() {
|
|
3044
|
+
return Loader.apply(this, arguments);
|
|
3045
|
+
}
|
|
3046
|
+
var _proto = KTXCubeLoader.prototype;
|
|
3047
|
+
_proto.load = function load(item, resourceManager) {
|
|
3048
|
+
var _this = this;
|
|
3049
|
+
return new AssetPromise(function(resolve, reject) {
|
|
3050
|
+
Promise.all(item.urls.map(function(url) {
|
|
3051
|
+
return _this.request(url, _extends({}, item, {
|
|
3052
|
+
type: "arraybuffer"
|
|
3053
|
+
}));
|
|
3054
|
+
})).then(function(data) {
|
|
3055
|
+
var parsedData = parseCubeKTX(data);
|
|
3056
|
+
var width = parsedData.width, mipmapsFaces = parsedData.mipmapsFaces, engineFormat = parsedData.engineFormat;
|
|
3057
|
+
var mipmap = mipmapsFaces[0].length > 1;
|
|
3058
|
+
var texture = new TextureCube(resourceManager.engine, width, engineFormat, mipmap);
|
|
3059
|
+
for(var face = 0; face < 6; face++){
|
|
3060
|
+
var length = mipmapsFaces[face].length;
|
|
3061
|
+
for(var miplevel = 0; miplevel < length; miplevel++){
|
|
3062
|
+
var _mipmapsFaces_face_miplevel = mipmapsFaces[face][miplevel], _$data = _mipmapsFaces_face_miplevel.data, width1 = _mipmapsFaces_face_miplevel.width, height = _mipmapsFaces_face_miplevel.height;
|
|
3063
|
+
texture.setPixelBuffer(TextureCubeFace.PositiveX + face, _$data, miplevel, 0, 0, width1, height);
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
resolve(texture);
|
|
3067
|
+
}).catch(function(e) {
|
|
3068
|
+
reject(e);
|
|
3069
|
+
});
|
|
3070
|
+
});
|
|
3071
|
+
};
|
|
3072
|
+
return KTXCubeLoader;
|
|
3073
|
+
}(Loader);
|
|
3074
|
+
KTXCubeLoader = __decorate([
|
|
3075
|
+
resourceLoader(AssetType.KTXCube, [])
|
|
3076
|
+
], KTXCubeLoader);
|
|
3077
|
+
|
|
3078
|
+
var KTXLoader = /*#__PURE__*/ function(Loader) {
|
|
3079
|
+
_inherits(KTXLoader, Loader);
|
|
3080
|
+
function KTXLoader() {
|
|
3081
|
+
return Loader.apply(this, arguments);
|
|
3082
|
+
}
|
|
3083
|
+
var _proto = KTXLoader.prototype;
|
|
3084
|
+
_proto.load = function load(item, resourceManager) {
|
|
3085
|
+
var _this = this;
|
|
3086
|
+
return new AssetPromise(function(resolve, reject) {
|
|
3087
|
+
_this.request(item.url, _extends({}, item, {
|
|
3088
|
+
type: "arraybuffer"
|
|
3089
|
+
})).then(function(bin) {
|
|
3090
|
+
var parsedData = parseSingleKTX(bin);
|
|
3091
|
+
var width = parsedData.width, height = parsedData.height, mipmaps = parsedData.mipmaps, engineFormat = parsedData.engineFormat;
|
|
3092
|
+
var mipmap = mipmaps.length > 1;
|
|
3093
|
+
var texture = new Texture2D(resourceManager.engine, width, height, engineFormat, mipmap);
|
|
3094
|
+
for(var miplevel = 0; miplevel < mipmaps.length; miplevel++){
|
|
3095
|
+
var _mipmaps_miplevel = mipmaps[miplevel], width1 = _mipmaps_miplevel.width, height1 = _mipmaps_miplevel.height, data = _mipmaps_miplevel.data;
|
|
3096
|
+
texture.setPixelBuffer(data, miplevel, 0, 0, width1, height1);
|
|
3097
|
+
}
|
|
3098
|
+
resolve(texture);
|
|
3099
|
+
}).catch(function(e) {
|
|
3100
|
+
reject(e);
|
|
3101
|
+
});
|
|
3102
|
+
});
|
|
3103
|
+
};
|
|
3104
|
+
return KTXLoader;
|
|
3105
|
+
}(Loader);
|
|
3106
|
+
KTXLoader = __decorate([
|
|
3107
|
+
resourceLoader(AssetType.KTX, [
|
|
3108
|
+
"ktx"
|
|
3109
|
+
])
|
|
3110
|
+
], KTXLoader);
|
|
3111
|
+
|
|
3112
|
+
var MaterialLoader = /*#__PURE__*/ function(Loader) {
|
|
3113
|
+
_inherits(MaterialLoader, Loader);
|
|
3114
|
+
function MaterialLoader() {
|
|
3115
|
+
return Loader.apply(this, arguments);
|
|
3116
|
+
}
|
|
3117
|
+
var _proto = MaterialLoader.prototype;
|
|
3118
|
+
_proto.load = function load(item, resourceManager) {
|
|
3119
|
+
var _this = this;
|
|
3120
|
+
return new AssetPromise(function(resolve, reject) {
|
|
3121
|
+
_this.request(item.url, _extends({}, item, {
|
|
3122
|
+
type: "json"
|
|
3123
|
+
})).then(function(json) {
|
|
3124
|
+
var _loop = function(key) {
|
|
3125
|
+
var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
|
|
3126
|
+
switch(type){
|
|
3127
|
+
case "Vector2":
|
|
3128
|
+
materialShaderData.setVector2(key, new Vector2(value.x, value.y));
|
|
3129
|
+
break;
|
|
3130
|
+
case "Vector3":
|
|
3131
|
+
materialShaderData.setVector3(key, new Vector3(value.x, value.y, value.z));
|
|
3132
|
+
break;
|
|
3133
|
+
case "Vector4":
|
|
3134
|
+
materialShaderData.setVector4(key, new Vector4(value.x, value.y, value.z, value.w));
|
|
3135
|
+
break;
|
|
3136
|
+
case "Color":
|
|
3137
|
+
materialShaderData.setColor(key, new Color(value.r, value.g, value.b, value.a));
|
|
3138
|
+
break;
|
|
3139
|
+
case "Float":
|
|
3140
|
+
materialShaderData.setFloat(key, value);
|
|
3141
|
+
break;
|
|
3142
|
+
case "Texture":
|
|
3143
|
+
texturePromises.push(// @ts-ignore
|
|
3144
|
+
resourceManager.getResourceByRef(value).then(function(texture) {
|
|
3145
|
+
materialShaderData.setTexture(key, texture);
|
|
3146
|
+
}));
|
|
3147
|
+
break;
|
|
3148
|
+
}
|
|
3149
|
+
};
|
|
3150
|
+
var engine = resourceManager.engine;
|
|
3151
|
+
var name = json.name, shader = json.shader, shaderData = json.shaderData, macros = json.macros, renderState = json.renderState;
|
|
3152
|
+
var material;
|
|
3153
|
+
switch(shader){
|
|
3154
|
+
case "pbr":
|
|
3155
|
+
material = new PBRMaterial(engine);
|
|
3156
|
+
break;
|
|
3157
|
+
case "pbr-specular":
|
|
3158
|
+
material = new PBRSpecularMaterial(engine);
|
|
3159
|
+
break;
|
|
3160
|
+
case "unlit":
|
|
3161
|
+
material = new UnlitMaterial(engine);
|
|
3162
|
+
break;
|
|
3163
|
+
case "blinn-phong":
|
|
3164
|
+
material = new BlinnPhongMaterial(engine);
|
|
3165
|
+
break;
|
|
3166
|
+
case "bake-pbr":
|
|
3167
|
+
// @todo refactor custom shader later
|
|
3168
|
+
// @ts-ignore
|
|
3169
|
+
material = new PBRBaseMaterial(engine, Shader.find("bake-pbr"));
|
|
3170
|
+
break;
|
|
3171
|
+
}
|
|
3172
|
+
material.name = name;
|
|
3173
|
+
var texturePromises = new Array();
|
|
3174
|
+
var materialShaderData = material.shaderData;
|
|
3175
|
+
for(var key in shaderData)_loop(key);
|
|
3176
|
+
for(var i = 0, length = macros.length; i < length; i++){
|
|
3177
|
+
var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
|
|
3178
|
+
if (value == undefined) {
|
|
3179
|
+
materialShaderData.enableMacro(name1);
|
|
3180
|
+
} else {
|
|
3181
|
+
materialShaderData.enableMacro(name1, value);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
for(var key1 in renderState){
|
|
3185
|
+
material[key1] = renderState[key1];
|
|
3186
|
+
}
|
|
3187
|
+
return Promise.all(texturePromises).then(function() {
|
|
3188
|
+
resolve(material);
|
|
3189
|
+
});
|
|
3190
|
+
}).catch(reject);
|
|
3191
|
+
});
|
|
3192
|
+
};
|
|
3193
|
+
return MaterialLoader;
|
|
3194
|
+
}(Loader);
|
|
3195
|
+
MaterialLoader = __decorate([
|
|
3196
|
+
resourceLoader(AssetType.Material, [
|
|
3197
|
+
"json"
|
|
3198
|
+
])
|
|
3199
|
+
], MaterialLoader);
|
|
3200
|
+
|
|
3201
|
+
function _defineProperties(target, props) {
|
|
3202
|
+
for (var i = 0; i < props.length; i++) {
|
|
3203
|
+
var descriptor = props[i];
|
|
3204
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
3205
|
+
descriptor.configurable = true;
|
|
3206
|
+
|
|
3207
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
3208
|
+
|
|
3209
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
3213
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3214
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3215
|
+
|
|
3216
|
+
return Constructor;
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
var BufferReader = /*#__PURE__*/ function() {
|
|
3220
|
+
function BufferReader(buffer, byteOffset, byteLength, littleEndian) {
|
|
3221
|
+
if (byteOffset === void 0) byteOffset = 0;
|
|
3222
|
+
if (littleEndian === void 0) littleEndian = true;
|
|
3223
|
+
this.buffer = buffer;
|
|
3224
|
+
// byteLength = byteLength ?? _buffer.byteLength;
|
|
3225
|
+
this._dataView = new DataView(buffer);
|
|
3226
|
+
this._littleEndian = littleEndian;
|
|
3227
|
+
this._offset = byteOffset;
|
|
3228
|
+
}
|
|
3229
|
+
var _proto = BufferReader.prototype;
|
|
3230
|
+
_proto.nextUint8 = function nextUint8() {
|
|
3231
|
+
var value = this._dataView.getUint8(this._offset);
|
|
3232
|
+
this._offset += 1;
|
|
3233
|
+
return value;
|
|
3234
|
+
};
|
|
3235
|
+
_proto.nextUint16 = function nextUint16() {
|
|
3236
|
+
var value = this._dataView.getUint16(this._offset, this._littleEndian);
|
|
3237
|
+
this._offset += 2;
|
|
3238
|
+
return value;
|
|
3239
|
+
};
|
|
3240
|
+
_proto.nextUint32 = function nextUint32() {
|
|
3241
|
+
var value = this._dataView.getUint32(this._offset, this._littleEndian);
|
|
3242
|
+
this._offset += 4;
|
|
3243
|
+
return value;
|
|
3244
|
+
};
|
|
3245
|
+
_proto.nextInt32 = function nextInt32() {
|
|
3246
|
+
var value = this._dataView.getInt32(this._offset, this._littleEndian);
|
|
3247
|
+
this._offset += 4;
|
|
3248
|
+
return value;
|
|
3249
|
+
};
|
|
3250
|
+
_proto.nextInt32Array = function nextInt32Array(len) {
|
|
3251
|
+
var value = new Int32Array(this.buffer, this._offset, len);
|
|
3252
|
+
this._offset += 4 * len;
|
|
3253
|
+
return value;
|
|
3254
|
+
};
|
|
3255
|
+
_proto.nextFloat32 = function nextFloat32() {
|
|
3256
|
+
var value = this._dataView.getFloat32(this._offset, this._littleEndian);
|
|
3257
|
+
this._offset += 4;
|
|
3258
|
+
return value;
|
|
3259
|
+
};
|
|
3260
|
+
_proto.nextFloat32Array = function nextFloat32Array(len) {
|
|
3261
|
+
var value = new Float32Array(this.buffer, this._offset, len);
|
|
3262
|
+
this._offset += 4 * len;
|
|
3263
|
+
return value;
|
|
3264
|
+
};
|
|
3265
|
+
_proto.nextUint32Array = function nextUint32Array(len) {
|
|
3266
|
+
var value = new Uint32Array(this.buffer, this._offset, len);
|
|
3267
|
+
this._offset += 4 * len;
|
|
3268
|
+
return value;
|
|
3269
|
+
};
|
|
3270
|
+
_proto.nextUint8Array = function nextUint8Array(len) {
|
|
3271
|
+
var value = new Uint8Array(this.buffer, this._offset, len);
|
|
3272
|
+
this._offset += len;
|
|
3273
|
+
return value;
|
|
3274
|
+
};
|
|
3275
|
+
_proto.nextUint64 = function nextUint64() {
|
|
3276
|
+
var left = this._dataView.getUint32(this._offset, this._littleEndian);
|
|
3277
|
+
var right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
|
|
3278
|
+
var value = left + Math.pow(2, 32) * right;
|
|
3279
|
+
this._offset += 8;
|
|
3280
|
+
return value;
|
|
3281
|
+
};
|
|
3282
|
+
_proto.nextStr = function nextStr() {
|
|
3283
|
+
var strByteLength = this.nextUint16();
|
|
3284
|
+
var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
|
|
3285
|
+
this._offset += strByteLength;
|
|
3286
|
+
return GLTFUtil.decodeText(uint8Array);
|
|
3287
|
+
};
|
|
3288
|
+
/**
|
|
3289
|
+
* image data 放在最后
|
|
3290
|
+
*/ _proto.nextImageData = function nextImageData(count) {
|
|
3291
|
+
return this.buffer.slice(this._offset);
|
|
3292
|
+
};
|
|
3293
|
+
_proto.nextImagesData = function nextImagesData(count) {
|
|
3294
|
+
var imagesLen = new Array(count);
|
|
3295
|
+
// Start offset of Uint32Array should be a multiple of 4. ref: https://stackoverflow.com/questions/15417310/why-typed-array-constructors-require-offset-to-be-multiple-of-underlying-type-si
|
|
3296
|
+
for(var i = 0; i < count; i++){
|
|
3297
|
+
var len = this._dataView.getUint32(this._offset, this._littleEndian);
|
|
3298
|
+
imagesLen[i] = len;
|
|
3299
|
+
this._offset += 4;
|
|
3300
|
+
}
|
|
3301
|
+
var imagesData = [];
|
|
3302
|
+
for(var i1 = 0; i1 < count; i1++){
|
|
3303
|
+
var len1 = imagesLen[i1];
|
|
3304
|
+
var buffer = this.buffer.slice(this._offset, this._offset + len1);
|
|
3305
|
+
this._offset += len1;
|
|
3306
|
+
imagesData.push(buffer);
|
|
3307
|
+
}
|
|
3308
|
+
return imagesData;
|
|
3309
|
+
};
|
|
3310
|
+
_proto.skip = function skip(bytes) {
|
|
3311
|
+
this._offset += bytes;
|
|
3312
|
+
return this;
|
|
3313
|
+
};
|
|
3314
|
+
_proto.scan = function scan(maxByteLength, term) {
|
|
3315
|
+
if (term === void 0) term = 0x00;
|
|
3316
|
+
var byteOffset = this._offset;
|
|
3317
|
+
var byteLength = 0;
|
|
3318
|
+
while(this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength){
|
|
3319
|
+
byteLength++;
|
|
3320
|
+
this._offset++;
|
|
3321
|
+
}
|
|
3322
|
+
if (byteLength < maxByteLength) this._offset++;
|
|
3323
|
+
return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
|
|
3324
|
+
};
|
|
3325
|
+
_create_class(BufferReader, [
|
|
3326
|
+
{
|
|
3327
|
+
key: "offset",
|
|
3328
|
+
get: function get() {
|
|
3329
|
+
return this._offset;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
]);
|
|
3333
|
+
return BufferReader;
|
|
3334
|
+
}();
|
|
3335
|
+
(function() {
|
|
3336
|
+
BufferReader.imageMapping = {
|
|
3337
|
+
0: "image/png",
|
|
3338
|
+
1: "image/jpg",
|
|
3339
|
+
2: "image/webp",
|
|
3340
|
+
3: "ktx"
|
|
3341
|
+
};
|
|
3342
|
+
})();
|
|
3343
|
+
|
|
3344
|
+
var decoderMap = {};
|
|
3345
|
+
/**
|
|
3346
|
+
* Decoder decorator generator.
|
|
3347
|
+
* @param type - resource file type.
|
|
3348
|
+
* @returns Decoder decorator
|
|
3349
|
+
*/ function decoder(type) {
|
|
3350
|
+
return function(target) {
|
|
3351
|
+
decoderMap[type] = target;
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
var FileHeader = /*#__PURE__*/ function() {
|
|
3356
|
+
function FileHeader() {
|
|
3357
|
+
this.totalLength = 0;
|
|
3358
|
+
this.version = 0;
|
|
3359
|
+
this.type = "";
|
|
3360
|
+
this.name = "";
|
|
3361
|
+
this.headerLength = 0;
|
|
3362
|
+
}
|
|
3363
|
+
FileHeader.decode = function decode(arrayBuffer) {
|
|
3364
|
+
var dataView = new DataView(arrayBuffer);
|
|
3365
|
+
var totalLen = dataView.getUint32(0, true);
|
|
3366
|
+
var fileVersion = dataView.getUint8(4);
|
|
3367
|
+
var typeLen = dataView.getUint16(5, true);
|
|
3368
|
+
var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
|
|
3369
|
+
var nameLen = dataView.getUint16(7 + typeLen, true);
|
|
3370
|
+
var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
|
|
3371
|
+
var name = GLTFUtil.decodeText(nameUint8Array);
|
|
3372
|
+
var type = GLTFUtil.decodeText(typeUint8Array);
|
|
3373
|
+
var header = new FileHeader();
|
|
3374
|
+
header.totalLength = totalLen;
|
|
3375
|
+
header.name = name;
|
|
3376
|
+
header.type = type;
|
|
3377
|
+
header.version = fileVersion;
|
|
3378
|
+
header.headerLength = nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
|
|
3379
|
+
return header;
|
|
3380
|
+
};
|
|
3381
|
+
_create_class(FileHeader, [
|
|
3382
|
+
{
|
|
3383
|
+
key: "dataLength",
|
|
3384
|
+
get: function get() {
|
|
3385
|
+
return this.totalLength - this.headerLength;
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
]);
|
|
3389
|
+
return FileHeader;
|
|
3390
|
+
}();
|
|
3391
|
+
|
|
3392
|
+
var MeshDecoder = /*#__PURE__*/ function() {
|
|
3393
|
+
function MeshDecoder() {}
|
|
3394
|
+
MeshDecoder.decode = function decode(engine, bufferReader) {
|
|
3395
|
+
return new Promise(function(resolve) {
|
|
3396
|
+
var modelMesh = new ModelMesh(engine);
|
|
3397
|
+
var jsonDataString = bufferReader.nextStr();
|
|
3398
|
+
var encodedMeshData = JSON.parse(jsonDataString);
|
|
3399
|
+
// @ts-ignore Vector3 is not compatible with {x: number, y: number, z: number}.
|
|
3400
|
+
encodedMeshData.bounds && modelMesh.bounds.copyFrom(encodedMeshData.bounds);
|
|
3401
|
+
var offset = Math.ceil(bufferReader.offset / 4) * 4;
|
|
3402
|
+
var float32Array = new Float32Array(bufferReader.buffer, encodedMeshData.positions.start + offset, (encodedMeshData.positions.end - encodedMeshData.positions.start) / 4);
|
|
3403
|
+
var vertexCount = float32Array.length / 3;
|
|
3404
|
+
var positions = float32ArrayToVector3(float32Array, vertexCount);
|
|
3405
|
+
modelMesh.setPositions(positions);
|
|
3406
|
+
if (encodedMeshData.normals) {
|
|
3407
|
+
var float32Array1 = new Float32Array(bufferReader.buffer, encodedMeshData.normals.start + offset, (encodedMeshData.normals.end - encodedMeshData.normals.start) / 4);
|
|
3408
|
+
var normals = float32ArrayToVector3(float32Array1, vertexCount);
|
|
3409
|
+
modelMesh.setNormals(normals);
|
|
3410
|
+
}
|
|
3411
|
+
if (encodedMeshData.uvs) {
|
|
3412
|
+
var float32Array2 = new Float32Array(bufferReader.buffer, encodedMeshData.uvs.start + offset, (encodedMeshData.uvs.end - encodedMeshData.uvs.start) / 4);
|
|
3413
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array2, vertexCount));
|
|
3414
|
+
}
|
|
3415
|
+
if (encodedMeshData.uv1) {
|
|
3416
|
+
var float32Array3 = new Float32Array(bufferReader.buffer, encodedMeshData.uv1.start + offset, (encodedMeshData.uv1.end - encodedMeshData.uv1.start) / 4);
|
|
3417
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array3, vertexCount), 1);
|
|
3418
|
+
}
|
|
3419
|
+
if (encodedMeshData.uv2) {
|
|
3420
|
+
var float32Array4 = new Float32Array(bufferReader.buffer, encodedMeshData.uv2.start + offset, (encodedMeshData.uv2.end - encodedMeshData.uv2.start) / 4);
|
|
3421
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array4, vertexCount), 2);
|
|
3422
|
+
}
|
|
3423
|
+
if (encodedMeshData.uv3) {
|
|
3424
|
+
var float32Array5 = new Float32Array(bufferReader.buffer, encodedMeshData.uv3.start + offset, (encodedMeshData.uv3.end - encodedMeshData.uv3.start) / 4);
|
|
3425
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array5, vertexCount), 3);
|
|
3426
|
+
}
|
|
3427
|
+
if (encodedMeshData.uv4) {
|
|
3428
|
+
var float32Array6 = new Float32Array(bufferReader.buffer, encodedMeshData.uv4.start + offset, (encodedMeshData.uv4.end - encodedMeshData.uv4.start) / 4);
|
|
3429
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array6, vertexCount), 4);
|
|
3430
|
+
}
|
|
3431
|
+
if (encodedMeshData.uv5) {
|
|
3432
|
+
var float32Array7 = new Float32Array(bufferReader.buffer, encodedMeshData.uv5.start + offset, (encodedMeshData.uv5.end - encodedMeshData.uv5.start) / 4);
|
|
3433
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array7, vertexCount), 5);
|
|
3434
|
+
}
|
|
3435
|
+
if (encodedMeshData.uv6) {
|
|
3436
|
+
var float32Array8 = new Float32Array(bufferReader.buffer, encodedMeshData.uv6.start + offset, (encodedMeshData.uv6.end - encodedMeshData.uv6.start) / 4);
|
|
3437
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array8, vertexCount), 6);
|
|
3438
|
+
}
|
|
3439
|
+
if (encodedMeshData.uv7) {
|
|
3440
|
+
var float32Array9 = new Float32Array(bufferReader.buffer, encodedMeshData.uv7.start + offset, (encodedMeshData.uv7.end - encodedMeshData.uv7.start) / 4);
|
|
3441
|
+
modelMesh.setUVs(float32ArrayToVector2(float32Array9, vertexCount), 7);
|
|
3442
|
+
}
|
|
3443
|
+
if (encodedMeshData.colors) {
|
|
3444
|
+
var float32Array10 = new Float32Array(bufferReader.buffer, encodedMeshData.colors.start + offset, (encodedMeshData.colors.end - encodedMeshData.colors.start) / 4);
|
|
3445
|
+
modelMesh.setColors(float32ArrayToVColor(float32Array10, vertexCount));
|
|
3446
|
+
}
|
|
3447
|
+
if (encodedMeshData.boneWeights) {
|
|
3448
|
+
var float32Array11 = new Float32Array(bufferReader.buffer, encodedMeshData.boneWeights.start + offset, (encodedMeshData.boneWeights.end - encodedMeshData.boneWeights.start) / 4);
|
|
3449
|
+
modelMesh.setBoneWeights(float32ArrayToVector4(float32Array11, vertexCount));
|
|
3450
|
+
}
|
|
3451
|
+
if (encodedMeshData.boneIndices) {
|
|
3452
|
+
var float32Array12 = new Float32Array(bufferReader.buffer, encodedMeshData.boneIndices.start + offset, (encodedMeshData.boneIndices.end - encodedMeshData.boneIndices.start) / 4);
|
|
3453
|
+
modelMesh.setBoneIndices(float32ArrayToVector4(float32Array12, vertexCount));
|
|
3454
|
+
}
|
|
3455
|
+
if (encodedMeshData.blendShapes) {
|
|
3456
|
+
encodedMeshData.blendShapes.forEach(function(blendShapeData) {
|
|
3457
|
+
var blendShape = new BlendShape(blendShapeData.name);
|
|
3458
|
+
blendShapeData.frames.forEach(function(frameData) {
|
|
3459
|
+
var positionArray = new Float32Array(bufferReader.buffer, frameData.deltaPosition.start + offset, (frameData.deltaPosition.end - frameData.deltaPosition.start) / 4);
|
|
3460
|
+
var count = positionArray.length / 3;
|
|
3461
|
+
var deltaPosition = float32ArrayToVector3(positionArray, count);
|
|
3462
|
+
if (frameData.deltaNormals) {
|
|
3463
|
+
var normalsArray = new Float32Array(bufferReader.buffer, frameData.deltaNormals.start + offset, (frameData.deltaNormals.end - frameData.deltaNormals.start) / 4);
|
|
3464
|
+
float32ArrayToVector3(normalsArray, count);
|
|
3465
|
+
}
|
|
3466
|
+
if (frameData.deltaTangents) {
|
|
3467
|
+
var tangentsArray = new Float32Array(bufferReader.buffer, frameData.deltaTangents.start + offset, (frameData.deltaTangents.end - frameData.deltaTangents.start) / 4);
|
|
3468
|
+
float32ArrayToVector4(tangentsArray, count);
|
|
3469
|
+
}
|
|
3470
|
+
blendShape.addFrame(frameData.weight, deltaPosition);
|
|
3471
|
+
});
|
|
3472
|
+
modelMesh.addBlendShape(blendShape);
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3475
|
+
if (encodedMeshData.indices) {
|
|
3476
|
+
var indices = null;
|
|
3477
|
+
if (encodedMeshData.indices.type === 0) {
|
|
3478
|
+
indices = new Uint16Array(bufferReader.buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 2);
|
|
3479
|
+
} else {
|
|
3480
|
+
indices = new Uint32Array(bufferReader.buffer, encodedMeshData.indices.start + offset, (encodedMeshData.indices.end - encodedMeshData.indices.start) / 4);
|
|
3481
|
+
}
|
|
3482
|
+
modelMesh.setIndices(indices);
|
|
3483
|
+
}
|
|
3484
|
+
encodedMeshData.subMeshes.forEach(function(subMesh) {
|
|
3485
|
+
return modelMesh.addSubMesh(subMesh);
|
|
3486
|
+
});
|
|
3487
|
+
modelMesh.uploadData(false);
|
|
3488
|
+
resolve(modelMesh);
|
|
3489
|
+
});
|
|
3490
|
+
};
|
|
3491
|
+
return MeshDecoder;
|
|
3492
|
+
}();
|
|
3493
|
+
MeshDecoder = __decorate([
|
|
3494
|
+
decoder("Mesh")
|
|
3495
|
+
], MeshDecoder);
|
|
3496
|
+
function float32ArrayToVColor(float32Array, vertexCount) {
|
|
3497
|
+
var array = new Array(vertexCount);
|
|
3498
|
+
for(var i = 0; i < vertexCount; i++){
|
|
3499
|
+
array[i] = new Color(float32Array[i * 4], float32Array[i * 4 + 1], float32Array[i * 4 + 2], float32Array[i * 4 + 3]);
|
|
3500
|
+
}
|
|
3501
|
+
return array;
|
|
3502
|
+
}
|
|
3503
|
+
function float32ArrayToVector4(float32Array, vertexCount) {
|
|
3504
|
+
var array = new Array(vertexCount);
|
|
3505
|
+
for(var i = 0; i < vertexCount; i++){
|
|
3506
|
+
array[i] = new Vector4(float32Array[i * 4], float32Array[i * 4 + 1], float32Array[i * 4 + 2], float32Array[i * 4 + 3]);
|
|
3507
|
+
}
|
|
3508
|
+
return array;
|
|
3509
|
+
}
|
|
3510
|
+
function float32ArrayToVector3(float32Array, vertexCount) {
|
|
3511
|
+
var array = new Array(vertexCount);
|
|
3512
|
+
for(var i = 0; i < vertexCount; i++){
|
|
3513
|
+
array[i] = new Vector3(float32Array[i * 3], float32Array[i * 3 + 1], float32Array[i * 3 + 2]);
|
|
3514
|
+
}
|
|
3515
|
+
return array;
|
|
3516
|
+
}
|
|
3517
|
+
function float32ArrayToVector2(float32Array, vertexCount) {
|
|
3518
|
+
var array = new Array(vertexCount);
|
|
3519
|
+
for(var i = 0; i < vertexCount; i++){
|
|
3520
|
+
array[i] = new Vector2(float32Array[i * 2], float32Array[i * 2 + 1]);
|
|
3521
|
+
}
|
|
3522
|
+
return array;
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
var Texture2DDecoder = /*#__PURE__*/ function() {
|
|
3526
|
+
function Texture2DDecoder() {}
|
|
3527
|
+
Texture2DDecoder.decode = function decode(engine, bufferReader) {
|
|
3528
|
+
return new Promise(function(resolve, reject) {
|
|
3529
|
+
var objectId = bufferReader.nextStr();
|
|
3530
|
+
var mipmap = !!bufferReader.nextUint8();
|
|
3531
|
+
var filterMode = bufferReader.nextUint8();
|
|
3532
|
+
var anisoLevel = bufferReader.nextUint8();
|
|
3533
|
+
var wrapModeU = bufferReader.nextUint8();
|
|
3534
|
+
var wrapModeV = bufferReader.nextUint8();
|
|
3535
|
+
var format = bufferReader.nextUint8();
|
|
3536
|
+
var width = bufferReader.nextUint16();
|
|
3537
|
+
var height = bufferReader.nextUint16();
|
|
3538
|
+
var isPixelBuffer = bufferReader.nextUint8();
|
|
3539
|
+
var mipCount = bufferReader.nextUint8();
|
|
3540
|
+
var imagesData = bufferReader.nextImagesData(mipCount);
|
|
3541
|
+
var texture2D = new Texture2D(engine, width, height, format, mipmap);
|
|
3542
|
+
texture2D.filterMode = filterMode;
|
|
3543
|
+
texture2D.anisoLevel = anisoLevel;
|
|
3544
|
+
texture2D.wrapModeU = wrapModeU;
|
|
3545
|
+
texture2D.wrapModeV = wrapModeV;
|
|
3546
|
+
if (isPixelBuffer) {
|
|
3547
|
+
var pixelBuffer = new Uint8Array(imagesData[0]);
|
|
3548
|
+
texture2D.setPixelBuffer(pixelBuffer);
|
|
3549
|
+
if (mipmap) {
|
|
3550
|
+
texture2D.generateMipmaps();
|
|
3551
|
+
for(var i = 1; i < mipCount; i++){
|
|
3552
|
+
var pixelBuffer1 = new Uint8Array(imagesData[i]);
|
|
3553
|
+
texture2D.setPixelBuffer(pixelBuffer1, i);
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
// @ts-ignore
|
|
3557
|
+
engine.resourceManager._objectPool[objectId] = texture2D;
|
|
3558
|
+
resolve(texture2D);
|
|
3559
|
+
} else {
|
|
3560
|
+
var blob = new window.Blob([
|
|
3561
|
+
imagesData[0]
|
|
3562
|
+
]);
|
|
3563
|
+
var img = new Image();
|
|
3564
|
+
img.onload = function() {
|
|
3565
|
+
texture2D.setImageSource(img);
|
|
3566
|
+
var completedCount = 0;
|
|
3567
|
+
var onComplete = function() {
|
|
3568
|
+
completedCount++;
|
|
3569
|
+
if (completedCount >= mipCount) {
|
|
3570
|
+
resolve(texture2D);
|
|
3571
|
+
}
|
|
3572
|
+
};
|
|
3573
|
+
onComplete();
|
|
3574
|
+
if (mipmap) {
|
|
3575
|
+
var _loop = function(i) {
|
|
3576
|
+
var blob = new window.Blob([
|
|
3577
|
+
imagesData[i]
|
|
3578
|
+
]);
|
|
3579
|
+
var img = new Image();
|
|
3580
|
+
img.onload = function() {
|
|
3581
|
+
texture2D.setImageSource(img, i);
|
|
3582
|
+
onComplete();
|
|
3583
|
+
};
|
|
3584
|
+
img.src = URL.createObjectURL(blob);
|
|
3585
|
+
};
|
|
3586
|
+
texture2D.generateMipmaps();
|
|
3587
|
+
for(var i = 1; i < mipCount; i++)_loop(i);
|
|
3588
|
+
}
|
|
3589
|
+
};
|
|
3590
|
+
img.src = URL.createObjectURL(blob);
|
|
3591
|
+
}
|
|
3592
|
+
});
|
|
3593
|
+
};
|
|
3594
|
+
return Texture2DDecoder;
|
|
3595
|
+
}();
|
|
3596
|
+
Texture2DDecoder = __decorate([
|
|
3597
|
+
decoder("Texture2D")
|
|
3598
|
+
], Texture2DDecoder);
|
|
3599
|
+
|
|
3600
|
+
function _is_native_reflect_construct() {
|
|
3601
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
3602
|
+
if (Reflect.construct.sham) return false;
|
|
3603
|
+
if (typeof Proxy === "function") return true;
|
|
3604
|
+
|
|
3605
|
+
try {
|
|
3606
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
3607
|
+
|
|
3608
|
+
return true;
|
|
3609
|
+
} catch (e) {
|
|
3610
|
+
return false;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
function _construct(Parent, args, Class) {
|
|
3615
|
+
if (_is_native_reflect_construct()) _construct = Reflect.construct;
|
|
3616
|
+
else {
|
|
3617
|
+
_construct = function construct(Parent, args, Class) {
|
|
3618
|
+
var a = [null];
|
|
3619
|
+
a.push.apply(a, args);
|
|
3620
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
3621
|
+
var instance = new Constructor();
|
|
3622
|
+
|
|
3623
|
+
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
3624
|
+
|
|
3625
|
+
return instance;
|
|
3626
|
+
};
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
return _construct.apply(null, arguments);
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
var ReflectionParser = /*#__PURE__*/ function() {
|
|
3633
|
+
function ReflectionParser() {}
|
|
3634
|
+
ReflectionParser.registerCustomParseComponent = function registerCustomParseComponent(componentType, handle) {
|
|
3635
|
+
this.customParseComponentHandles[componentType] = handle;
|
|
3636
|
+
};
|
|
3637
|
+
ReflectionParser.parseEntity = function parseEntity(entityConfig, engine) {
|
|
3638
|
+
return ReflectionParser.getEntityByConfig(entityConfig, engine).then(function(entity) {
|
|
3639
|
+
var _entityConfig_isActive;
|
|
3640
|
+
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : true;
|
|
3641
|
+
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
3642
|
+
if (position) entity.transform.position.copyFrom(position);
|
|
3643
|
+
if (rotation) entity.transform.rotation.copyFrom(rotation);
|
|
3644
|
+
if (scale) entity.transform.scale.copyFrom(scale);
|
|
3645
|
+
return entity;
|
|
3646
|
+
});
|
|
3647
|
+
};
|
|
3648
|
+
ReflectionParser.getEntityByConfig = function getEntityByConfig(entityConfig, engine) {
|
|
3649
|
+
// @ts-ignore
|
|
3650
|
+
var assetRefId = entityConfig.assetRefId;
|
|
3651
|
+
if (assetRefId) {
|
|
3652
|
+
return engine.resourceManager// @ts-ignore
|
|
3653
|
+
.getResourceByRef({
|
|
3654
|
+
refId: assetRefId,
|
|
3655
|
+
key: entityConfig.key,
|
|
3656
|
+
isClone: entityConfig.isClone
|
|
3657
|
+
}).then(function(entity) {
|
|
3658
|
+
entity.name = entityConfig.name;
|
|
3659
|
+
return entity;
|
|
3660
|
+
});
|
|
3661
|
+
} else {
|
|
3662
|
+
var entity = new Entity(engine, entityConfig.name);
|
|
3663
|
+
return Promise.resolve(entity);
|
|
3664
|
+
}
|
|
3665
|
+
};
|
|
3666
|
+
ReflectionParser.parseClassObject = function parseClassObject(item, engine, resourceManager) {
|
|
3667
|
+
if (resourceManager === void 0) resourceManager = engine.resourceManager;
|
|
3668
|
+
var Class = Loader.getClass(item.class);
|
|
3669
|
+
var _item_constructParams;
|
|
3670
|
+
var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
|
|
3671
|
+
var instance = _construct(Class, [].concat(params));
|
|
3672
|
+
return this.parsePropsAndMethods(instance, item, engine, resourceManager);
|
|
3673
|
+
};
|
|
3674
|
+
ReflectionParser.parseBasicType = function parseBasicType(value, engine, resourceManager) {
|
|
3675
|
+
if (resourceManager === void 0) resourceManager = engine.resourceManager;
|
|
3676
|
+
var _this = this;
|
|
3677
|
+
if (Array.isArray(value)) {
|
|
3678
|
+
return Promise.all(value.map(function(item) {
|
|
3679
|
+
return _this.parseBasicType(item, engine, resourceManager);
|
|
3680
|
+
}));
|
|
3681
|
+
} else if (typeof value === "object" && value != null) {
|
|
3682
|
+
if (this._isClass(value)) {
|
|
3683
|
+
// class object
|
|
3684
|
+
return this.parseClassObject(value, engine, resourceManager);
|
|
3685
|
+
} else if (this._isRef(value)) {
|
|
3686
|
+
// reference object
|
|
3687
|
+
return resourceManager.getResourceByRef(value);
|
|
3688
|
+
} else {
|
|
3689
|
+
// basic type
|
|
3690
|
+
return Promise.resolve(value);
|
|
3691
|
+
}
|
|
3692
|
+
} else {
|
|
3693
|
+
return Promise.resolve(value);
|
|
3694
|
+
}
|
|
3695
|
+
};
|
|
3696
|
+
ReflectionParser.parsePropsAndMethods = function parsePropsAndMethods(instance, item, engine, resourceManager) {
|
|
3697
|
+
if (resourceManager === void 0) resourceManager = engine.resourceManager;
|
|
3698
|
+
var _this = this;
|
|
3699
|
+
var promises = [];
|
|
3700
|
+
if (item.methods) {
|
|
3701
|
+
for(var methodName in item.methods){
|
|
3702
|
+
var methodParams = item.methods[methodName];
|
|
3703
|
+
for(var i = 0, count = methodParams.length; i < count; i++){
|
|
3704
|
+
var params = methodParams[i];
|
|
3705
|
+
var promise = this.parseMethod(instance, methodName, params, engine, resourceManager);
|
|
3706
|
+
promises.push(promise);
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
if (item.props) {
|
|
3711
|
+
var _this1 = this, _loop = function(key) {
|
|
3712
|
+
var value = item.props[key];
|
|
3713
|
+
var promise = _this1.parseBasicType(value, engine).then(function(v) {
|
|
3714
|
+
return instance[key] = v;
|
|
3715
|
+
});
|
|
3716
|
+
promises.push(promise);
|
|
3717
|
+
};
|
|
3718
|
+
for(var key in item.props)_loop(key);
|
|
3719
|
+
}
|
|
3720
|
+
return Promise.all(promises).then(function() {
|
|
3721
|
+
var handle = _this.customParseComponentHandles[instance.constructor.name];
|
|
3722
|
+
if (handle) return handle(instance, item, engine);
|
|
3723
|
+
else return instance;
|
|
3724
|
+
});
|
|
3725
|
+
};
|
|
3726
|
+
ReflectionParser.parseMethod = function parseMethod(instance, methodName, methodParams, engine, resourceManager) {
|
|
3727
|
+
if (resourceManager === void 0) resourceManager = engine.resourceManager;
|
|
3728
|
+
var _this = this;
|
|
3729
|
+
return Promise.all(methodParams.map(function(param) {
|
|
3730
|
+
return _this.parseBasicType(param, engine, resourceManager);
|
|
3731
|
+
})).then(function(result) {
|
|
3732
|
+
var _instance;
|
|
3733
|
+
return (_instance = instance)[methodName].apply(_instance, result);
|
|
3734
|
+
});
|
|
3735
|
+
};
|
|
3736
|
+
ReflectionParser._isClass = function _isClass(value) {
|
|
3737
|
+
return value["class"] != undefined;
|
|
3738
|
+
};
|
|
3739
|
+
ReflectionParser._isRef = function _isRef(value) {
|
|
3740
|
+
return value["refId"] != undefined;
|
|
3741
|
+
};
|
|
3742
|
+
return ReflectionParser;
|
|
3743
|
+
}();
|
|
3744
|
+
(function() {
|
|
3745
|
+
ReflectionParser.customParseComponentHandles = new Map();
|
|
3746
|
+
})();
|
|
3747
|
+
|
|
3748
|
+
var PrefabParser = /*#__PURE__*/ function() {
|
|
3749
|
+
function PrefabParser() {}
|
|
3750
|
+
PrefabParser.parseChildren = function parseChildren(entitiesConfig, entities, parentId) {
|
|
3751
|
+
var children = entitiesConfig.get(parentId).children;
|
|
3752
|
+
if (children && children.length > 0) {
|
|
3753
|
+
var parent = entities.get(parentId);
|
|
3754
|
+
for(var i = 0; i < children.length; i++){
|
|
3755
|
+
var childId = children[i];
|
|
3756
|
+
var entity = entities.get(childId);
|
|
3757
|
+
parent.addChild(entity);
|
|
3758
|
+
this.parseChildren(entitiesConfig, entities, childId);
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
return PrefabParser;
|
|
3763
|
+
}();
|
|
3764
|
+
|
|
3765
|
+
var ComponentMap = {
|
|
3766
|
+
Transform: Transform,
|
|
3767
|
+
Animator: Animator,
|
|
3768
|
+
DirectLight: DirectLight,
|
|
3769
|
+
Camera: Camera,
|
|
3770
|
+
MeshRenderer: MeshRenderer,
|
|
3771
|
+
ParticleRenderer: ParticleRenderer,
|
|
3772
|
+
PointLight: PointLight,
|
|
3773
|
+
SpotLight: SpotLight,
|
|
3774
|
+
Script: Script,
|
|
3775
|
+
SpriteMask: SpriteMask,
|
|
3776
|
+
SpriteRenderer: SpriteRenderer,
|
|
3777
|
+
TextRenderer: TextRenderer
|
|
3778
|
+
};
|
|
3779
|
+
|
|
3780
|
+
var InterpolableValueType;
|
|
3781
|
+
(function(InterpolableValueType) {
|
|
3782
|
+
InterpolableValueType[InterpolableValueType["Float"] = 0] = "Float";
|
|
3783
|
+
InterpolableValueType[InterpolableValueType["FloatArray"] = 1] = "FloatArray";
|
|
3784
|
+
InterpolableValueType[InterpolableValueType["Vector2"] = 2] = "Vector2";
|
|
3785
|
+
InterpolableValueType[InterpolableValueType["Vector3"] = 3] = "Vector3";
|
|
3786
|
+
InterpolableValueType[InterpolableValueType["Vector4"] = 4] = "Vector4";
|
|
3787
|
+
InterpolableValueType[InterpolableValueType["Quaternion"] = 5] = "Quaternion";
|
|
3788
|
+
InterpolableValueType[InterpolableValueType["Color"] = 6] = "Color";
|
|
3789
|
+
InterpolableValueType[InterpolableValueType["Array"] = 7] = "Array";
|
|
3790
|
+
InterpolableValueType[InterpolableValueType["Boolean"] = 8] = "Boolean";
|
|
3791
|
+
})(InterpolableValueType || (InterpolableValueType = {}));
|
|
3792
|
+
var AnimationClipDecoder = /*#__PURE__*/ function() {
|
|
3793
|
+
function AnimationClipDecoder() {}
|
|
3794
|
+
AnimationClipDecoder.decode = function decode(engine, bufferReader) {
|
|
3795
|
+
return new Promise(function(resolve) {
|
|
3796
|
+
var name = bufferReader.nextStr();
|
|
3797
|
+
var clip = new AnimationClip(name);
|
|
3798
|
+
var eventsLen = bufferReader.nextUint16();
|
|
3799
|
+
for(var i = 0; i < eventsLen; ++i){
|
|
3800
|
+
var event = new AnimationEvent();
|
|
3801
|
+
event.time = bufferReader.nextFloat32();
|
|
3802
|
+
event.functionName = bufferReader.nextStr();
|
|
3803
|
+
event.parameter = JSON.parse(bufferReader.nextStr()).val;
|
|
3804
|
+
clip.addEvent(event);
|
|
3805
|
+
}
|
|
3806
|
+
var curveBindingsLen = bufferReader.nextUint16();
|
|
3807
|
+
for(var i1 = 0; i1 < curveBindingsLen; ++i1){
|
|
3808
|
+
var relativePath = bufferReader.nextStr();
|
|
3809
|
+
var componentStr = bufferReader.nextStr();
|
|
3810
|
+
var componentType = ComponentMap[componentStr];
|
|
3811
|
+
var property = bufferReader.nextStr();
|
|
3812
|
+
var curve = void 0;
|
|
3813
|
+
var interpolation = bufferReader.nextUint8();
|
|
3814
|
+
var keysLen = bufferReader.nextUint16();
|
|
3815
|
+
var curveType = bufferReader.nextStr();
|
|
3816
|
+
switch(curveType){
|
|
3817
|
+
case "AnimationFloatCurve":
|
|
3818
|
+
{
|
|
3819
|
+
curve = curve || new AnimationFloatCurve();
|
|
3820
|
+
curve.interpolation = interpolation;
|
|
3821
|
+
for(var j = 0; j < keysLen; ++j){
|
|
3822
|
+
var keyframe = new Keyframe();
|
|
3823
|
+
keyframe.time = bufferReader.nextFloat32();
|
|
3824
|
+
keyframe.value = bufferReader.nextFloat32();
|
|
3825
|
+
keyframe.inTangent = bufferReader.nextFloat32();
|
|
3826
|
+
keyframe.outTangent = bufferReader.nextFloat32();
|
|
3827
|
+
curve.addKey(keyframe);
|
|
3828
|
+
}
|
|
3829
|
+
break;
|
|
3830
|
+
}
|
|
3831
|
+
case "AnimationArrayCurve":
|
|
3832
|
+
{
|
|
3833
|
+
curve = curve || new AnimationArrayCurve();
|
|
3834
|
+
curve.interpolation = interpolation;
|
|
3835
|
+
for(var j1 = 0; j1 < keysLen; ++j1){
|
|
3836
|
+
var keyframe1 = new Keyframe();
|
|
3837
|
+
keyframe1.time = bufferReader.nextFloat32();
|
|
3838
|
+
var len = bufferReader.nextUint16();
|
|
3839
|
+
keyframe1.value = Array.from(bufferReader.nextFloat32Array(len));
|
|
3840
|
+
keyframe1.inTangent = Array.from(bufferReader.nextFloat32Array(len));
|
|
3841
|
+
keyframe1.outTangent = Array.from(bufferReader.nextFloat32Array(len));
|
|
3842
|
+
curve.addKey(keyframe1);
|
|
3843
|
+
}
|
|
3844
|
+
break;
|
|
3845
|
+
}
|
|
3846
|
+
case "AnimationFloatArrayCurve":
|
|
3847
|
+
{
|
|
3848
|
+
curve = curve || new AnimationFloatArrayCurve();
|
|
3849
|
+
curve.interpolation = interpolation;
|
|
3850
|
+
for(var j2 = 0; j2 < keysLen; ++j2){
|
|
3851
|
+
var keyframe2 = new Keyframe();
|
|
3852
|
+
keyframe2.time = bufferReader.nextFloat32();
|
|
3853
|
+
var len1 = bufferReader.nextUint16();
|
|
3854
|
+
keyframe2.value = bufferReader.nextFloat32Array(len1);
|
|
3855
|
+
keyframe2.inTangent = Array.from(bufferReader.nextFloat32Array(len1));
|
|
3856
|
+
keyframe2.outTangent = Array.from(bufferReader.nextFloat32Array(len1));
|
|
3857
|
+
curve.addKey(keyframe2);
|
|
3858
|
+
}
|
|
3859
|
+
break;
|
|
3860
|
+
}
|
|
3861
|
+
case "AnimationVector2Curve":
|
|
3862
|
+
{
|
|
3863
|
+
curve = curve || new AnimationVector2Curve();
|
|
3864
|
+
curve.interpolation = interpolation;
|
|
3865
|
+
for(var j3 = 0; j3 < keysLen; ++j3){
|
|
3866
|
+
var keyframe3 = new Keyframe();
|
|
3867
|
+
keyframe3.time = bufferReader.nextFloat32();
|
|
3868
|
+
keyframe3.value = new Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3869
|
+
keyframe3.inTangent = new Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3870
|
+
keyframe3.outTangent = new Vector2(bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3871
|
+
curve.addKey(keyframe3);
|
|
3872
|
+
}
|
|
3873
|
+
break;
|
|
3874
|
+
}
|
|
3875
|
+
case "AnimationVector3Curve":
|
|
3876
|
+
{
|
|
3877
|
+
curve = curve || new AnimationVector3Curve();
|
|
3878
|
+
curve.interpolation = interpolation;
|
|
3879
|
+
for(var j4 = 0; j4 < keysLen; ++j4){
|
|
3880
|
+
var keyframe4 = new Keyframe();
|
|
3881
|
+
keyframe4.time = bufferReader.nextFloat32();
|
|
3882
|
+
keyframe4.value = new Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3883
|
+
keyframe4.inTangent = new Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3884
|
+
keyframe4.outTangent = new Vector3(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3885
|
+
curve.addKey(keyframe4);
|
|
3886
|
+
}
|
|
3887
|
+
break;
|
|
3888
|
+
}
|
|
3889
|
+
case "AnimationVector4Curve":
|
|
3890
|
+
{
|
|
3891
|
+
curve = curve || new AnimationVector4Curve();
|
|
3892
|
+
curve.interpolation = interpolation;
|
|
3893
|
+
var keyframe5 = new Keyframe();
|
|
3894
|
+
keyframe5.time = bufferReader.nextFloat32();
|
|
3895
|
+
keyframe5.value = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3896
|
+
keyframe5.inTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3897
|
+
keyframe5.outTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3898
|
+
curve.addKey(keyframe5);
|
|
3899
|
+
break;
|
|
3900
|
+
}
|
|
3901
|
+
case "AnimationColorCurve":
|
|
3902
|
+
{
|
|
3903
|
+
curve = curve || new AnimationColorCurve();
|
|
3904
|
+
curve.interpolation = interpolation;
|
|
3905
|
+
for(var j5 = 0; j5 < keysLen; ++j5){
|
|
3906
|
+
var keyframe6 = new Keyframe();
|
|
3907
|
+
keyframe6.time = bufferReader.nextFloat32();
|
|
3908
|
+
keyframe6.value = new Color(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3909
|
+
keyframe6.inTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3910
|
+
keyframe6.outTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3911
|
+
curve.addKey(keyframe6);
|
|
3912
|
+
}
|
|
3913
|
+
break;
|
|
3914
|
+
}
|
|
3915
|
+
case "AnimationQuaternionCurve":
|
|
3916
|
+
{
|
|
3917
|
+
curve = curve || new AnimationQuaternionCurve();
|
|
3918
|
+
curve.interpolation = interpolation;
|
|
3919
|
+
for(var j6 = 0; j6 < keysLen; ++j6){
|
|
3920
|
+
var keyframe7 = new Keyframe();
|
|
3921
|
+
keyframe7.time = bufferReader.nextFloat32();
|
|
3922
|
+
keyframe7.value = new Quaternion(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3923
|
+
keyframe7.inTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3924
|
+
keyframe7.outTangent = new Vector4(bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32(), bufferReader.nextFloat32());
|
|
3925
|
+
curve.addKey(keyframe7);
|
|
3926
|
+
}
|
|
3927
|
+
break;
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
clip.addCurveBinding(relativePath, componentType, property, curve);
|
|
3931
|
+
}
|
|
3932
|
+
resolve(clip);
|
|
3933
|
+
});
|
|
3934
|
+
};
|
|
3935
|
+
return AnimationClipDecoder;
|
|
3936
|
+
}();
|
|
3937
|
+
AnimationClipDecoder = __decorate([
|
|
3938
|
+
decoder("AnimationClip")
|
|
3939
|
+
], AnimationClipDecoder);
|
|
3940
|
+
|
|
3941
|
+
var SceneParserContext = /*#__PURE__*/ function() {
|
|
3942
|
+
function SceneParserContext(originalData, scene) {
|
|
3943
|
+
this.originalData = originalData;
|
|
3944
|
+
this.scene = scene;
|
|
3945
|
+
this.entityMap = new Map();
|
|
3946
|
+
this.components = new Map();
|
|
3947
|
+
this.assets = new Map();
|
|
3948
|
+
this.entityConfigMap = new Map();
|
|
3949
|
+
this.rootIds = [];
|
|
3950
|
+
}
|
|
3951
|
+
var _proto = SceneParserContext.prototype;
|
|
3952
|
+
_proto.destroy = function destroy() {
|
|
3953
|
+
this.entityMap.clear();
|
|
3954
|
+
this.components.clear();
|
|
3955
|
+
this.assets.clear();
|
|
3956
|
+
this.entityConfigMap.clear();
|
|
3957
|
+
this.rootIds.length = 0;
|
|
3958
|
+
};
|
|
3959
|
+
return SceneParserContext;
|
|
3960
|
+
}();
|
|
3961
|
+
|
|
3962
|
+
/** @Internal */ var SceneParser = /*#__PURE__*/ function() {
|
|
3963
|
+
function SceneParser(context) {
|
|
3964
|
+
var _this = this;
|
|
3965
|
+
this.context = context;
|
|
3966
|
+
this._engine = this.context.scene.engine;
|
|
3967
|
+
this._organizeEntities = this._organizeEntities.bind(this);
|
|
3968
|
+
this._parseComponents = this._parseComponents.bind(this);
|
|
3969
|
+
this._clearAndResolveScene = this._clearAndResolveScene.bind(this);
|
|
3970
|
+
this.promise = new Promise(function(resolve, reject) {
|
|
3971
|
+
_this._reject = reject;
|
|
3972
|
+
_this._resolve = resolve;
|
|
3973
|
+
});
|
|
3974
|
+
}
|
|
3975
|
+
var _proto = SceneParser.prototype;
|
|
3976
|
+
/** start parse the scene */ _proto.start = function start() {
|
|
3977
|
+
this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._clearAndResolveScene).then(this._resolve).catch(this._reject);
|
|
3978
|
+
};
|
|
3979
|
+
_proto._parseEntities = function _parseEntities() {
|
|
3980
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
3981
|
+
var entityConfigMap = this.context.entityConfigMap;
|
|
3982
|
+
var entitiesMap = this.context.entityMap;
|
|
3983
|
+
var rootIds = this.context.rootIds;
|
|
3984
|
+
var engine = this._engine;
|
|
3985
|
+
var promises = entitiesConfig.map(function(entityConfig) {
|
|
3986
|
+
entityConfigMap.set(entityConfig.id, entityConfig);
|
|
3987
|
+
// record root entities
|
|
3988
|
+
if (!entityConfig.parent) rootIds.push(entityConfig.id);
|
|
3989
|
+
return ReflectionParser.parseEntity(entityConfig, engine);
|
|
3990
|
+
});
|
|
3991
|
+
return Promise.all(promises).then(function(entities) {
|
|
3992
|
+
for(var i = 0, l = entities.length; i < l; i++){
|
|
3993
|
+
entitiesMap.set(entitiesConfig[i].id, entities[i]);
|
|
3994
|
+
}
|
|
3995
|
+
return entities;
|
|
3996
|
+
});
|
|
3997
|
+
};
|
|
3998
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
3999
|
+
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
|
|
4000
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
|
|
4001
|
+
var rootId = _step.value;
|
|
4002
|
+
PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
|
|
4003
|
+
}
|
|
4004
|
+
var rootEntities = rootIds.map(function(id) {
|
|
4005
|
+
return entityMap.get(id);
|
|
4006
|
+
});
|
|
4007
|
+
for(var i = 0; i < rootEntities.length; i++){
|
|
4008
|
+
scene.addRootEntity(rootEntities[i]);
|
|
4009
|
+
}
|
|
4010
|
+
};
|
|
4011
|
+
_proto._parseComponents = function _parseComponents() {
|
|
4012
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
4013
|
+
var entityMap = this.context.entityMap;
|
|
4014
|
+
var promises = [];
|
|
4015
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
4016
|
+
var entityConfig = entitiesConfig[i];
|
|
4017
|
+
var entity = entityMap.get(entityConfig.id);
|
|
4018
|
+
for(var i1 = 0; i1 < entityConfig.components.length; i1++){
|
|
4019
|
+
var componentConfig = entityConfig.components[i1];
|
|
4020
|
+
var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
|
|
4021
|
+
var component = void 0;
|
|
4022
|
+
// TODO: remove hack code when support additional edit
|
|
4023
|
+
if (key === "Animator") {
|
|
4024
|
+
component = entity.getComponent(Loader.getClass(key));
|
|
4025
|
+
}
|
|
4026
|
+
component = component || entity.addComponent(Loader.getClass(key));
|
|
4027
|
+
var promise = ReflectionParser.parsePropsAndMethods(component, componentConfig, entity.engine);
|
|
4028
|
+
promises.push(promise);
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
return Promise.all(promises);
|
|
4032
|
+
};
|
|
4033
|
+
_proto._clearAndResolveScene = function _clearAndResolveScene() {
|
|
4034
|
+
var scene = this.context.scene;
|
|
4035
|
+
this.context.destroy();
|
|
4036
|
+
return scene;
|
|
4037
|
+
};
|
|
4038
|
+
/**
|
|
4039
|
+
* Parse scene data.
|
|
4040
|
+
* @param engine - the engine of the parser context
|
|
4041
|
+
* @param sceneData - scene data which is exported by editor
|
|
4042
|
+
* @returns a promise of scene
|
|
4043
|
+
*/ SceneParser.parse = function parse(engine, sceneData) {
|
|
4044
|
+
var scene = new Scene(engine);
|
|
4045
|
+
var context = new SceneParserContext(sceneData, scene);
|
|
4046
|
+
var parser = new SceneParser(context);
|
|
4047
|
+
parser.start();
|
|
4048
|
+
return parser.promise;
|
|
4049
|
+
};
|
|
4050
|
+
return SceneParser;
|
|
4051
|
+
}();
|
|
4052
|
+
|
|
4053
|
+
var MeshLoader$1 = /*#__PURE__*/ function(Loader) {
|
|
4054
|
+
_inherits(MeshLoader, Loader);
|
|
4055
|
+
function MeshLoader() {
|
|
4056
|
+
return Loader.apply(this, arguments);
|
|
4057
|
+
}
|
|
4058
|
+
var _proto = MeshLoader.prototype;
|
|
4059
|
+
_proto.load = function load(item, resourceManager) {
|
|
4060
|
+
var _this = this;
|
|
4061
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4062
|
+
_this.request(item.url, {
|
|
4063
|
+
type: "arraybuffer"
|
|
4064
|
+
}).then(function(data) {
|
|
4065
|
+
decode(data, resourceManager.engine).then(function(mesh) {
|
|
4066
|
+
resolve(mesh);
|
|
4067
|
+
});
|
|
4068
|
+
});
|
|
4069
|
+
});
|
|
4070
|
+
};
|
|
4071
|
+
return MeshLoader;
|
|
4072
|
+
}(Loader);
|
|
4073
|
+
MeshLoader$1 = __decorate([
|
|
4074
|
+
resourceLoader("Mesh", [
|
|
4075
|
+
"prefab"
|
|
4076
|
+
], true)
|
|
4077
|
+
], MeshLoader$1);
|
|
4078
|
+
|
|
4079
|
+
var EditorTextureLoader = /*#__PURE__*/ function(Loader) {
|
|
4080
|
+
_inherits(EditorTextureLoader, Loader);
|
|
4081
|
+
function EditorTextureLoader() {
|
|
4082
|
+
return Loader.apply(this, arguments);
|
|
4083
|
+
}
|
|
4084
|
+
var _proto = EditorTextureLoader.prototype;
|
|
4085
|
+
_proto.load = function load(item, resourceManager) {
|
|
4086
|
+
var _this = this;
|
|
4087
|
+
return new AssetPromise(function(resolve) {
|
|
4088
|
+
_this.request(item.url, {
|
|
4089
|
+
type: "arraybuffer"
|
|
4090
|
+
}).then(function(data) {
|
|
4091
|
+
decode(data, resourceManager.engine).then(function(texture) {
|
|
4092
|
+
resolve(texture);
|
|
4093
|
+
});
|
|
4094
|
+
});
|
|
4095
|
+
});
|
|
4096
|
+
};
|
|
4097
|
+
return EditorTextureLoader;
|
|
4098
|
+
}(Loader);
|
|
4099
|
+
EditorTextureLoader = __decorate([
|
|
4100
|
+
resourceLoader("EditorTexture2D", [
|
|
4101
|
+
"prefab"
|
|
4102
|
+
], true)
|
|
4103
|
+
], EditorTextureLoader);
|
|
4104
|
+
|
|
4105
|
+
/**
|
|
4106
|
+
* Decode engine binary resource.
|
|
4107
|
+
* @param arrayBuffer - array buffer of decode binary file
|
|
4108
|
+
* @param engine - engine
|
|
4109
|
+
* @returns
|
|
4110
|
+
*/ function decode(arrayBuffer, engine) {
|
|
4111
|
+
var header = FileHeader.decode(arrayBuffer);
|
|
4112
|
+
var bufferReader = new BufferReader(arrayBuffer, header.headerLength, header.dataLength);
|
|
4113
|
+
return decoderMap[header.type].decode(engine, bufferReader).then(function(object) {
|
|
4114
|
+
object.name = header.name;
|
|
4115
|
+
return object;
|
|
4116
|
+
});
|
|
4117
|
+
}
|
|
4118
|
+
|
|
4119
|
+
var MeshLoader = /*#__PURE__*/ function(Loader) {
|
|
4120
|
+
_inherits(MeshLoader, Loader);
|
|
4121
|
+
function MeshLoader() {
|
|
4122
|
+
return Loader.apply(this, arguments);
|
|
4123
|
+
}
|
|
4124
|
+
var _proto = MeshLoader.prototype;
|
|
4125
|
+
_proto.load = function load(item, resourceManager) {
|
|
4126
|
+
var _this = this;
|
|
4127
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4128
|
+
_this.request(item.url, _extends({}, item, {
|
|
4129
|
+
type: "arraybuffer"
|
|
4130
|
+
})).then(function(data) {
|
|
4131
|
+
return decode(data, resourceManager.engine);
|
|
4132
|
+
}).then(function(mesh) {
|
|
4133
|
+
resolve(mesh);
|
|
4134
|
+
}).catch(reject);
|
|
4135
|
+
});
|
|
4136
|
+
};
|
|
4137
|
+
return MeshLoader;
|
|
4138
|
+
}(Loader);
|
|
4139
|
+
MeshLoader = __decorate([
|
|
4140
|
+
resourceLoader(AssetType.Mesh, [
|
|
4141
|
+
"mesh"
|
|
4142
|
+
])
|
|
4143
|
+
], MeshLoader);
|
|
4144
|
+
|
|
4145
|
+
var SourceFontLoader = /*#__PURE__*/ function(Loader) {
|
|
4146
|
+
_inherits(SourceFontLoader, Loader);
|
|
4147
|
+
function SourceFontLoader() {
|
|
4148
|
+
return Loader.apply(this, arguments);
|
|
4149
|
+
}
|
|
4150
|
+
var _proto = SourceFontLoader.prototype;
|
|
4151
|
+
_proto.load = function load(item, resourceManager) {
|
|
4152
|
+
var _this = this;
|
|
4153
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4154
|
+
var url = item.url;
|
|
4155
|
+
_this._registerFont(url, url).then(function() {
|
|
4156
|
+
var font = new Font(resourceManager.engine, url);
|
|
4157
|
+
resolve(font);
|
|
4158
|
+
}).catch(function(e) {
|
|
4159
|
+
reject("load font " + url + " fail");
|
|
4160
|
+
});
|
|
4161
|
+
});
|
|
4162
|
+
};
|
|
4163
|
+
_proto._registerFont = function _registerFont(fontName, fontUrl) {
|
|
4164
|
+
return _async_to_generator(function() {
|
|
4165
|
+
var fontFace;
|
|
4166
|
+
return __generator(this, function(_state) {
|
|
4167
|
+
switch(_state.label){
|
|
4168
|
+
case 0:
|
|
4169
|
+
fontFace = new FontFace(fontName, "url(" + fontUrl + ")");
|
|
4170
|
+
return [
|
|
4171
|
+
4,
|
|
4172
|
+
fontFace.load()
|
|
4173
|
+
];
|
|
4174
|
+
case 1:
|
|
4175
|
+
_state.sent();
|
|
4176
|
+
document.fonts.add(fontFace);
|
|
4177
|
+
return [
|
|
4178
|
+
2
|
|
4179
|
+
];
|
|
4180
|
+
}
|
|
4181
|
+
});
|
|
4182
|
+
})();
|
|
4183
|
+
};
|
|
4184
|
+
return SourceFontLoader;
|
|
4185
|
+
}(Loader);
|
|
4186
|
+
SourceFontLoader = __decorate([
|
|
4187
|
+
resourceLoader(AssetType.SourceFont, [
|
|
4188
|
+
"ttf",
|
|
4189
|
+
"otf",
|
|
4190
|
+
"woff"
|
|
4191
|
+
], false)
|
|
4192
|
+
], SourceFontLoader);
|
|
4193
|
+
|
|
4194
|
+
var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
|
|
4195
|
+
_inherits(SpriteAtlasLoader, Loader);
|
|
4196
|
+
function SpriteAtlasLoader() {
|
|
4197
|
+
var _this;
|
|
4198
|
+
_this = Loader.apply(this, arguments) || this;
|
|
4199
|
+
_this._tempRect = new Rect();
|
|
4200
|
+
_this._tempVec2 = new Vector2();
|
|
4201
|
+
_this._tempVec4 = new Vector4();
|
|
4202
|
+
return _this;
|
|
4203
|
+
}
|
|
4204
|
+
var _proto = SpriteAtlasLoader.prototype;
|
|
4205
|
+
_proto.load = function load(item, resourceManager) {
|
|
4206
|
+
var _this = this;
|
|
4207
|
+
return new AssetPromise(function(resolve, reject, _, onCancel) {
|
|
4208
|
+
var chainPromises = [];
|
|
4209
|
+
onCancel(function() {
|
|
4210
|
+
for(var i = 0; i < chainPromises.length; i++){
|
|
4211
|
+
chainPromises[i].cancel();
|
|
4212
|
+
}
|
|
4213
|
+
});
|
|
4214
|
+
var configPromise = _this.request(item.url, _extends({}, item, {
|
|
4215
|
+
type: "json"
|
|
4216
|
+
}));
|
|
4217
|
+
chainPromises.push(configPromise);
|
|
4218
|
+
configPromise.then(function(atlasData) {
|
|
4219
|
+
var _loop = function(i) {
|
|
4220
|
+
var atlasItem = atlasItems[i];
|
|
4221
|
+
if (atlasItem.img) {
|
|
4222
|
+
chainPromises.push(resourceManager.load({
|
|
4223
|
+
url: atlasItem.img,
|
|
4224
|
+
type: AssetType.Texture2D,
|
|
4225
|
+
params: {
|
|
4226
|
+
format: format,
|
|
4227
|
+
mipmap: mipmap
|
|
4228
|
+
}
|
|
4229
|
+
}).then(function(texture) {
|
|
4230
|
+
anisoLevel && (texture.anisoLevel = anisoLevel);
|
|
4231
|
+
filterMode !== undefined && (texture.filterMode = filterMode);
|
|
4232
|
+
wrapModeU !== undefined && (texture.wrapModeU = wrapModeU);
|
|
4233
|
+
wrapModeV !== undefined && (texture.wrapModeV = wrapModeV);
|
|
4234
|
+
for(var i = 0; i < atlasItem.sprites.length; i++){
|
|
4235
|
+
// @ts-ignore
|
|
4236
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i], texture));
|
|
4237
|
+
}
|
|
4238
|
+
}).catch(reject));
|
|
4239
|
+
} else {
|
|
4240
|
+
for(var i1 = 0; i1 < atlasItem.sprites.length; i1++){
|
|
4241
|
+
// @ts-ignore
|
|
4242
|
+
spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i1]));
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
};
|
|
4246
|
+
var atlasItems = atlasData.atlasItems, mipmap = atlasData.mipmap, anisoLevel = atlasData.anisoLevel, filterMode = atlasData.filterMode, wrapModeU = atlasData.wrapModeU, wrapModeV = atlasData.wrapModeV, format = atlasData.format;
|
|
4247
|
+
var atlasItemsLen = atlasItems ? atlasItems.length : 0;
|
|
4248
|
+
var engine = resourceManager.engine;
|
|
4249
|
+
var spriteAtlas = new SpriteAtlas(engine);
|
|
4250
|
+
if (atlasItemsLen < 0) {
|
|
4251
|
+
resolve(spriteAtlas);
|
|
4252
|
+
return;
|
|
4253
|
+
}
|
|
4254
|
+
chainPromises.length = 0;
|
|
4255
|
+
for(var i = 0; i < atlasItems.length; i++)_loop(i);
|
|
4256
|
+
AssetPromise.all(chainPromises).then(function() {
|
|
4257
|
+
resolve(spriteAtlas);
|
|
4258
|
+
}).catch(reject);
|
|
4259
|
+
}).catch(reject);
|
|
4260
|
+
});
|
|
4261
|
+
};
|
|
4262
|
+
_proto._makeSprite = function _makeSprite(engine, config, texture) {
|
|
4263
|
+
// Generate a SpriteAtlas object.
|
|
4264
|
+
var region = config.region, atlasRegionOffset = config.atlasRegionOffset, atlasRegion = config.atlasRegion, pivot = config.pivot, border = config.border;
|
|
4265
|
+
var sprite = new Sprite(engine, texture, region ? this._tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? this._tempVec2.set(pivot.x, pivot.y) : undefined, border ? this._tempVec4.set(border.x, border.y, border.z, border.w) : undefined, config.name);
|
|
4266
|
+
if (texture) {
|
|
4267
|
+
var invW = 1 / texture.width;
|
|
4268
|
+
var invH = 1 / texture.height;
|
|
4269
|
+
sprite.atlasRegion.set(atlasRegion.x * invW, atlasRegion.y * invH, atlasRegion.w * invW, atlasRegion.h * invH);
|
|
4270
|
+
if (atlasRegionOffset) {
|
|
4271
|
+
var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
|
|
4272
|
+
sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
|
|
4273
|
+
}
|
|
4274
|
+
config.atlasRotated && (sprite.atlasRotated = true);
|
|
4275
|
+
}
|
|
4276
|
+
return sprite;
|
|
4277
|
+
};
|
|
4278
|
+
return SpriteAtlasLoader;
|
|
4279
|
+
}(Loader);
|
|
4280
|
+
SpriteAtlasLoader = __decorate([
|
|
4281
|
+
resourceLoader(AssetType.SpriteAtlas, [
|
|
4282
|
+
"atlas"
|
|
4283
|
+
], false)
|
|
4284
|
+
], SpriteAtlasLoader);
|
|
4285
|
+
|
|
4286
|
+
var SpriteLoader = /*#__PURE__*/ function(Loader) {
|
|
4287
|
+
_inherits(SpriteLoader, Loader);
|
|
4288
|
+
function SpriteLoader() {
|
|
4289
|
+
return Loader.apply(this, arguments);
|
|
4290
|
+
}
|
|
4291
|
+
var _proto = SpriteLoader.prototype;
|
|
4292
|
+
_proto.load = function load(item, resourceManager) {
|
|
4293
|
+
var _this = this;
|
|
4294
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4295
|
+
_this.request(item.url, _extends({}, item, {
|
|
4296
|
+
type: "json"
|
|
4297
|
+
})).then(function(data) {
|
|
4298
|
+
if (data.belongToAtlas) {
|
|
4299
|
+
resourceManager// @ts-ignore
|
|
4300
|
+
.getResourceByRef(data.belongToAtlas).then(function(atlas) {
|
|
4301
|
+
resolve(atlas.getSprite(data.fullPath));
|
|
4302
|
+
}).catch(reject);
|
|
4303
|
+
} else if (data.texture) {
|
|
4304
|
+
resourceManager// @ts-ignore
|
|
4305
|
+
.getResourceByRef(data.texture).then(function(texture) {
|
|
4306
|
+
resolve(new Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border));
|
|
4307
|
+
}).catch(reject);
|
|
4308
|
+
} else {
|
|
4309
|
+
resolve(new Sprite(resourceManager.engine, null, data.region, data.pivot, data.border));
|
|
4310
|
+
}
|
|
4311
|
+
}).catch(reject);
|
|
4312
|
+
});
|
|
4313
|
+
};
|
|
4314
|
+
return SpriteLoader;
|
|
4315
|
+
}(Loader);
|
|
4316
|
+
SpriteLoader = __decorate([
|
|
4317
|
+
resourceLoader(AssetType.Sprite, [
|
|
4318
|
+
"sprite"
|
|
4319
|
+
], false)
|
|
4320
|
+
], SpriteLoader);
|
|
4321
|
+
|
|
4322
|
+
var Texture2DLoader = /*#__PURE__*/ function(Loader) {
|
|
4323
|
+
_inherits(Texture2DLoader, Loader);
|
|
4324
|
+
function Texture2DLoader() {
|
|
4325
|
+
return Loader.apply(this, arguments);
|
|
4326
|
+
}
|
|
4327
|
+
var _proto = Texture2DLoader.prototype;
|
|
4328
|
+
_proto.load = function load(item, resourceManager) {
|
|
4329
|
+
var _this = this;
|
|
4330
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4331
|
+
_this.request(item.url, _extends({}, item, {
|
|
4332
|
+
type: "image"
|
|
4333
|
+
})).then(function(image) {
|
|
4334
|
+
var _item_params;
|
|
4335
|
+
var params = (_item_params = item.params) != null ? _item_params : {};
|
|
4336
|
+
var texture = new Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
|
|
4337
|
+
/** @ts-ignore */ if (!texture._platformTexture) return;
|
|
4338
|
+
texture.setImageSource(image);
|
|
4339
|
+
texture.generateMipmaps();
|
|
4340
|
+
if (item.url.indexOf("data:") !== 0) {
|
|
4341
|
+
var splitPath = item.url.split("/");
|
|
4342
|
+
texture.name = splitPath[splitPath.length - 1];
|
|
4343
|
+
}
|
|
4344
|
+
resolve(texture);
|
|
4345
|
+
}).catch(function(e) {
|
|
4346
|
+
reject(e);
|
|
4347
|
+
});
|
|
4348
|
+
});
|
|
4349
|
+
};
|
|
4350
|
+
return Texture2DLoader;
|
|
4351
|
+
}(Loader);
|
|
4352
|
+
Texture2DLoader = __decorate([
|
|
4353
|
+
resourceLoader(AssetType.Texture2D, [
|
|
4354
|
+
"png",
|
|
4355
|
+
"jpg",
|
|
4356
|
+
"webp",
|
|
4357
|
+
"jpeg"
|
|
4358
|
+
])
|
|
4359
|
+
], Texture2DLoader);
|
|
4360
|
+
|
|
4361
|
+
var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
|
|
4362
|
+
_inherits(TextureCubeLoader, Loader);
|
|
4363
|
+
function TextureCubeLoader() {
|
|
4364
|
+
return Loader.apply(this, arguments);
|
|
4365
|
+
}
|
|
4366
|
+
var _proto = TextureCubeLoader.prototype;
|
|
4367
|
+
_proto.load = function load(item, resourceManager) {
|
|
4368
|
+
var _this = this;
|
|
4369
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4370
|
+
Promise.all(item.urls.map(function(url) {
|
|
4371
|
+
return _this.request(url, _extends({}, item, {
|
|
4372
|
+
type: "image"
|
|
4373
|
+
}));
|
|
4374
|
+
})).then(function(images) {
|
|
4375
|
+
var _images_ = images[0], width = _images_.width, height = _images_.height;
|
|
4376
|
+
if (width !== height) {
|
|
4377
|
+
console.error("The cube texture must have the same width and height");
|
|
4378
|
+
return;
|
|
4379
|
+
}
|
|
4380
|
+
var tex = new TextureCube(resourceManager.engine, width);
|
|
4381
|
+
/** @ts-ignore */ if (!tex._platformTexture) return;
|
|
4382
|
+
for(var faceIndex = 0; faceIndex < 6; faceIndex++){
|
|
4383
|
+
tex.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
|
|
4384
|
+
}
|
|
4385
|
+
tex.generateMipmaps();
|
|
4386
|
+
resolve(tex);
|
|
4387
|
+
}).catch(function(e) {
|
|
4388
|
+
reject(e);
|
|
4389
|
+
});
|
|
4390
|
+
});
|
|
4391
|
+
};
|
|
4392
|
+
return TextureCubeLoader;
|
|
4393
|
+
}(Loader);
|
|
4394
|
+
TextureCubeLoader = __decorate([
|
|
4395
|
+
resourceLoader(AssetType.TextureCube, [
|
|
4396
|
+
""
|
|
4397
|
+
])
|
|
4398
|
+
], TextureCubeLoader);
|
|
4399
|
+
|
|
4400
|
+
var SceneLoader = /*#__PURE__*/ function(Loader) {
|
|
4401
|
+
_inherits(SceneLoader, Loader);
|
|
4402
|
+
function SceneLoader() {
|
|
4403
|
+
return Loader.apply(this, arguments);
|
|
4404
|
+
}
|
|
4405
|
+
var _proto = SceneLoader.prototype;
|
|
4406
|
+
_proto.load = function load(item, resourceManager) {
|
|
4407
|
+
var _this = this;
|
|
4408
|
+
var engine = resourceManager.engine;
|
|
4409
|
+
return new AssetPromise(function(resolve, reject) {
|
|
4410
|
+
_this.request(item.url, {
|
|
4411
|
+
type: "json"
|
|
4412
|
+
}).then(function(data) {
|
|
4413
|
+
// @ts-ignore
|
|
4414
|
+
engine.resourceManager.initVirtualResources(data.files);
|
|
4415
|
+
return SceneParser.parse(engine, data).then(function(scene) {
|
|
4416
|
+
// parse ambient light
|
|
4417
|
+
var ambient = data.scene.ambient;
|
|
4418
|
+
var ambientLightPromise = Promise.resolve();
|
|
4419
|
+
if (ambient.ambientLight) {
|
|
4420
|
+
ambientLightPromise = resourceManager// @ts-ignore
|
|
4421
|
+
.getResourceByRef(data.scene.ambient.ambientLight).then(function(light) {
|
|
4422
|
+
scene.ambientLight = light;
|
|
4423
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4424
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4425
|
+
});
|
|
4426
|
+
} else {
|
|
4427
|
+
scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
|
|
4428
|
+
scene.ambientLight.specularIntensity = ambient.specularIntensity;
|
|
4429
|
+
scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
|
|
4430
|
+
}
|
|
4431
|
+
var background = data.scene.background;
|
|
4432
|
+
scene.background.mode = background.mode;
|
|
4433
|
+
var backgroundPromise = Promise.resolve();
|
|
4434
|
+
switch(scene.background.mode){
|
|
4435
|
+
case BackgroundMode.SolidColor:
|
|
4436
|
+
scene.background.solidColor.copyFrom(background.color);
|
|
4437
|
+
break;
|
|
4438
|
+
case BackgroundMode.Sky:
|
|
4439
|
+
if (background.sky) {
|
|
4440
|
+
// @ts-ignore
|
|
4441
|
+
backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
|
|
4442
|
+
var sky = scene.background.sky;
|
|
4443
|
+
var skyMaterial = new SkyBoxMaterial(engine);
|
|
4444
|
+
skyMaterial.textureCubeMap = light.specularTexture;
|
|
4445
|
+
skyMaterial.textureDecodeRGBM = true;
|
|
4446
|
+
sky.material = skyMaterial;
|
|
4447
|
+
sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
|
|
4448
|
+
});
|
|
4449
|
+
}
|
|
4450
|
+
break;
|
|
4451
|
+
case BackgroundMode.Texture:
|
|
4452
|
+
if (background.texture) {
|
|
4453
|
+
// @ts-ignore
|
|
4454
|
+
backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
|
|
4455
|
+
scene.background.texture = texture;
|
|
4456
|
+
});
|
|
4457
|
+
}
|
|
4458
|
+
break;
|
|
4459
|
+
}
|
|
4460
|
+
// parse shadow
|
|
4461
|
+
var shadow = data.scene.shadow;
|
|
4462
|
+
if (shadow) {
|
|
4463
|
+
if (shadow.castShadows != undefined) scene.castShadows = shadow.castShadows;
|
|
4464
|
+
if (shadow.shadowResolution != undefined) scene.shadowResolution = shadow.shadowResolution;
|
|
4465
|
+
if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
|
|
4466
|
+
if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
|
|
4467
|
+
}
|
|
4468
|
+
return Promise.all([
|
|
4469
|
+
ambientLightPromise,
|
|
4470
|
+
backgroundPromise
|
|
4471
|
+
]).then(function() {
|
|
4472
|
+
resolve(scene);
|
|
4473
|
+
});
|
|
4474
|
+
});
|
|
4475
|
+
}).catch(reject);
|
|
4476
|
+
});
|
|
4477
|
+
};
|
|
4478
|
+
return SceneLoader;
|
|
4479
|
+
}(Loader);
|
|
4480
|
+
SceneLoader = __decorate([
|
|
4481
|
+
resourceLoader(AssetType.Scene, [
|
|
4482
|
+
"prefab"
|
|
4483
|
+
], true)
|
|
4484
|
+
], SceneLoader);
|
|
4485
|
+
ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _async_to_generator(function(instance, item, engine) {
|
|
4486
|
+
var props;
|
|
4487
|
+
return __generator(this, function(_state) {
|
|
4488
|
+
props = item.props;
|
|
4489
|
+
if (!props.font) {
|
|
4490
|
+
// @ts-ignore
|
|
4491
|
+
instance.font = Font.createFromOS(engine, props.fontFamily || "Arial");
|
|
4492
|
+
}
|
|
4493
|
+
return [
|
|
4494
|
+
2,
|
|
4495
|
+
instance
|
|
4496
|
+
];
|
|
4497
|
+
});
|
|
4498
|
+
}));
|
|
4499
|
+
|
|
4500
|
+
export { AnimationClipDecoder, ComponentMap, EditorTextureLoader, GLTFResource, InterpolableValueType, MeshDecoder, MeshLoader$1 as MeshLoader, PrefabParser, ReflectionParser, SceneParser, Texture2DDecoder, decode, parseSingleKTX };
|
|
4501
|
+
//# sourceMappingURL=module.js.map
|