@scenography/plugin-model 0.2.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/data-CHJeJEc2.mjs +21 -0
- package/dist/data-CHJeJEc2.mjs.map +1 -0
- package/dist/data-tK2hlhyq.cjs +32 -0
- package/dist/data-tK2hlhyq.cjs.map +1 -0
- package/dist/data.cjs +4 -0
- package/dist/data.d.cts +2 -0
- package/dist/data.d.mts +2 -0
- package/dist/data.mjs +2 -0
- package/dist/index-B1oVLmLG.d.cts +39 -0
- package/dist/index-B1oVLmLG.d.mts +39 -0
- package/dist/index.cjs +43 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +39 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsProp, isFiniteNumber, isVec3, propIs, validate } from "@scenography/scene";
|
|
2
|
+
//#region src/data/validate.ts
|
|
3
|
+
const validateModel = (model) => validate([
|
|
4
|
+
existsProp("id", "Model is missing an id."),
|
|
5
|
+
existsProp("src", "Model is missing a src."),
|
|
6
|
+
propIs("position", isVec3, "position must be a [x, y, z] triple."),
|
|
7
|
+
propIs("rotation", isVec3, "rotation must be a [x, y, z] triple."),
|
|
8
|
+
propIs("scale", (v) => isFiniteNumber(v) || isVec3(v), "scale must be a number or a [x, y, z] triple.")
|
|
9
|
+
])(model);
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/data/plugin.ts
|
|
12
|
+
/** The data half of the model plugin: owns the `models` scene key (a collection). */
|
|
13
|
+
const modelData = {
|
|
14
|
+
kind: "models",
|
|
15
|
+
cardinality: "many",
|
|
16
|
+
validate: (model) => validateModel(model)
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { validateModel as n, modelData as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=data-CHJeJEc2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-CHJeJEc2.mjs","names":[],"sources":["../src/data/validate.ts","../src/data/plugin.ts"],"sourcesContent":["import {\n existsProp,\n isFiniteNumber,\n isVec3,\n propIs,\n validate,\n type ValidationResult,\n} from \"@scenography/scene\";\n\nimport type { Model } from \"./model\";\n\nexport const validateModel = (model: Model): ValidationResult =>\n validate<Model>([\n existsProp(\"id\", \"Model is missing an id.\"),\n existsProp(\"src\", \"Model is missing a src.\"),\n propIs(\"position\", isVec3, \"position must be a [x, y, z] triple.\"),\n propIs(\"rotation\", isVec3, \"rotation must be a [x, y, z] triple.\"),\n propIs(\n \"scale\",\n (v) => isFiniteNumber(v) || isVec3(v),\n \"scale must be a number or a [x, y, z] triple.\",\n ),\n ])(model);\n","import type { DataPlugin } from \"@scenography/scene\";\n\nimport { validateModel } from \"./validate\";\nimport type { Model } from \"./model\";\n\n/** The data half of the model plugin: owns the `models` scene key (a collection). */\nexport const modelData: DataPlugin<Model> = {\n kind: \"models\",\n cardinality: \"many\",\n validate: (model) => validateModel(model),\n};\n"],"mappings":";;AAWA,MAAa,iBAAiB,UAC5B,SAAgB;CACd,WAAW,MAAM,yBAAyB;CAC1C,WAAW,OAAO,yBAAyB;CAC3C,OAAO,YAAY,QAAQ,sCAAsC;CACjE,OAAO,YAAY,QAAQ,sCAAsC;CACjE,OACE,UACC,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,GACpC,+CACF;AACF,CAAC,CAAC,CAAC,KAAK;;;;AChBV,MAAa,YAA+B;CAC1C,MAAM;CACN,aAAa;CACb,WAAW,UAAU,cAAc,KAAK;AAC1C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
let _scenography_scene = require("@scenography/scene");
|
|
2
|
+
//#region src/data/validate.ts
|
|
3
|
+
const validateModel = (model) => (0, _scenography_scene.validate)([
|
|
4
|
+
(0, _scenography_scene.existsProp)("id", "Model is missing an id."),
|
|
5
|
+
(0, _scenography_scene.existsProp)("src", "Model is missing a src."),
|
|
6
|
+
(0, _scenography_scene.propIs)("position", _scenography_scene.isVec3, "position must be a [x, y, z] triple."),
|
|
7
|
+
(0, _scenography_scene.propIs)("rotation", _scenography_scene.isVec3, "rotation must be a [x, y, z] triple."),
|
|
8
|
+
(0, _scenography_scene.propIs)("scale", (v) => (0, _scenography_scene.isFiniteNumber)(v) || (0, _scenography_scene.isVec3)(v), "scale must be a number or a [x, y, z] triple.")
|
|
9
|
+
])(model);
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/data/plugin.ts
|
|
12
|
+
/** The data half of the model plugin: owns the `models` scene key (a collection). */
|
|
13
|
+
const modelData = {
|
|
14
|
+
kind: "models",
|
|
15
|
+
cardinality: "many",
|
|
16
|
+
validate: (model) => validateModel(model)
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, "modelData", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return modelData;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "validateModel", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return validateModel;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=data-tK2hlhyq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-tK2hlhyq.cjs","names":["isVec3"],"sources":["../src/data/validate.ts","../src/data/plugin.ts"],"sourcesContent":["import {\n existsProp,\n isFiniteNumber,\n isVec3,\n propIs,\n validate,\n type ValidationResult,\n} from \"@scenography/scene\";\n\nimport type { Model } from \"./model\";\n\nexport const validateModel = (model: Model): ValidationResult =>\n validate<Model>([\n existsProp(\"id\", \"Model is missing an id.\"),\n existsProp(\"src\", \"Model is missing a src.\"),\n propIs(\"position\", isVec3, \"position must be a [x, y, z] triple.\"),\n propIs(\"rotation\", isVec3, \"rotation must be a [x, y, z] triple.\"),\n propIs(\n \"scale\",\n (v) => isFiniteNumber(v) || isVec3(v),\n \"scale must be a number or a [x, y, z] triple.\",\n ),\n ])(model);\n","import type { DataPlugin } from \"@scenography/scene\";\n\nimport { validateModel } from \"./validate\";\nimport type { Model } from \"./model\";\n\n/** The data half of the model plugin: owns the `models` scene key (a collection). */\nexport const modelData: DataPlugin<Model> = {\n kind: \"models\",\n cardinality: \"many\",\n validate: (model) => validateModel(model),\n};\n"],"mappings":";;AAWA,MAAa,iBAAiB,WAAA,GAAA,mBAAA,SAAA,CACZ;oCACH,MAAM,yBAAyB;oCAC/B,OAAO,yBAAyB;gCACpC,YAAYA,mBAAAA,QAAQ,sCAAsC;gCAC1D,YAAYA,mBAAAA,QAAQ,sCAAsC;gCAE/D,UACC,OAAA,GAAA,mBAAA,eAAA,CAAqB,CAAC,MAAA,GAAA,mBAAA,OAAA,CAAY,CAAC,GACpC,+CACF;AACF,CAAC,CAAC,CAAC,KAAK;;;;AChBV,MAAa,YAA+B;CAC1C,MAAM;CACN,aAAa;CACb,WAAW,UAAU,cAAc,KAAK;AAC1C"}
|
package/dist/data.cjs
ADDED
package/dist/data.d.cts
ADDED
package/dist/data.d.mts
ADDED
package/dist/data.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DataPlugin, ValidationResult, Vec3 } from "@scenography/scene";
|
|
2
|
+
|
|
3
|
+
//#region src/data/model.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An external 3D model placed in the space — a glTF/GLB asset (chairs, plinths,
|
|
6
|
+
* sculptures…). Pure data: the URL plus a transform. The runtime loads the file
|
|
7
|
+
* and materializes it; relative URIs inside the glTF (`.bin`, textures) resolve
|
|
8
|
+
* against `src`.
|
|
9
|
+
*
|
|
10
|
+
* Note on units: glTF files are authored in meters, while scenes here use
|
|
11
|
+
* centimeter-ish world units. Use `scale` (e.g. `100`) to bridge the two.
|
|
12
|
+
*/
|
|
13
|
+
interface Model {
|
|
14
|
+
id: string;
|
|
15
|
+
/** URL of the glTF/GLB file. */
|
|
16
|
+
src: string;
|
|
17
|
+
/** World position `[x, y, z]`. Defaults to the origin. */
|
|
18
|
+
position?: Vec3;
|
|
19
|
+
/** Rotation in radians `[x, y, z]`. Defaults to no rotation. */
|
|
20
|
+
rotation?: Vec3;
|
|
21
|
+
/** Uniform scale (number) or per-axis `[x, y, z]`. Defaults to `1`. */
|
|
22
|
+
scale?: number | Vec3;
|
|
23
|
+
}
|
|
24
|
+
declare module "@scenography/scene" {
|
|
25
|
+
interface Scene {
|
|
26
|
+
/** External 3D models (glTF/GLB) placed in the space — from `@scenography/plugin-model`. */
|
|
27
|
+
models?: Model[];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/data/validate.d.ts
|
|
32
|
+
declare const validateModel: (model: Model) => ValidationResult;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/data/plugin.d.ts
|
|
35
|
+
/** The data half of the model plugin: owns the `models` scene key (a collection). */
|
|
36
|
+
declare const modelData: DataPlugin<Model>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { validateModel as n, Model as r, modelData as t };
|
|
39
|
+
//# sourceMappingURL=index-B1oVLmLG.d.cts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DataPlugin, ValidationResult, Vec3 } from "@scenography/scene";
|
|
2
|
+
|
|
3
|
+
//#region src/data/model.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An external 3D model placed in the space — a glTF/GLB asset (chairs, plinths,
|
|
6
|
+
* sculptures…). Pure data: the URL plus a transform. The runtime loads the file
|
|
7
|
+
* and materializes it; relative URIs inside the glTF (`.bin`, textures) resolve
|
|
8
|
+
* against `src`.
|
|
9
|
+
*
|
|
10
|
+
* Note on units: glTF files are authored in meters, while scenes here use
|
|
11
|
+
* centimeter-ish world units. Use `scale` (e.g. `100`) to bridge the two.
|
|
12
|
+
*/
|
|
13
|
+
interface Model {
|
|
14
|
+
id: string;
|
|
15
|
+
/** URL of the glTF/GLB file. */
|
|
16
|
+
src: string;
|
|
17
|
+
/** World position `[x, y, z]`. Defaults to the origin. */
|
|
18
|
+
position?: Vec3;
|
|
19
|
+
/** Rotation in radians `[x, y, z]`. Defaults to no rotation. */
|
|
20
|
+
rotation?: Vec3;
|
|
21
|
+
/** Uniform scale (number) or per-axis `[x, y, z]`. Defaults to `1`. */
|
|
22
|
+
scale?: number | Vec3;
|
|
23
|
+
}
|
|
24
|
+
declare module "@scenography/scene" {
|
|
25
|
+
interface Scene {
|
|
26
|
+
/** External 3D models (glTF/GLB) placed in the space — from `@scenography/plugin-model`. */
|
|
27
|
+
models?: Model[];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/data/validate.d.ts
|
|
32
|
+
declare const validateModel: (model: Model) => ValidationResult;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/data/plugin.d.ts
|
|
35
|
+
/** The data half of the model plugin: owns the `models` scene key (a collection). */
|
|
36
|
+
declare const modelData: DataPlugin<Model>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { validateModel as n, Model as r, modelData as t };
|
|
39
|
+
//# sourceMappingURL=index-B1oVLmLG.d.mts.map
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_data = require("./data-tK2hlhyq.cjs");
|
|
3
|
+
let three = require("three");
|
|
4
|
+
//#region src/buildModel.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build the three.js object for an external `Model`. Returns an empty `Group`
|
|
7
|
+
* with the transform applied immediately; the glTF/GLB is fetched async and its
|
|
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.
|
|
10
|
+
*/
|
|
11
|
+
function buildModel(model) {
|
|
12
|
+
const group = new three.Group();
|
|
13
|
+
group.name = `model:${model.id}`;
|
|
14
|
+
group.userData.scenographyId = model.id;
|
|
15
|
+
if (model.position) group.position.set(...model.position);
|
|
16
|
+
if (model.rotation) group.rotation.set(...model.rotation);
|
|
17
|
+
if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
|
|
18
|
+
else group.scale.set(...model.scale);
|
|
19
|
+
import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
|
|
20
|
+
new GLTFLoader().load(model.src, (gltf) => {
|
|
21
|
+
gltf.scene.traverse((child) => {
|
|
22
|
+
child.castShadow = true;
|
|
23
|
+
child.receiveShadow = true;
|
|
24
|
+
});
|
|
25
|
+
group.add(gltf.scene);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return group;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/plugin.ts
|
|
32
|
+
/** The model plugin: places each external glTF/GLB `Model` in the scene. */
|
|
33
|
+
const model = () => ({
|
|
34
|
+
data: require_data.modelData,
|
|
35
|
+
build: (definition) => ({ object: buildModel(definition) })
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.buildModel = buildModel;
|
|
39
|
+
exports.model = model;
|
|
40
|
+
exports.modelData = require_data.modelData;
|
|
41
|
+
exports.validateModel = require_data.validateModel;
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as validateModel, r as Model, t as modelData } from "./index-B1oVLmLG.cjs";
|
|
2
|
+
import { EnginePlugin } from "@scenography/engine";
|
|
3
|
+
import { Object3D } from "three";
|
|
4
|
+
|
|
5
|
+
//#region src/plugin.d.ts
|
|
6
|
+
/** The model plugin: places each external glTF/GLB `Model` in the scene. */
|
|
7
|
+
declare const model: () => EnginePlugin<Model>;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/buildModel.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Build the three.js object for an external `Model`. Returns an empty `Group`
|
|
12
|
+
* with the transform applied immediately; the glTF/GLB is fetched async and its
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
declare function buildModel(model: Model): Object3D;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type Model, buildModel, model, modelData, validateModel };
|
|
19
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as validateModel, r as Model, t as modelData } from "./index-B1oVLmLG.mjs";
|
|
2
|
+
import { Object3D } from "three";
|
|
3
|
+
import { EnginePlugin } from "@scenography/engine";
|
|
4
|
+
|
|
5
|
+
//#region src/plugin.d.ts
|
|
6
|
+
/** The model plugin: places each external glTF/GLB `Model` in the scene. */
|
|
7
|
+
declare const model: () => EnginePlugin<Model>;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/buildModel.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Build the three.js object for an external `Model`. Returns an empty `Group`
|
|
12
|
+
* with the transform applied immediately; the glTF/GLB is fetched async and its
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
declare function buildModel(model: Model): Object3D;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { type Model, buildModel, model, modelData, validateModel };
|
|
19
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { n as validateModel, t as modelData } from "./data-CHJeJEc2.mjs";
|
|
2
|
+
import { Group } from "three";
|
|
3
|
+
//#region src/buildModel.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build the three.js object for an external `Model`. Returns an empty `Group`
|
|
6
|
+
* with the transform applied immediately; the glTF/GLB is fetched async and its
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
function buildModel(model) {
|
|
11
|
+
const group = new Group();
|
|
12
|
+
group.name = `model:${model.id}`;
|
|
13
|
+
group.userData.scenographyId = model.id;
|
|
14
|
+
if (model.position) group.position.set(...model.position);
|
|
15
|
+
if (model.rotation) group.rotation.set(...model.rotation);
|
|
16
|
+
if (model.scale !== void 0) if (typeof model.scale === "number") group.scale.setScalar(model.scale);
|
|
17
|
+
else group.scale.set(...model.scale);
|
|
18
|
+
import("three/examples/jsm/loaders/GLTFLoader.js").then(({ GLTFLoader }) => {
|
|
19
|
+
new GLTFLoader().load(model.src, (gltf) => {
|
|
20
|
+
gltf.scene.traverse((child) => {
|
|
21
|
+
child.castShadow = true;
|
|
22
|
+
child.receiveShadow = true;
|
|
23
|
+
});
|
|
24
|
+
group.add(gltf.scene);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return group;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/plugin.ts
|
|
31
|
+
/** The model plugin: places each external glTF/GLB `Model` in the scene. */
|
|
32
|
+
const model = () => ({
|
|
33
|
+
data: modelData,
|
|
34
|
+
build: (definition) => ({ object: buildModel(definition) })
|
|
35
|
+
});
|
|
36
|
+
//#endregion
|
|
37
|
+
export { buildModel, model, modelData, validateModel };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scenography/plugin-model",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Model plugin for scenography: external glTF/GLB models placed in the space.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"./data": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/data.d.mts",
|
|
27
|
+
"default": "./dist/data.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/data.d.cts",
|
|
31
|
+
"default": "./dist/data.cjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@scenography/scene": "0.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/three": "^0.160.0",
|
|
40
|
+
"three": "^0.160.0",
|
|
41
|
+
"@scenography/engine": "0.2.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"three": ">=0.160.0",
|
|
45
|
+
"@scenography/engine": "0.2.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"dev": "tsdown --watch",
|
|
50
|
+
"typecheck": "tsc --noEmit"
|
|
51
|
+
}
|
|
52
|
+
}
|