@galacean/engine-loader 0.9.0-beta.80 → 0.9.0-beta.82

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
@@ -1820,6 +1820,8 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1820
1820
  var vertexElements = new Array();
1821
1821
  var vertexCount;
1822
1822
  var bufferBindIndex = 0;
1823
+ var positions;
1824
+ keepMeshData && (positions = new Array(vertexCount));
1823
1825
  for(var attribute in attributes){
1824
1826
  var accessor = accessors[attributes[attribute]];
1825
1827
  var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
@@ -1861,16 +1863,24 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1861
1863
  if (accessor.min && accessor.max) {
1862
1864
  min.copyFromArray(accessor.min);
1863
1865
  max.copyFromArray(accessor.max);
1866
+ if (keepMeshData) {
1867
+ var stride1 = vertices.length / attributeCount;
1868
+ for(var j = 0; j < attributeCount; j++){
1869
+ var offset = j * stride1;
1870
+ positions[j] = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1871
+ }
1872
+ }
1864
1873
  } else {
1865
1874
  var position = MeshParser._tempVector3;
1866
1875
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1867
1876
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1868
- var stride1 = vertices.length / attributeCount;
1869
- for(var j = 0; j < attributeCount; j++){
1870
- var offset = j * stride1;
1871
- position.copyFromArray(vertices, offset);
1877
+ var stride2 = vertices.length / attributeCount;
1878
+ for(var j1 = 0; j1 < attributeCount; j1++){
1879
+ var offset1 = j1 * stride2;
1880
+ position.copyFromArray(vertices, offset1);
1872
1881
  engineMath.Vector3.min(min, position, min);
1873
1882
  engineMath.Vector3.max(max, position, max);
1883
+ keepMeshData && (positions[j1] = position.clone());
1874
1884
  }
1875
1885
  }
1876
1886
  if (accessor.normalized) {
@@ -1893,6 +1903,8 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1893
1903
  // BlendShapes
1894
1904
  targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1895
1905
  mesh.uploadData(!keepMeshData);
1906
+ //@ts-ignore
1907
+ mesh._positions = positions;
1896
1908
  return Promise.resolve(mesh);
1897
1909
  };
1898
1910
  _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
@@ -4116,6 +4128,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4116
4128
  _this = Loader.apply(this, arguments) || this;
4117
4129
  _this._tempRect = new engineMath.Rect();
4118
4130
  _this._tempVec2 = new engineMath.Vector2();
4131
+ _this._tempVec4 = new engineMath.Vector4();
4119
4132
  return _this;
4120
4133
  }
4121
4134
  var _proto = SpriteAtlasLoader.prototype;
@@ -4133,57 +4146,65 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4133
4146
  }));
4134
4147
  chainPromises.push(configPromise);
4135
4148
  configPromise.then(function(atlasData) {
4136
- var atlasItems = atlasData.atlasItems, format = atlasData.format;
4137
- var atlasItemsLen = atlasItems.length;
4138
- var imagePromises = engineCore.AssetPromise.all(atlasItems.map(function(param) {
4139
- var img = param.img;
4140
- return _this.request(GLTFUtil.parseRelativeUrl(item.url, img), _extends({}, item, {
4141
- type: "image"
4142
- }));
4143
- }));
4144
- chainPromises.push(imagePromises);
4145
- return imagePromises.then(function(imgs) {
4146
- var engine = resourceManager.engine;
4147
- // Generate a SpriteAtlas object.
4148
- var tempRect = _this._tempRect, tempVec2 = _this._tempVec2;
4149
- var spriteAtlas = new engineCore.SpriteAtlas(engine);
4150
- for(var i = 0; i < atlasItemsLen; i++){
4151
- // Generate Texture2D according to configuration.
4152
- var originalImg = imgs[i];
4153
- var width = originalImg.width, height = originalImg.height;
4154
- var texture = new engineCore.Texture2D(engine, width, height, format);
4155
- texture.setImageSource(originalImg);
4156
- texture.generateMipmaps();
4157
- // Generate all the sprites on this texture.
4158
- var atlasItem = atlasItems[i];
4159
- var sprites = atlasItem.sprites;
4160
- var sourceWidthReciprocal = 1.0 / width;
4161
- var sourceHeightReciprocal = 1.0 / height;
4162
- for(var j = sprites.length - 1; j >= 0; j--){
4163
- var atlasSprite = sprites[j];
4164
- var region = atlasSprite.region, atlasRegionOffset = atlasSprite.atlasRegionOffset, atlasRegion = atlasSprite.atlasRegion, id = atlasSprite.id, pivot = atlasSprite.pivot;
4165
- var sprite = new engineCore.Sprite(engine, texture, region ? tempRect.set(region.x, region.y, region.w, region.h) : undefined, pivot ? tempVec2.set(pivot.x, pivot.y) : undefined, undefined, atlasSprite.name);
4166
- sprite.atlasRegion.set(atlasRegion.x * sourceWidthReciprocal, atlasRegion.y * sourceHeightReciprocal, atlasRegion.w * sourceWidthReciprocal, atlasRegion.h * sourceHeightReciprocal);
4167
- atlasSprite.atlasRotated && (sprite.atlasRotated = true);
4168
- if (atlasRegionOffset) {
4169
- var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
4170
- sprite.atlasRegionOffset.set(offsetLeft * sourceWidthReciprocal, offsetTop * sourceHeightReciprocal, offsetRight * sourceWidthReciprocal, offsetBottom * sourceHeightReciprocal);
4149
+ var _loop = function(i) {
4150
+ var atlasItem = atlasItems[i];
4151
+ if (atlasItem.img) {
4152
+ chainPromises.push(resourceManager.load({
4153
+ url: atlasItem.img,
4154
+ type: engineCore.AssetType.Texture2D,
4155
+ params: {
4156
+ format: format,
4157
+ mipmap: mipmap
4171
4158
  }
4172
- if (id !== undefined) {
4159
+ }).then(function(texture) {
4160
+ anisoLevel && (texture.anisoLevel = anisoLevel);
4161
+ filterMode !== undefined && (texture.filterMode = filterMode);
4162
+ wrapModeU !== undefined && (texture.wrapModeU = wrapModeU);
4163
+ wrapModeV !== undefined && (texture.wrapModeV = wrapModeV);
4164
+ for(var i = 0; i < atlasItem.sprites.length; i++){
4173
4165
  // @ts-ignore
4174
- sprite._assetID = id;
4166
+ spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i], texture));
4175
4167
  }
4168
+ }).catch(reject));
4169
+ } else {
4170
+ for(var i1 = 0; i1 < atlasItem.sprites.length; i1++){
4176
4171
  // @ts-ignore
4177
- spriteAtlas._addSprite(sprite);
4172
+ spriteAtlas._addSprite(_this._makeSprite(engine, atlasItem.sprites[i1]));
4178
4173
  }
4179
4174
  }
4175
+ };
4176
+ var atlasItems = atlasData.atlasItems, mipmap = atlasData.mipmap, anisoLevel = atlasData.anisoLevel, filterMode = atlasData.filterMode, wrapModeU = atlasData.wrapModeU, wrapModeV = atlasData.wrapModeV, format = atlasData.format;
4177
+ var atlasItemsLen = atlasItems ? atlasItems.length : 0;
4178
+ var engine = resourceManager.engine;
4179
+ var spriteAtlas = new engineCore.SpriteAtlas(engine);
4180
+ if (atlasItemsLen < 0) {
4180
4181
  resolve(spriteAtlas);
4181
- });
4182
- }).catch(function(e) {
4183
- reject(e);
4184
- });
4182
+ return;
4183
+ }
4184
+ chainPromises.length = 0;
4185
+ for(var i = 0; i < atlasItems.length; i++)_loop(i);
4186
+ engineCore.AssetPromise.all(chainPromises).then(function() {
4187
+ resolve(spriteAtlas);
4188
+ }).catch(reject);
4189
+ }).catch(reject);
4185
4190
  });
4186
4191
  };
4192
+ _proto._makeSprite = function _makeSprite(engine, config, texture) {
4193
+ // Generate a SpriteAtlas object.
4194
+ var region = config.region, atlasRegionOffset = config.atlasRegionOffset, atlasRegion = config.atlasRegion, pivot = config.pivot, border = config.border;
4195
+ var sprite = new engineCore.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);
4196
+ if (texture) {
4197
+ var invW = 1 / texture.width;
4198
+ var invH = 1 / texture.height;
4199
+ sprite.atlasRegion.set(atlasRegion.x * invW, atlasRegion.y * invH, atlasRegion.w * invW, atlasRegion.h * invH);
4200
+ if (atlasRegionOffset) {
4201
+ var offsetLeft = atlasRegionOffset.x, offsetTop = atlasRegionOffset.y, offsetRight = atlasRegionOffset.z, offsetBottom = atlasRegionOffset.w;
4202
+ sprite.atlasRegionOffset.set(offsetLeft * invW, offsetTop * invH, offsetRight * invW, offsetBottom * invH);
4203
+ }
4204
+ config.atlasRotated && (sprite.atlasRotated = true);
4205
+ }
4206
+ return sprite;
4207
+ };
4187
4208
  return SpriteAtlasLoader;
4188
4209
  }(engineCore.Loader);
4189
4210
  SpriteAtlasLoader = __decorate([
@@ -4204,13 +4225,19 @@ var SpriteLoader = /*#__PURE__*/ function(Loader) {
4204
4225
  _this.request(item.url, _extends({}, item, {
4205
4226
  type: "json"
4206
4227
  })).then(function(data) {
4207
- // @ts-ignore
4208
- resourceManager.getResourceByRef(data.texture).then(function(texture) {
4209
- var sprite = new engineCore.Sprite(resourceManager.engine, texture);
4210
- sprite.region = data.region;
4211
- sprite.pivot = data.pivot;
4212
- resolve(sprite);
4213
- });
4228
+ if (data.belongToAtlas) {
4229
+ resourceManager// @ts-ignore
4230
+ .getResourceByRef(data.belongToAtlas).then(function(atlas) {
4231
+ resolve(atlas.getSprite(data.fullPath));
4232
+ }).catch(reject);
4233
+ } else if (data.texture) {
4234
+ resourceManager// @ts-ignore
4235
+ .getResourceByRef(data.texture).then(function(texture) {
4236
+ resolve(new engineCore.Sprite(resourceManager.engine, texture, data.region, data.pivot, data.border));
4237
+ }).catch(reject);
4238
+ } else {
4239
+ resolve(new engineCore.Sprite(resourceManager.engine, null, data.region, data.pivot, data.border));
4240
+ }
4214
4241
  }).catch(reject);
4215
4242
  });
4216
4243
  };