@galacean/engine-loader 2.0.0-alpha.56 → 2.0.0-alpha.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1198,6 +1198,61 @@ HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
1198
1198
  HDRDecoder._floatView = new Float32Array(1);
1199
1199
  HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
1200
1200
 
1201
+ function _instanceof(left, right) {
1202
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1203
+ return !!right[Symbol.hasInstance](left);
1204
+ } else return left instanceof right;
1205
+ }
1206
+
1207
+ /**
1208
+ * Decodes encoded image bytes (PNG, JPEG, WebP, ...) into an image element.
1209
+ *
1210
+ * The blob handed to the image carries the MIME type detected from the bytes: browsers sniff an untyped
1211
+ * blob, but some platforms (for example mini-game runtimes) only decode images whose type is declared.
1212
+ * @internal
1213
+ */ var ImageDecoder = /*#__PURE__*/ function() {
1214
+ function ImageDecoder() {}
1215
+ ImageDecoder._decode = function _decode(data, url) {
1216
+ return new engineCore.AssetPromise(function(resolve, reject) {
1217
+ var objectUrl = URL.createObjectURL(new Blob([
1218
+ data
1219
+ ], {
1220
+ type: ImageDecoder._getMimeType(data)
1221
+ }));
1222
+ var image = new Image();
1223
+ image.onload = function() {
1224
+ ImageDecoder._releaseObjectUrl(image, objectUrl);
1225
+ resolve(image);
1226
+ };
1227
+ image.onerror = function() {
1228
+ ImageDecoder._releaseObjectUrl(image, objectUrl);
1229
+ reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + data.byteLength + " bytes)."));
1230
+ };
1231
+ image.src = objectUrl;
1232
+ });
1233
+ };
1234
+ ImageDecoder._getMimeType = function _getMimeType(data) {
1235
+ var bytes = _instanceof(data, Uint8Array) ? data : new Uint8Array(data);
1236
+ if (bytes.length >= 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) {
1237
+ return "image/png";
1238
+ }
1239
+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
1240
+ return "image/jpeg";
1241
+ }
1242
+ // "RIFF" .... "WEBP"
1243
+ if (bytes.length >= 12 && bytes[0] === 0x52 && bytes[1] === 0x49 && bytes[2] === 0x46 && bytes[3] === 0x46 && bytes[8] === 0x57 && bytes[9] === 0x45 && bytes[10] === 0x42 && bytes[11] === 0x50) {
1244
+ return "image/webp";
1245
+ }
1246
+ return "";
1247
+ };
1248
+ ImageDecoder._releaseObjectUrl = function _releaseObjectUrl(image, objectUrl) {
1249
+ image.onload = null;
1250
+ image.onerror = null;
1251
+ URL.revokeObjectURL(objectUrl);
1252
+ };
1253
+ return ImageDecoder;
1254
+ }();
1255
+
1201
1256
  /**
1202
1257
  * Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
1203
1258
  * [format(1B)] [width(2B)] [height(2B)] [isSRGBColorSpace(1B)] [Uint32(imageSize) + imageBytes]
@@ -1205,7 +1260,7 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
1205
1260
  function Texture2DDecoder() {}
1206
1261
  Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
1207
1262
  return new engineCore.AssetPromise(function(resolve, reject) {
1208
- bufferReader.nextStr();
1263
+ var url = bufferReader.nextStr();
1209
1264
  var mipmap = !!bufferReader.nextUint8();
1210
1265
  var filterMode = bufferReader.nextUint8();
1211
1266
  var anisoLevel = bufferReader.nextUint8();
@@ -1229,21 +1284,11 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
1229
1284
  mipmap && texture.generateMipmaps();
1230
1285
  resolve(texture);
1231
1286
  } else {
1232
- var blob = new Blob([
1233
- imageData
1234
- ]);
1235
- var img = new Image();
1236
- img.onload = function() {
1237
- URL.revokeObjectURL(img.src);
1287
+ ImageDecoder._decode(imageData, url).then(function(img) {
1238
1288
  texture.setImageSource(img);
1239
1289
  mipmap && texture.generateMipmaps();
1240
1290
  resolve(texture);
1241
- };
1242
- img.onerror = function(e) {
1243
- URL.revokeObjectURL(img.src);
1244
- reject(e);
1245
- };
1246
- img.src = URL.createObjectURL(blob);
1291
+ }, reject);
1247
1292
  }
1248
1293
  });
1249
1294
  };
@@ -1260,7 +1305,7 @@ Texture2DDecoder = __decorate([
1260
1305
  function TextureCubeDecoder() {}
1261
1306
  TextureCubeDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
1262
1307
  return new engineCore.AssetPromise(function(resolve, reject) {
1263
- bufferReader.nextStr();
1308
+ var url = bufferReader.nextStr();
1264
1309
  var mipmap = !!bufferReader.nextUint8();
1265
1310
  var filterMode = bufferReader.nextUint8();
1266
1311
  var anisoLevel = bufferReader.nextUint8();
@@ -1287,23 +1332,13 @@ Texture2DDecoder = __decorate([
1287
1332
  resolve(texture);
1288
1333
  } else {
1289
1334
  var _loop = function(i1) {
1290
- var blob = new Blob([
1291
- facesData[i1]
1292
- ]);
1293
- var img = new Image();
1294
- img.onload = function() {
1295
- URL.revokeObjectURL(img.src);
1335
+ ImageDecoder._decode(facesData[i1], url).then(function(img) {
1296
1336
  texture.setImageSource(engineCore.TextureCubeFace.PositiveX + i1, img);
1297
1337
  if (++loadedCount === 6) {
1298
1338
  mipmap && texture.generateMipmaps();
1299
1339
  resolve(texture);
1300
1340
  }
1301
- };
1302
- img.onerror = function(e) {
1303
- URL.revokeObjectURL(img.src);
1304
- reject(e);
1305
- };
1306
- img.src = URL.createObjectURL(blob);
1341
+ }, reject);
1307
1342
  };
1308
1343
  var loadedCount = 0;
1309
1344
  for(var i1 = 0; i1 < 6; i1++)_loop(i1);
@@ -1316,12 +1351,6 @@ TextureCubeDecoder = __decorate([
1316
1351
  decoder("TextureCube")
1317
1352
  ], TextureCubeDecoder);
1318
1353
 
1319
- function _instanceof(left, right) {
1320
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1321
- return !!right[Symbol.hasInstance](left);
1322
- } else return left instanceof right;
1323
- }
1324
-
1325
1354
  /**
1326
1355
  * The Prefab resource.
1327
1356
  */ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
@@ -5926,26 +5955,102 @@ var PrimitiveMeshLoader = /*#__PURE__*/ function(Loader) {
5926
5955
  }
5927
5956
  var _proto = PrimitiveMeshLoader.prototype;
5928
5957
  _proto.load = function load(item, resourceManager) {
5929
- var engine = resourceManager.engine;
5958
+ var _this = this;
5930
5959
  return resourceManager._request(item.url, _extends({}, item, {
5931
5960
  type: "json"
5932
5961
  })).then(function(data) {
5933
- switch(data.type){
5934
- case "sphere":
5935
- return engineCore.PrimitiveMesh.createSubdivisionSurfaceSphere(engine, data.sphereRadius, data.sphereStep);
5936
- case "capsule":
5937
- return engineCore.PrimitiveMesh.createCapsule(engine, data.capsuleRadius, data.capsuleHeight, data.capsuleRadialSegments, data.capsuleHeightSegments);
5938
- case "cone":
5939
- return engineCore.PrimitiveMesh.createCone(engine, data.coneRadius, data.coneHeight, data.coneRadialSegment, data.coneHeightSegment);
5940
- case "cuboid":
5941
- return engineCore.PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth);
5942
- case "cylinder":
5943
- return engineCore.PrimitiveMesh.createCylinder(engine, data.cylinderRadiusTop, data.cylinderRadiusBottom, data.cylinderHeight, data.cylinderRadialSegment, data.cylinderHeightSegment);
5944
- case "plane":
5945
- return engineCore.PrimitiveMesh.createPlane(engine, data.planeWidth, data.planeHeight, data.planeHorizontalSegments, data.planeVerticalSegments);
5946
- case "torus":
5947
- return engineCore.PrimitiveMesh.createTorus(engine, data.torusRadius, data.torusTubeRadius, data.torusRadialSegments, data.torusTubularSegments, data.torusArc);
5962
+ return _this._createPrimitiveMesh(resourceManager.engine, data);
5963
+ });
5964
+ };
5965
+ _proto._createPrimitiveMesh = function _createPrimitiveMesh(engine, data) {
5966
+ var type = data.type;
5967
+ switch(type){
5968
+ case "sphere":
5969
+ return engineCore.PrimitiveMesh.createSphere(engine, data.sphereRadius, this._parseRangeOptions(data.sphereOptions));
5970
+ case "cuboid":
5971
+ return engineCore.PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth, data.cuboidOptions);
5972
+ case "plane":
5973
+ return engineCore.PrimitiveMesh.createPlane(engine, data.planeWidth, data.planeDepth, data.planeOptions);
5974
+ case "cylinder":
5975
+ return engineCore.PrimitiveMesh.createCylinder(engine, data.cylinderRadius, data.cylinderHeight, this._parseRangeOptions(data.cylinderOptions));
5976
+ case "truncatedCone":
5977
+ return engineCore.PrimitiveMesh.createTruncatedCone(engine, data.truncatedConeTopRadius, data.truncatedConeBottomRadius, data.truncatedConeHeight, this._parseRangeOptions(data.truncatedConeOptions));
5978
+ case "cone":
5979
+ return engineCore.PrimitiveMesh.createCone(engine, data.coneRadius, data.coneHeight, this._parseRangeOptions(data.coneOptions));
5980
+ case "capsule":
5981
+ return engineCore.PrimitiveMesh.createCapsule(engine, data.capsuleRadius, data.capsuleCylinderHeight, data.capsuleOptions);
5982
+ case "torus":
5983
+ return engineCore.PrimitiveMesh.createTorus(engine, data.torusRadius, data.torusTubeRadius, this._parseRangeOptions(data.torusOptions));
5984
+ case "circle":
5985
+ return engineCore.PrimitiveMesh.createCircle(engine, data.circleRadius, this._parseRangeOptions(data.circleOptions));
5986
+ case "ring":
5987
+ return engineCore.PrimitiveMesh.createRing(engine, data.ringOuterRadius, data.ringInnerRadius, this._parseRangeOptions(data.ringOptions));
5988
+ case "tetrahedron":
5989
+ return engineCore.PrimitiveMesh.createTetrahedron(engine, data.tetrahedronRadius, data.tetrahedronOptions);
5990
+ case "octahedron":
5991
+ return engineCore.PrimitiveMesh.createOctahedron(engine, data.octahedronRadius, data.octahedronOptions);
5992
+ case "icosahedron":
5993
+ return engineCore.PrimitiveMesh.createIcosahedron(engine, data.icosahedronRadius, data.icosahedronOptions);
5994
+ case "dodecahedron":
5995
+ return engineCore.PrimitiveMesh.createDodecahedron(engine, data.dodecahedronRadius, data.dodecahedronOptions);
5996
+ case "revolvedSurface":
5997
+ return engineCore.PrimitiveMesh.createRevolvedSurface(engine, this._parseVector2s(data.revolvedSurfaceProfile), this._parseRangeOptions(data.revolvedSurfaceOptions));
5998
+ case "tube":
5999
+ return engineCore.PrimitiveMesh.createTube(engine, this._parseVector3s(data.tubePath), data.tubeRadius, data.tubeOptions);
6000
+ case "polygon":
6001
+ return engineCore.PrimitiveMesh.createPolygon(engine, this._parseShapes(data.polygonShapes), data.polygonOptions);
6002
+ case "extrudedPolygon":
6003
+ if ("extrudedPolygonPath" in data) {
6004
+ return engineCore.PrimitiveMesh.createExtrudedPolygon(engine, this._parseShapes(data.extrudedPolygonShapes), this._parseVector3s(data.extrudedPolygonPath), data.extrudedPolygonOptions);
6005
+ }
6006
+ return engineCore.PrimitiveMesh.createExtrudedPolygon(engine, this._parseShapes(data.extrudedPolygonShapes), data.extrudedPolygonDepth, data.extrudedPolygonOptions);
6007
+ case "torusKnot":
6008
+ return engineCore.PrimitiveMesh.createTorusKnot(engine, data.torusKnotRadius, data.torusKnotTubeRadius, data.torusKnotAxisTurns, data.torusKnotCrossSectionTurns, data.torusKnotOptions);
6009
+ case "roundedCuboid":
6010
+ return engineCore.PrimitiveMesh.createRoundedCuboid(engine, data.roundedCuboidWidth, data.roundedCuboidHeight, data.roundedCuboidDepth, data.roundedCuboidCornerRadius, data.roundedCuboidOptions);
6011
+ default:
6012
+ {
6013
+ var unsupportedType = type;
6014
+ throw new Error("Unknown primitive mesh type: " + unsupportedType);
6015
+ }
6016
+ }
6017
+ };
6018
+ _proto._parseRangeOptions = function _parseRangeOptions(options) {
6019
+ if (!options) {
6020
+ return;
6021
+ }
6022
+ var result;
6023
+ for(var key in options){
6024
+ var value = options[key];
6025
+ if (value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
6026
+ var range = value;
6027
+ (result != null ? result : result = _extends({}, options))[key] = new engineMath.Vector2(range.x, range.y);
5948
6028
  }
6029
+ }
6030
+ return result != null ? result : options;
6031
+ };
6032
+ _proto._parseVector2s = function _parseVector2s(points) {
6033
+ return points.map(function(param) {
6034
+ var x = param.x, y = param.y;
6035
+ return new engineMath.Vector2(x, y);
6036
+ });
6037
+ };
6038
+ _proto._parseVector3s = function _parseVector3s(points) {
6039
+ return points.map(function(param) {
6040
+ var x = param.x, y = param.y, z = param.z;
6041
+ return new engineMath.Vector3(x, y, z);
6042
+ });
6043
+ };
6044
+ _proto._parseShapes = function _parseShapes(shapes) {
6045
+ var _this = this;
6046
+ return shapes.map(function(param) {
6047
+ var points = param.points, holes = param.holes;
6048
+ return {
6049
+ points: _this._parseVector2s(points),
6050
+ holes: holes == null ? void 0 : holes.map(function(hole) {
6051
+ return _this._parseVector2s(hole);
6052
+ })
6053
+ };
5949
6054
  });
5950
6055
  };
5951
6056
  return PrimitiveMeshLoader;
@@ -6249,7 +6354,7 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
6249
6354
  };
6250
6355
  _proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
6251
6356
  var _this = this;
6252
- return decodeImage(buffer, item.url).then(function(img) {
6357
+ return ImageDecoder._decode(buffer, item.url).then(function(img) {
6253
6358
  var _item_params;
6254
6359
  var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? engineCore.TextureFormat.R8G8B8A8 : _ref_format, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
6255
6360
  var engine = resourceManager.engine;
@@ -6308,7 +6413,7 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6308
6413
  texture.mipmapCount > 1 && texture.generateMipmaps();
6309
6414
  return texture;
6310
6415
  }
6311
- return decodeImage(buffer, _this.url).then(function(img) {
6416
+ return ImageDecoder._decode(buffer, _this.url).then(function(img) {
6312
6417
  texture.setImageSource(img);
6313
6418
  texture.mipmapCount > 1 && texture.generateMipmaps();
6314
6419
  return texture;
@@ -6317,26 +6422,6 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
6317
6422
  };
6318
6423
  return TextureContentRestorer;
6319
6424
  }(engineCore.ContentRestorer);
6320
- function decodeImage(buffer, url) {
6321
- return new engineCore.AssetPromise(function(resolve, reject) {
6322
- var objectUrl = URL.createObjectURL(new Blob([
6323
- buffer
6324
- ]));
6325
- var image = new Image();
6326
- var releaseObjectUrl = function() {
6327
- return URL.revokeObjectURL(objectUrl);
6328
- };
6329
- image.onload = function() {
6330
- releaseObjectUrl();
6331
- resolve(image);
6332
- };
6333
- image.onerror = function() {
6334
- releaseObjectUrl();
6335
- reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + buffer.byteLength + " bytes)."));
6336
- };
6337
- image.src = objectUrl;
6338
- });
6339
- }
6340
6425
 
6341
6426
  var AudioLoader = /*#__PURE__*/ function(Loader) {
6342
6427
  _inherits(AudioLoader, Loader);
@@ -6733,6 +6818,25 @@ KHR_materials_clearcoat = __decorate([
6733
6818
  registerGLTFExtension("KHR_materials_clearcoat", GLTFExtensionMode.AdditiveParse)
6734
6819
  ], KHR_materials_clearcoat);
6735
6820
 
6821
+ var KHR_materials_emissive_strength = /*#__PURE__*/ function(GLTFExtensionParser) {
6822
+ _inherits(KHR_materials_emissive_strength, GLTFExtensionParser);
6823
+ function KHR_materials_emissive_strength() {
6824
+ return GLTFExtensionParser.apply(this, arguments) || this;
6825
+ }
6826
+ var _proto = KHR_materials_emissive_strength.prototype;
6827
+ _proto.additiveParse = function additiveParse(_, material, schema) {
6828
+ var _schema_emissiveStrength = schema.emissiveStrength, emissiveStrength = _schema_emissiveStrength === void 0 ? 1 : _schema_emissiveStrength;
6829
+ if (emissiveStrength !== 1 && _instanceof(material, engineCore.PBRMaterial)) {
6830
+ var color = material.emissiveColor;
6831
+ color.set(color.r * emissiveStrength, color.g * emissiveStrength, color.b * emissiveStrength, color.a);
6832
+ }
6833
+ };
6834
+ return KHR_materials_emissive_strength;
6835
+ }(GLTFExtensionParser);
6836
+ KHR_materials_emissive_strength = __decorate([
6837
+ registerGLTFExtension("KHR_materials_emissive_strength", GLTFExtensionMode.AdditiveParse)
6838
+ ], KHR_materials_emissive_strength);
6839
+
6736
6840
  var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
6737
6841
  _inherits(KHR_materials_ior, GLTFExtensionParser);
6738
6842
  function KHR_materials_ior() {