@scenography/plugin-model 0.4.1 → 0.6.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
@@ -1,12 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_data = require("./data-tK2hlhyq.cjs");
3
3
  let three = require("three");
4
+ let _scenography_engine = require("@scenography/engine");
4
5
  //#region src/buildModel.ts
5
6
  /**
6
7
  * Build the three.js object for an external `Model`. Returns an empty `Group`
7
8
  * with the transform applied immediately; the glTF/GLB is fetched async and its
8
9
  * 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.
10
+ * imported on demand so it only ships in the bundle when a scene uses models;
11
+ * the meshopt decoder rides along so `EXT_meshopt_compression` models load, and
12
+ * the shared KTX2 loader handles `KHR_texture_basisu` maps.
10
13
  */
11
14
  function buildModel(model) {
12
15
  const group = new three.Group();
@@ -16,8 +19,16 @@ function buildModel(model) {
16
19
  if (model.rotation) group.rotation.set(...model.rotation);
17
20
  if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
18
21
  else group.scale.set(...model.scale);
19
- import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
20
- new GLTFLoader().load(model.src, (gltf) => {
22
+ const ktx2 = (0, _scenography_engine.getKtx2Loader)();
23
+ Promise.all([
24
+ import("three/examples/jsm/loaders/GLTFLoader.js"),
25
+ import("three/examples/jsm/libs/meshopt_decoder.module.js"),
26
+ ktx2 ?? Promise.resolve(null)
27
+ ]).then(([{ GLTFLoader }, { MeshoptDecoder }, ktx2Loader]) => {
28
+ const loader = new GLTFLoader();
29
+ loader.setMeshoptDecoder(MeshoptDecoder);
30
+ if (ktx2Loader) loader.setKTX2Loader(ktx2Loader);
31
+ loader.load(model.src, (gltf) => {
21
32
  gltf.scene.traverse((child) => {
22
33
  child.castShadow = true;
23
34
  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\";\nimport { getKtx2Loader } from \"@scenography/engine\";\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, and\n * the shared KTX2 loader handles `KHR_texture_basisu` maps.\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 const ktx2 = getKtx2Loader();\n void Promise.all([\n import(\"three/examples/jsm/loaders/GLTFLoader.js\"),\n import(\"three/examples/jsm/libs/meshopt_decoder.module.js\"),\n ktx2 ?? Promise.resolve(null),\n ]).then(([{ GLTFLoader }, { MeshoptDecoder }, ktx2Loader]) => {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n if (ktx2Loader) loader.setKTX2Loader(ktx2Loader as Parameters<typeof loader.setKTX2Loader>[0]);\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":";;;;;;;;;;;;;AAaA,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,MAAM,QAAA,GAAA,oBAAA,cAAA,CAAqB;CAC3B,QAAa,IAAI;EACf,OAAO;EACP,OAAO;EACP,QAAQ,QAAQ,QAAQ,IAAI;CAC9B,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,kBAAkB,gBAAgB;EAC5D,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,kBAAkB,cAAc;EACvC,IAAI,YAAY,OAAO,cAAc,UAAwD;EAC7F,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;;;;ACtCA,MAAa,eAAoC;CAC/C,MAAMC,aAAAA;CACN,QAAQ,gBAAgB,EAAE,QAAQ,WAAW,UAAU,EAAE;AAC3D"}
package/dist/index.d.cts CHANGED
@@ -11,7 +11,9 @@ 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, and
16
+ * the shared KTX2 loader handles `KHR_texture_basisu` maps.
15
17
  */
16
18
  declare function buildModel(model: Model): Object3D;
17
19
  //#endregion
package/dist/index.d.mts CHANGED
@@ -11,7 +11,9 @@ 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, and
16
+ * the shared KTX2 loader handles `KHR_texture_basisu` maps.
15
17
  */
16
18
  declare function buildModel(model: Model): Object3D;
17
19
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,11 +1,14 @@
1
1
  import { n as validateModel, t as modelData } from "./data-CHJeJEc2.mjs";
2
2
  import { Group } from "three";
3
+ import { getKtx2Loader } from "@scenography/engine";
3
4
  //#region src/buildModel.ts
4
5
  /**
5
6
  * Build the three.js object for an external `Model`. Returns an empty `Group`
6
7
  * with the transform applied immediately; the glTF/GLB is fetched async and its
7
8
  * 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.
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, and
11
+ * the shared KTX2 loader handles `KHR_texture_basisu` maps.
9
12
  */
10
13
  function buildModel(model) {
11
14
  const group = new Group();
@@ -15,8 +18,16 @@ function buildModel(model) {
15
18
  if (model.rotation) group.rotation.set(...model.rotation);
16
19
  if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
17
20
  else group.scale.set(...model.scale);
18
- import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
19
- new GLTFLoader().load(model.src, (gltf) => {
21
+ const ktx2 = getKtx2Loader();
22
+ Promise.all([
23
+ import("three/examples/jsm/loaders/GLTFLoader.js"),
24
+ import("three/examples/jsm/libs/meshopt_decoder.module.js"),
25
+ ktx2 ?? Promise.resolve(null)
26
+ ]).then(([{ GLTFLoader }, { MeshoptDecoder }, ktx2Loader]) => {
27
+ const loader = new GLTFLoader();
28
+ loader.setMeshoptDecoder(MeshoptDecoder);
29
+ if (ktx2Loader) loader.setKTX2Loader(ktx2Loader);
30
+ loader.load(model.src, (gltf) => {
20
31
  gltf.scene.traverse((child) => {
21
32
  child.castShadow = true;
22
33
  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\";\nimport { getKtx2Loader } from \"@scenography/engine\";\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, and\n * the shared KTX2 loader handles `KHR_texture_basisu` maps.\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 const ktx2 = getKtx2Loader();\n void Promise.all([\n import(\"three/examples/jsm/loaders/GLTFLoader.js\"),\n import(\"three/examples/jsm/libs/meshopt_decoder.module.js\"),\n ktx2 ?? Promise.resolve(null),\n ]).then(([{ GLTFLoader }, { MeshoptDecoder }, ktx2Loader]) => {\n const loader = new GLTFLoader();\n loader.setMeshoptDecoder(MeshoptDecoder);\n if (ktx2Loader) loader.setKTX2Loader(ktx2Loader as Parameters<typeof loader.setKTX2Loader>[0]);\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":";;;;;;;;;;;;AAaA,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,MAAM,OAAO,cAAc;CAC3B,QAAa,IAAI;EACf,OAAO;EACP,OAAO;EACP,QAAQ,QAAQ,QAAQ,IAAI;CAC9B,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,kBAAkB,gBAAgB;EAC5D,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,kBAAkB,cAAc;EACvC,IAAI,YAAY,OAAO,cAAc,UAAwD;EAC7F,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;;;;ACtCA,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.6.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.6.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.6.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "three": ">=0.160.0",
45
- "@scenography/engine": "0.4.1"
45
+ "@scenography/engine": "0.6.0"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsdown",