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