@galacean/engine-loader 2.0.0-alpha.55 → 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 +174 -70
- package/dist/main.js.map +1 -1
- package/dist/module.js +174 -70
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/ImageDecoder.d.ts +13 -0
- package/types/PrimitiveMeshAsset.d.ts +238 -0
- package/types/gltf/extensions/GLTFExtensionSchema.d.ts +7 -1
- package/types/gltf/extensions/KHR_materials_emissive_strength.d.ts +1 -0
- package/types/gltf/extensions/index.d.ts +1 -0
- package/types/index.d.ts +1 -0
package/dist/module.js
CHANGED
|
@@ -1194,6 +1194,61 @@ HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
|
|
|
1194
1194
|
HDRDecoder._floatView = new Float32Array(1);
|
|
1195
1195
|
HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
1196
1196
|
|
|
1197
|
+
function _instanceof(left, right) {
|
|
1198
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1199
|
+
return !!right[Symbol.hasInstance](left);
|
|
1200
|
+
} else return left instanceof right;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Decodes encoded image bytes (PNG, JPEG, WebP, ...) into an image element.
|
|
1205
|
+
*
|
|
1206
|
+
* The blob handed to the image carries the MIME type detected from the bytes: browsers sniff an untyped
|
|
1207
|
+
* blob, but some platforms (for example mini-game runtimes) only decode images whose type is declared.
|
|
1208
|
+
* @internal
|
|
1209
|
+
*/ var ImageDecoder = /*#__PURE__*/ function() {
|
|
1210
|
+
function ImageDecoder() {}
|
|
1211
|
+
ImageDecoder._decode = function _decode(data, url) {
|
|
1212
|
+
return new AssetPromise(function(resolve, reject) {
|
|
1213
|
+
var objectUrl = URL.createObjectURL(new Blob([
|
|
1214
|
+
data
|
|
1215
|
+
], {
|
|
1216
|
+
type: ImageDecoder._getMimeType(data)
|
|
1217
|
+
}));
|
|
1218
|
+
var image = new Image();
|
|
1219
|
+
image.onload = function() {
|
|
1220
|
+
ImageDecoder._releaseObjectUrl(image, objectUrl);
|
|
1221
|
+
resolve(image);
|
|
1222
|
+
};
|
|
1223
|
+
image.onerror = function() {
|
|
1224
|
+
ImageDecoder._releaseObjectUrl(image, objectUrl);
|
|
1225
|
+
reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + data.byteLength + " bytes)."));
|
|
1226
|
+
};
|
|
1227
|
+
image.src = objectUrl;
|
|
1228
|
+
});
|
|
1229
|
+
};
|
|
1230
|
+
ImageDecoder._getMimeType = function _getMimeType(data) {
|
|
1231
|
+
var bytes = _instanceof(data, Uint8Array) ? data : new Uint8Array(data);
|
|
1232
|
+
if (bytes.length >= 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) {
|
|
1233
|
+
return "image/png";
|
|
1234
|
+
}
|
|
1235
|
+
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
|
|
1236
|
+
return "image/jpeg";
|
|
1237
|
+
}
|
|
1238
|
+
// "RIFF" .... "WEBP"
|
|
1239
|
+
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) {
|
|
1240
|
+
return "image/webp";
|
|
1241
|
+
}
|
|
1242
|
+
return "";
|
|
1243
|
+
};
|
|
1244
|
+
ImageDecoder._releaseObjectUrl = function _releaseObjectUrl(image, objectUrl) {
|
|
1245
|
+
image.onload = null;
|
|
1246
|
+
image.onerror = null;
|
|
1247
|
+
URL.revokeObjectURL(objectUrl);
|
|
1248
|
+
};
|
|
1249
|
+
return ImageDecoder;
|
|
1250
|
+
}();
|
|
1251
|
+
|
|
1197
1252
|
/**
|
|
1198
1253
|
* Data format: [url] [mipmap(1B)] [filterMode(1B)] [anisoLevel(1B)] [wrapModeU(1B)] [wrapModeV(1B)]
|
|
1199
1254
|
* [format(1B)] [width(2B)] [height(2B)] [isSRGBColorSpace(1B)] [Uint32(imageSize) + imageBytes]
|
|
@@ -1201,7 +1256,7 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1201
1256
|
function Texture2DDecoder() {}
|
|
1202
1257
|
Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1203
1258
|
return new AssetPromise(function(resolve, reject) {
|
|
1204
|
-
bufferReader.nextStr();
|
|
1259
|
+
var url = bufferReader.nextStr();
|
|
1205
1260
|
var mipmap = !!bufferReader.nextUint8();
|
|
1206
1261
|
var filterMode = bufferReader.nextUint8();
|
|
1207
1262
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -1225,21 +1280,11 @@ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
|
|
|
1225
1280
|
mipmap && texture.generateMipmaps();
|
|
1226
1281
|
resolve(texture);
|
|
1227
1282
|
} else {
|
|
1228
|
-
|
|
1229
|
-
imageData
|
|
1230
|
-
]);
|
|
1231
|
-
var img = new Image();
|
|
1232
|
-
img.onload = function() {
|
|
1233
|
-
URL.revokeObjectURL(img.src);
|
|
1283
|
+
ImageDecoder._decode(imageData, url).then(function(img) {
|
|
1234
1284
|
texture.setImageSource(img);
|
|
1235
1285
|
mipmap && texture.generateMipmaps();
|
|
1236
1286
|
resolve(texture);
|
|
1237
|
-
};
|
|
1238
|
-
img.onerror = function(e) {
|
|
1239
|
-
URL.revokeObjectURL(img.src);
|
|
1240
|
-
reject(e);
|
|
1241
|
-
};
|
|
1242
|
-
img.src = URL.createObjectURL(blob);
|
|
1287
|
+
}, reject);
|
|
1243
1288
|
}
|
|
1244
1289
|
});
|
|
1245
1290
|
};
|
|
@@ -1256,7 +1301,7 @@ Texture2DDecoder = __decorate([
|
|
|
1256
1301
|
function TextureCubeDecoder() {}
|
|
1257
1302
|
TextureCubeDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
|
|
1258
1303
|
return new AssetPromise(function(resolve, reject) {
|
|
1259
|
-
bufferReader.nextStr();
|
|
1304
|
+
var url = bufferReader.nextStr();
|
|
1260
1305
|
var mipmap = !!bufferReader.nextUint8();
|
|
1261
1306
|
var filterMode = bufferReader.nextUint8();
|
|
1262
1307
|
var anisoLevel = bufferReader.nextUint8();
|
|
@@ -1283,23 +1328,13 @@ Texture2DDecoder = __decorate([
|
|
|
1283
1328
|
resolve(texture);
|
|
1284
1329
|
} else {
|
|
1285
1330
|
var _loop = function(i1) {
|
|
1286
|
-
|
|
1287
|
-
facesData[i1]
|
|
1288
|
-
]);
|
|
1289
|
-
var img = new Image();
|
|
1290
|
-
img.onload = function() {
|
|
1291
|
-
URL.revokeObjectURL(img.src);
|
|
1331
|
+
ImageDecoder._decode(facesData[i1], url).then(function(img) {
|
|
1292
1332
|
texture.setImageSource(TextureCubeFace.PositiveX + i1, img);
|
|
1293
1333
|
if (++loadedCount === 6) {
|
|
1294
1334
|
mipmap && texture.generateMipmaps();
|
|
1295
1335
|
resolve(texture);
|
|
1296
1336
|
}
|
|
1297
|
-
};
|
|
1298
|
-
img.onerror = function(e) {
|
|
1299
|
-
URL.revokeObjectURL(img.src);
|
|
1300
|
-
reject(e);
|
|
1301
|
-
};
|
|
1302
|
-
img.src = URL.createObjectURL(blob);
|
|
1337
|
+
}, reject);
|
|
1303
1338
|
};
|
|
1304
1339
|
var loadedCount = 0;
|
|
1305
1340
|
for(var i1 = 0; i1 < 6; i1++)_loop(i1);
|
|
@@ -1312,12 +1347,6 @@ TextureCubeDecoder = __decorate([
|
|
|
1312
1347
|
decoder("TextureCube")
|
|
1313
1348
|
], TextureCubeDecoder);
|
|
1314
1349
|
|
|
1315
|
-
function _instanceof(left, right) {
|
|
1316
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
1317
|
-
return !!right[Symbol.hasInstance](left);
|
|
1318
|
-
} else return left instanceof right;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
1350
|
/**
|
|
1322
1351
|
* The Prefab resource.
|
|
1323
1352
|
*/ var PrefabResource = /*#__PURE__*/ function(ReferResource1) {
|
|
@@ -5922,26 +5951,102 @@ var PrimitiveMeshLoader = /*#__PURE__*/ function(Loader) {
|
|
|
5922
5951
|
}
|
|
5923
5952
|
var _proto = PrimitiveMeshLoader.prototype;
|
|
5924
5953
|
_proto.load = function load(item, resourceManager) {
|
|
5925
|
-
var
|
|
5954
|
+
var _this = this;
|
|
5926
5955
|
return resourceManager._request(item.url, _extends({}, item, {
|
|
5927
5956
|
type: "json"
|
|
5928
5957
|
})).then(function(data) {
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5958
|
+
return _this._createPrimitiveMesh(resourceManager.engine, data);
|
|
5959
|
+
});
|
|
5960
|
+
};
|
|
5961
|
+
_proto._createPrimitiveMesh = function _createPrimitiveMesh(engine, data) {
|
|
5962
|
+
var type = data.type;
|
|
5963
|
+
switch(type){
|
|
5964
|
+
case "sphere":
|
|
5965
|
+
return PrimitiveMesh.createSphere(engine, data.sphereRadius, this._parseRangeOptions(data.sphereOptions));
|
|
5966
|
+
case "cuboid":
|
|
5967
|
+
return PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth, data.cuboidOptions);
|
|
5968
|
+
case "plane":
|
|
5969
|
+
return PrimitiveMesh.createPlane(engine, data.planeWidth, data.planeDepth, data.planeOptions);
|
|
5970
|
+
case "cylinder":
|
|
5971
|
+
return PrimitiveMesh.createCylinder(engine, data.cylinderRadius, data.cylinderHeight, this._parseRangeOptions(data.cylinderOptions));
|
|
5972
|
+
case "truncatedCone":
|
|
5973
|
+
return PrimitiveMesh.createTruncatedCone(engine, data.truncatedConeTopRadius, data.truncatedConeBottomRadius, data.truncatedConeHeight, this._parseRangeOptions(data.truncatedConeOptions));
|
|
5974
|
+
case "cone":
|
|
5975
|
+
return PrimitiveMesh.createCone(engine, data.coneRadius, data.coneHeight, this._parseRangeOptions(data.coneOptions));
|
|
5976
|
+
case "capsule":
|
|
5977
|
+
return PrimitiveMesh.createCapsule(engine, data.capsuleRadius, data.capsuleCylinderHeight, data.capsuleOptions);
|
|
5978
|
+
case "torus":
|
|
5979
|
+
return PrimitiveMesh.createTorus(engine, data.torusRadius, data.torusTubeRadius, this._parseRangeOptions(data.torusOptions));
|
|
5980
|
+
case "circle":
|
|
5981
|
+
return PrimitiveMesh.createCircle(engine, data.circleRadius, this._parseRangeOptions(data.circleOptions));
|
|
5982
|
+
case "ring":
|
|
5983
|
+
return PrimitiveMesh.createRing(engine, data.ringOuterRadius, data.ringInnerRadius, this._parseRangeOptions(data.ringOptions));
|
|
5984
|
+
case "tetrahedron":
|
|
5985
|
+
return PrimitiveMesh.createTetrahedron(engine, data.tetrahedronRadius, data.tetrahedronOptions);
|
|
5986
|
+
case "octahedron":
|
|
5987
|
+
return PrimitiveMesh.createOctahedron(engine, data.octahedronRadius, data.octahedronOptions);
|
|
5988
|
+
case "icosahedron":
|
|
5989
|
+
return PrimitiveMesh.createIcosahedron(engine, data.icosahedronRadius, data.icosahedronOptions);
|
|
5990
|
+
case "dodecahedron":
|
|
5991
|
+
return PrimitiveMesh.createDodecahedron(engine, data.dodecahedronRadius, data.dodecahedronOptions);
|
|
5992
|
+
case "revolvedSurface":
|
|
5993
|
+
return PrimitiveMesh.createRevolvedSurface(engine, this._parseVector2s(data.revolvedSurfaceProfile), this._parseRangeOptions(data.revolvedSurfaceOptions));
|
|
5994
|
+
case "tube":
|
|
5995
|
+
return PrimitiveMesh.createTube(engine, this._parseVector3s(data.tubePath), data.tubeRadius, data.tubeOptions);
|
|
5996
|
+
case "polygon":
|
|
5997
|
+
return PrimitiveMesh.createPolygon(engine, this._parseShapes(data.polygonShapes), data.polygonOptions);
|
|
5998
|
+
case "extrudedPolygon":
|
|
5999
|
+
if ("extrudedPolygonPath" in data) {
|
|
6000
|
+
return PrimitiveMesh.createExtrudedPolygon(engine, this._parseShapes(data.extrudedPolygonShapes), this._parseVector3s(data.extrudedPolygonPath), data.extrudedPolygonOptions);
|
|
6001
|
+
}
|
|
6002
|
+
return PrimitiveMesh.createExtrudedPolygon(engine, this._parseShapes(data.extrudedPolygonShapes), data.extrudedPolygonDepth, data.extrudedPolygonOptions);
|
|
6003
|
+
case "torusKnot":
|
|
6004
|
+
return PrimitiveMesh.createTorusKnot(engine, data.torusKnotRadius, data.torusKnotTubeRadius, data.torusKnotAxisTurns, data.torusKnotCrossSectionTurns, data.torusKnotOptions);
|
|
6005
|
+
case "roundedCuboid":
|
|
6006
|
+
return PrimitiveMesh.createRoundedCuboid(engine, data.roundedCuboidWidth, data.roundedCuboidHeight, data.roundedCuboidDepth, data.roundedCuboidCornerRadius, data.roundedCuboidOptions);
|
|
6007
|
+
default:
|
|
6008
|
+
{
|
|
6009
|
+
var unsupportedType = type;
|
|
6010
|
+
throw new Error("Unknown primitive mesh type: " + unsupportedType);
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
};
|
|
6014
|
+
_proto._parseRangeOptions = function _parseRangeOptions(options) {
|
|
6015
|
+
if (!options) {
|
|
6016
|
+
return;
|
|
6017
|
+
}
|
|
6018
|
+
var result;
|
|
6019
|
+
for(var key in options){
|
|
6020
|
+
var value = options[key];
|
|
6021
|
+
if (value && (typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
6022
|
+
var range = value;
|
|
6023
|
+
(result != null ? result : result = _extends({}, options))[key] = new Vector2(range.x, range.y);
|
|
5944
6024
|
}
|
|
6025
|
+
}
|
|
6026
|
+
return result != null ? result : options;
|
|
6027
|
+
};
|
|
6028
|
+
_proto._parseVector2s = function _parseVector2s(points) {
|
|
6029
|
+
return points.map(function(param) {
|
|
6030
|
+
var x = param.x, y = param.y;
|
|
6031
|
+
return new Vector2(x, y);
|
|
6032
|
+
});
|
|
6033
|
+
};
|
|
6034
|
+
_proto._parseVector3s = function _parseVector3s(points) {
|
|
6035
|
+
return points.map(function(param) {
|
|
6036
|
+
var x = param.x, y = param.y, z = param.z;
|
|
6037
|
+
return new Vector3(x, y, z);
|
|
6038
|
+
});
|
|
6039
|
+
};
|
|
6040
|
+
_proto._parseShapes = function _parseShapes(shapes) {
|
|
6041
|
+
var _this = this;
|
|
6042
|
+
return shapes.map(function(param) {
|
|
6043
|
+
var points = param.points, holes = param.holes;
|
|
6044
|
+
return {
|
|
6045
|
+
points: _this._parseVector2s(points),
|
|
6046
|
+
holes: holes == null ? void 0 : holes.map(function(hole) {
|
|
6047
|
+
return _this._parseVector2s(hole);
|
|
6048
|
+
})
|
|
6049
|
+
};
|
|
5945
6050
|
});
|
|
5946
6051
|
};
|
|
5947
6052
|
return PrimitiveMeshLoader;
|
|
@@ -6245,7 +6350,7 @@ var TextureLoader = /*#__PURE__*/ function(Loader) {
|
|
|
6245
6350
|
};
|
|
6246
6351
|
_proto._decodeImage = function _decodeImage(buffer, item, resourceManager) {
|
|
6247
6352
|
var _this = this;
|
|
6248
|
-
return
|
|
6353
|
+
return ImageDecoder._decode(buffer, item.url).then(function(img) {
|
|
6249
6354
|
var _item_params;
|
|
6250
6355
|
var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? 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;
|
|
6251
6356
|
var engine = resourceManager.engine;
|
|
@@ -6304,7 +6409,7 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
|
6304
6409
|
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6305
6410
|
return texture;
|
|
6306
6411
|
}
|
|
6307
|
-
return
|
|
6412
|
+
return ImageDecoder._decode(buffer, _this.url).then(function(img) {
|
|
6308
6413
|
texture.setImageSource(img);
|
|
6309
6414
|
texture.mipmapCount > 1 && texture.generateMipmaps();
|
|
6310
6415
|
return texture;
|
|
@@ -6313,26 +6418,6 @@ var TextureContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
|
|
|
6313
6418
|
};
|
|
6314
6419
|
return TextureContentRestorer;
|
|
6315
6420
|
}(ContentRestorer);
|
|
6316
|
-
function decodeImage(buffer, url) {
|
|
6317
|
-
return new AssetPromise(function(resolve, reject) {
|
|
6318
|
-
var objectUrl = URL.createObjectURL(new Blob([
|
|
6319
|
-
buffer
|
|
6320
|
-
]));
|
|
6321
|
-
var image = new Image();
|
|
6322
|
-
var releaseObjectUrl = function() {
|
|
6323
|
-
return URL.revokeObjectURL(objectUrl);
|
|
6324
|
-
};
|
|
6325
|
-
image.onload = function() {
|
|
6326
|
-
releaseObjectUrl();
|
|
6327
|
-
resolve(image);
|
|
6328
|
-
};
|
|
6329
|
-
image.onerror = function() {
|
|
6330
|
-
releaseObjectUrl();
|
|
6331
|
-
reject(new Error('TextureLoader: failed to decode texture "' + url + '" (' + buffer.byteLength + " bytes)."));
|
|
6332
|
-
};
|
|
6333
|
-
image.src = objectUrl;
|
|
6334
|
-
});
|
|
6335
|
-
}
|
|
6336
6421
|
|
|
6337
6422
|
var AudioLoader = /*#__PURE__*/ function(Loader) {
|
|
6338
6423
|
_inherits(AudioLoader, Loader);
|
|
@@ -6729,6 +6814,25 @@ KHR_materials_clearcoat = __decorate([
|
|
|
6729
6814
|
registerGLTFExtension("KHR_materials_clearcoat", GLTFExtensionMode.AdditiveParse)
|
|
6730
6815
|
], KHR_materials_clearcoat);
|
|
6731
6816
|
|
|
6817
|
+
var KHR_materials_emissive_strength = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
6818
|
+
_inherits(KHR_materials_emissive_strength, GLTFExtensionParser);
|
|
6819
|
+
function KHR_materials_emissive_strength() {
|
|
6820
|
+
return GLTFExtensionParser.apply(this, arguments) || this;
|
|
6821
|
+
}
|
|
6822
|
+
var _proto = KHR_materials_emissive_strength.prototype;
|
|
6823
|
+
_proto.additiveParse = function additiveParse(_, material, schema) {
|
|
6824
|
+
var _schema_emissiveStrength = schema.emissiveStrength, emissiveStrength = _schema_emissiveStrength === void 0 ? 1 : _schema_emissiveStrength;
|
|
6825
|
+
if (emissiveStrength !== 1 && _instanceof(material, PBRMaterial)) {
|
|
6826
|
+
var color = material.emissiveColor;
|
|
6827
|
+
color.set(color.r * emissiveStrength, color.g * emissiveStrength, color.b * emissiveStrength, color.a);
|
|
6828
|
+
}
|
|
6829
|
+
};
|
|
6830
|
+
return KHR_materials_emissive_strength;
|
|
6831
|
+
}(GLTFExtensionParser);
|
|
6832
|
+
KHR_materials_emissive_strength = __decorate([
|
|
6833
|
+
registerGLTFExtension("KHR_materials_emissive_strength", GLTFExtensionMode.AdditiveParse)
|
|
6834
|
+
], KHR_materials_emissive_strength);
|
|
6835
|
+
|
|
6732
6836
|
var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
|
|
6733
6837
|
_inherits(KHR_materials_ior, GLTFExtensionParser);
|
|
6734
6838
|
function KHR_materials_ior() {
|