@scenography/plugin-model 0.4.1 → 0.5.0

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/index.cjs CHANGED
@@ -6,7 +6,8 @@ let three = require("three");
6
6
  * Build the three.js object for an external `Model`. Returns an empty `Group`
7
7
  * with the transform applied immediately; the glTF/GLB is fetched async and its
8
8
  * scene added once ready (same pattern as texture loading). `GLTFLoader` is
9
- * imported on demand so it only ships in the bundle when a scene uses models.
9
+ * imported on demand so it only ships in the bundle when a scene uses models;
10
+ * the meshopt decoder rides along so `EXT_meshopt_compression` models load.
10
11
  */
11
12
  function buildModel(model) {
12
13
  const group = new three.Group();
@@ -16,8 +17,10 @@ function buildModel(model) {
16
17
  if (model.rotation) group.rotation.set(...model.rotation);
17
18
  if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
18
19
  else group.scale.set(...model.scale);
19
- import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
20
- new GLTFLoader().load(model.src, (gltf) => {
20
+ Promise.all([import("three/examples/jsm/loaders/GLTFLoader.js"), import("three/examples/jsm/libs/meshopt_decoder.module.js")]).then(([{ GLTFLoader }, { MeshoptDecoder }]) => {
21
+ const loader = new GLTFLoader();
22
+ loader.setMeshoptDecoder(MeshoptDecoder);
23
+ loader.load(model.src, (gltf) => {
21
24
  gltf.scene.traverse((child) => {
22
25
  child.castShadow = true;
23
26
  child.receiveShadow = true;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Group","modelData"],"sources":["../src/buildModel.ts","../src/plugin.ts"],"sourcesContent":["import { Group, type Object3D } from \"three\";\n\nimport type { Model } from \"./data\";\n\n/**\n * Build the three.js object for an external `Model`. Returns an empty `Group`\n * with the transform applied immediately; the glTF/GLB is fetched async and its\n * scene added once ready (same pattern as texture loading). `GLTFLoader` is\n * imported on demand so it only ships in the bundle when a scene uses models.\n */\nexport function buildModel(model: Model): Object3D {\n const group = new Group();\n group.name = `model:${model.id}`;\n group.userData.scenographyId = model.id;\n\n if (model.position) group.position.set(...model.position);\n if (model.rotation) group.rotation.set(...model.rotation);\n if (model.scale !== undefined) {\n if (typeof model.scale === \"number\") group.scale.setScalar(model.scale);\n else group.scale.set(...model.scale);\n }\n\n void import(\"three/examples/jsm/loaders/GLTFLoader.js\").then(({ GLTFLoader }) => {\n new GLTFLoader().load(model.src, (gltf) => {\n gltf.scene.traverse((child) => {\n child.castShadow = true;\n child.receiveShadow = true;\n });\n group.add(gltf.scene);\n });\n });\n\n return group;\n}\n","import type { EnginePlugin } from \"@scenography/engine\";\n\nimport { buildModel } from \"./buildModel\";\nimport { modelData, type Model } from \"./data\";\n\n/** The model plugin: places each external glTF/GLB `Model` in the scene. */\nexport const model = (): EnginePlugin<Model> => ({\n data: modelData,\n build: (definition) => ({ object: buildModel(definition) }),\n});\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,WAAW,OAAwB;CACjD,MAAM,QAAQ,IAAIA,MAAAA,MAAM;CACxB,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SAAS,gBAAgB,MAAM;CAErC,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,OAAO,MAAM,UAAU,UAAU,MAAM,MAAM,UAAU,MAAM,KAAK;MACjE,MAAM,MAAM,IAAI,GAAG,MAAM,KAAK;CAGrC,OAAY,2CAA2C,CAAC,MAAM,EAAE,iBAAiB;EAC/E,IAAI,WAAW,CAAC,CAAC,KAAK,MAAM,MAAM,SAAS;GACzC,KAAK,MAAM,UAAU,UAAU;IAC7B,MAAM,aAAa;IACnB,MAAM,gBAAgB;GACxB,CAAC;GACD,MAAM,IAAI,KAAK,KAAK;EACtB,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;;AC3BA,MAAa,eAAoC;CAC/C,MAAMC,aAAAA;CACN,QAAQ,gBAAgB,EAAE,QAAQ,WAAW,UAAU,EAAE;AAC3D"}
1
+ {"version":3,"file":"index.cjs","names":["Group","modelData"],"sources":["../src/buildModel.ts","../src/plugin.ts"],"sourcesContent":["import { Group, type Object3D } from \"three\";\n\nimport type { Model } from \"./data\";\n\n/**\n * Build the three.js object for an external `Model`. Returns an empty `Group`\n * with the transform applied immediately; the glTF/GLB is fetched async and its\n * scene added once ready (same pattern as texture loading). `GLTFLoader` is\n * imported on demand so it only ships in the bundle when a scene uses models;\n * the meshopt decoder rides along so `EXT_meshopt_compression` models load.\n */\nexport function buildModel(model: Model): Object3D {\n const group = new Group();\n group.name = `model:${model.id}`;\n group.userData.scenographyId = model.id;\n\n if (model.position) group.position.set(...model.position);\n if (model.rotation) group.rotation.set(...model.rotation);\n if (model.scale !== undefined) {\n if (typeof model.scale === \"number\") group.scale.setScalar(model.scale);\n else group.scale.set(...model.scale);\n }\n\n void Promise.all([\n import(\"three/examples/jsm/loaders/GLTFLoader.js\"),\n import(\"three/examples/jsm/libs/meshopt_decoder.module.js\"),\n ]).then(([{ GLTFLoader }, { MeshoptDecoder }]) => {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n loader.load(model.src, (gltf) => {\n gltf.scene.traverse((child) => {\n child.castShadow = true;\n child.receiveShadow = true;\n });\n group.add(gltf.scene);\n });\n });\n\n return group;\n}\n","import type { EnginePlugin } from \"@scenography/engine\";\n\nimport { buildModel } from \"./buildModel\";\nimport { modelData, type Model } from \"./data\";\n\n/** The model plugin: places each external glTF/GLB `Model` in the scene. */\nexport const model = (): EnginePlugin<Model> => ({\n data: modelData,\n build: (definition) => ({ object: buildModel(definition) }),\n});\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,WAAW,OAAwB;CACjD,MAAM,QAAQ,IAAIA,MAAAA,MAAM;CACxB,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SAAS,gBAAgB,MAAM;CAErC,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,OAAO,MAAM,UAAU,UAAU,MAAM,MAAM,UAAU,MAAM,KAAK;MACjE,MAAM,MAAM,IAAI,GAAG,MAAM,KAAK;CAGrC,QAAa,IAAI,CACf,OAAO,6CACP,OAAO,oDACT,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,sBAAsB;EAChD,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,kBAAkB,cAAc;EACvC,OAAO,KAAK,MAAM,MAAM,SAAS;GAC/B,KAAK,MAAM,UAAU,UAAU;IAC7B,MAAM,aAAa;IACnB,MAAM,gBAAgB;GACxB,CAAC;GACD,MAAM,IAAI,KAAK,KAAK;EACtB,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;;ACjCA,MAAa,eAAoC;CAC/C,MAAMC,aAAAA;CACN,QAAQ,gBAAgB,EAAE,QAAQ,WAAW,UAAU,EAAE;AAC3D"}
package/dist/index.d.cts CHANGED
@@ -11,7 +11,8 @@ declare const model: () => EnginePlugin<Model>;
11
11
  * Build the three.js object for an external `Model`. Returns an empty `Group`
12
12
  * with the transform applied immediately; the glTF/GLB is fetched async and its
13
13
  * scene added once ready (same pattern as texture loading). `GLTFLoader` is
14
- * imported on demand so it only ships in the bundle when a scene uses models.
14
+ * imported on demand so it only ships in the bundle when a scene uses models;
15
+ * the meshopt decoder rides along so `EXT_meshopt_compression` models load.
15
16
  */
16
17
  declare function buildModel(model: Model): Object3D;
17
18
  //#endregion
package/dist/index.d.mts CHANGED
@@ -11,7 +11,8 @@ declare const model: () => EnginePlugin<Model>;
11
11
  * Build the three.js object for an external `Model`. Returns an empty `Group`
12
12
  * with the transform applied immediately; the glTF/GLB is fetched async and its
13
13
  * scene added once ready (same pattern as texture loading). `GLTFLoader` is
14
- * imported on demand so it only ships in the bundle when a scene uses models.
14
+ * imported on demand so it only ships in the bundle when a scene uses models;
15
+ * the meshopt decoder rides along so `EXT_meshopt_compression` models load.
15
16
  */
16
17
  declare function buildModel(model: Model): Object3D;
17
18
  //#endregion
package/dist/index.mjs CHANGED
@@ -5,7 +5,8 @@ import { Group } from "three";
5
5
  * Build the three.js object for an external `Model`. Returns an empty `Group`
6
6
  * with the transform applied immediately; the glTF/GLB is fetched async and its
7
7
  * scene added once ready (same pattern as texture loading). `GLTFLoader` is
8
- * imported on demand so it only ships in the bundle when a scene uses models.
8
+ * imported on demand so it only ships in the bundle when a scene uses models;
9
+ * the meshopt decoder rides along so `EXT_meshopt_compression` models load.
9
10
  */
10
11
  function buildModel(model) {
11
12
  const group = new Group();
@@ -15,8 +16,10 @@ function buildModel(model) {
15
16
  if (model.rotation) group.rotation.set(...model.rotation);
16
17
  if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
17
18
  else group.scale.set(...model.scale);
18
- import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
19
- new GLTFLoader().load(model.src, (gltf) => {
19
+ Promise.all([import("three/examples/jsm/loaders/GLTFLoader.js"), import("three/examples/jsm/libs/meshopt_decoder.module.js")]).then(([{ GLTFLoader }, { MeshoptDecoder }]) => {
20
+ const loader = new GLTFLoader();
21
+ loader.setMeshoptDecoder(MeshoptDecoder);
22
+ loader.load(model.src, (gltf) => {
20
23
  gltf.scene.traverse((child) => {
21
24
  child.castShadow = true;
22
25
  child.receiveShadow = true;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/buildModel.ts","../src/plugin.ts"],"sourcesContent":["import { Group, type Object3D } from \"three\";\n\nimport type { Model } from \"./data\";\n\n/**\n * Build the three.js object for an external `Model`. Returns an empty `Group`\n * with the transform applied immediately; the glTF/GLB is fetched async and its\n * scene added once ready (same pattern as texture loading). `GLTFLoader` is\n * imported on demand so it only ships in the bundle when a scene uses models.\n */\nexport function buildModel(model: Model): Object3D {\n const group = new Group();\n group.name = `model:${model.id}`;\n group.userData.scenographyId = model.id;\n\n if (model.position) group.position.set(...model.position);\n if (model.rotation) group.rotation.set(...model.rotation);\n if (model.scale !== undefined) {\n if (typeof model.scale === \"number\") group.scale.setScalar(model.scale);\n else group.scale.set(...model.scale);\n }\n\n void import(\"three/examples/jsm/loaders/GLTFLoader.js\").then(({ GLTFLoader }) => {\n new GLTFLoader().load(model.src, (gltf) => {\n gltf.scene.traverse((child) => {\n child.castShadow = true;\n child.receiveShadow = true;\n });\n group.add(gltf.scene);\n });\n });\n\n return group;\n}\n","import type { EnginePlugin } from \"@scenography/engine\";\n\nimport { buildModel } from \"./buildModel\";\nimport { modelData, type Model } from \"./data\";\n\n/** The model plugin: places each external glTF/GLB `Model` in the scene. */\nexport const model = (): EnginePlugin<Model> => ({\n data: modelData,\n build: (definition) => ({ object: buildModel(definition) }),\n});\n"],"mappings":";;;;;;;;;AAUA,SAAgB,WAAW,OAAwB;CACjD,MAAM,QAAQ,IAAI,MAAM;CACxB,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SAAS,gBAAgB,MAAM;CAErC,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,OAAO,MAAM,UAAU,UAAU,MAAM,MAAM,UAAU,MAAM,KAAK;MACjE,MAAM,MAAM,IAAI,GAAG,MAAM,KAAK;CAGrC,OAAY,2CAA2C,CAAC,MAAM,EAAE,iBAAiB;EAC/E,IAAI,WAAW,CAAC,CAAC,KAAK,MAAM,MAAM,SAAS;GACzC,KAAK,MAAM,UAAU,UAAU;IAC7B,MAAM,aAAa;IACnB,MAAM,gBAAgB;GACxB,CAAC;GACD,MAAM,IAAI,KAAK,KAAK;EACtB,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;;AC3BA,MAAa,eAAoC;CAC/C,MAAM;CACN,QAAQ,gBAAgB,EAAE,QAAQ,WAAW,UAAU,EAAE;AAC3D"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/buildModel.ts","../src/plugin.ts"],"sourcesContent":["import { Group, type Object3D } from \"three\";\n\nimport type { Model } from \"./data\";\n\n/**\n * Build the three.js object for an external `Model`. Returns an empty `Group`\n * with the transform applied immediately; the glTF/GLB is fetched async and its\n * scene added once ready (same pattern as texture loading). `GLTFLoader` is\n * imported on demand so it only ships in the bundle when a scene uses models;\n * the meshopt decoder rides along so `EXT_meshopt_compression` models load.\n */\nexport function buildModel(model: Model): Object3D {\n const group = new Group();\n group.name = `model:${model.id}`;\n group.userData.scenographyId = model.id;\n\n if (model.position) group.position.set(...model.position);\n if (model.rotation) group.rotation.set(...model.rotation);\n if (model.scale !== undefined) {\n if (typeof model.scale === \"number\") group.scale.setScalar(model.scale);\n else group.scale.set(...model.scale);\n }\n\n void Promise.all([\n import(\"three/examples/jsm/loaders/GLTFLoader.js\"),\n import(\"three/examples/jsm/libs/meshopt_decoder.module.js\"),\n ]).then(([{ GLTFLoader }, { MeshoptDecoder }]) => {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n loader.load(model.src, (gltf) => {\n gltf.scene.traverse((child) => {\n child.castShadow = true;\n child.receiveShadow = true;\n });\n group.add(gltf.scene);\n });\n });\n\n return group;\n}\n","import type { EnginePlugin } from \"@scenography/engine\";\n\nimport { buildModel } from \"./buildModel\";\nimport { modelData, type Model } from \"./data\";\n\n/** The model plugin: places each external glTF/GLB `Model` in the scene. */\nexport const model = (): EnginePlugin<Model> => ({\n data: modelData,\n build: (definition) => ({ object: buildModel(definition) }),\n});\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,WAAW,OAAwB;CACjD,MAAM,QAAQ,IAAI,MAAM;CACxB,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SAAS,gBAAgB,MAAM;CAErC,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,MAAM,SAAS,IAAI,GAAG,MAAM,QAAQ;CACxD,IAAI,MAAM,UAAU,KAAA,GAClB,IAAI,OAAO,MAAM,UAAU,UAAU,MAAM,MAAM,UAAU,MAAM,KAAK;MACjE,MAAM,MAAM,IAAI,GAAG,MAAM,KAAK;CAGrC,QAAa,IAAI,CACf,OAAO,6CACP,OAAO,oDACT,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,sBAAsB;EAChD,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,kBAAkB,cAAc;EACvC,OAAO,KAAK,MAAM,MAAM,SAAS;GAC/B,KAAK,MAAM,UAAU,UAAU;IAC7B,MAAM,aAAa;IACnB,MAAM,gBAAgB;GACxB,CAAC;GACD,MAAM,IAAI,KAAK,KAAK;EACtB,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;;ACjCA,MAAa,eAAoC;CAC/C,MAAM;CACN,QAAQ,gBAAgB,EAAE,QAAQ,WAAW,UAAU,EAAE;AAC3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scenography/plugin-model",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Model plugin for scenography: external glTF/GLB models placed in the space.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -33,16 +33,16 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@scenography/scene": "0.4.1"
36
+ "@scenography/scene": "0.5.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/three": "^0.160.0",
40
40
  "three": "^0.160.0",
41
- "@scenography/engine": "0.4.1"
41
+ "@scenography/engine": "0.5.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "three": ">=0.160.0",
45
- "@scenography/engine": "0.4.1"
45
+ "@scenography/engine": "0.5.0"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsdown",