@exodeui/react-3d 0.0.0-stage → 1.0.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/README.md +95 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +311 -0
- package/dist/src/AnimationEvaluator3D.d.ts +7 -0
- package/dist/src/Exode3DCanvas.d.ts +16 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/types.d.ts +133 -0
- package/dist/src/useExode3D.d.ts +10 -0
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@exodeui/react-3d`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Official 3D React Runtime & Canvas component for the **ExodeUI** Motion Development Environment.
|
|
4
|
+
|
|
5
|
+
Embed interactive, hardware-accelerated 3D graphics, PBR materials, extruded vector art, and real-time keyframe animations in any React, Next.js, or Vite application with zero handoff.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @exodeui/react-3d three
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @exodeui/react-3d three
|
|
15
|
+
# or
|
|
16
|
+
yarn add @exodeui/react-3d three
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Quick Start
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { Exode3DCanvas } from '@exodeui/react-3d';
|
|
26
|
+
import sceneData from './scene.exode3d.json';
|
|
27
|
+
|
|
28
|
+
export function HeroScene() {
|
|
29
|
+
return (
|
|
30
|
+
<div style={{ width: '100%', height: '600px' }}>
|
|
31
|
+
<Exode3DCanvas
|
|
32
|
+
scene={sceneData}
|
|
33
|
+
interactive={true}
|
|
34
|
+
autoplay={true}
|
|
35
|
+
autoRotate={false}
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🎛️ Programmatic Control with `useExode3D`
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import React from 'react';
|
|
48
|
+
import { Exode3DCanvas, useExode3D } from '@exodeui/react-3d';
|
|
49
|
+
import sceneData from './scene.exode3d.json';
|
|
50
|
+
|
|
51
|
+
export function InteractiveDemo() {
|
|
52
|
+
const { onReady, play, pause, setCameraPosition } = useExode3D();
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div>
|
|
56
|
+
<div style={{ display: 'flex', gap: '8px', marginBottom: '12px' }}>
|
|
57
|
+
<button onClick={play}>Play</button>
|
|
58
|
+
<button onClick={pause}>Pause</button>
|
|
59
|
+
<button onClick={() => setCameraPosition({ x: 0, y: 10, z: 0 }, { x: 0, y: 0, z: 0 })}>
|
|
60
|
+
Top View
|
|
61
|
+
</button>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div style={{ width: '100%', height: '500px' }}>
|
|
65
|
+
<Exode3DCanvas
|
|
66
|
+
scene={sceneData}
|
|
67
|
+
onReady={onReady}
|
|
68
|
+
onClickNode={(nodeId) => console.log('Clicked 3D object:', nodeId)}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## ⚙️ Component Props
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Default | Description |
|
|
81
|
+
|---|---|---|---|
|
|
82
|
+
| `scene` | `Exode3DScene` | `undefined` | Scene JSON exported from Exode 3D Studio |
|
|
83
|
+
| `autoplay` | `boolean` | `true` | Automatically play keyframed tracks on mount |
|
|
84
|
+
| `autoRotate` | `boolean` | `false` | Continuous turntable rotation around the center |
|
|
85
|
+
| `autoRotateSpeed` | `number` | `2.0` | Turntable speed |
|
|
86
|
+
| `interactive` | `boolean` | `true` | Enable OrbitControls (drag to rotate, wheel to zoom) |
|
|
87
|
+
| `onReady` | `(controller) => void` | `undefined` | Callback receiving scene, camera, renderer & controls |
|
|
88
|
+
| `onClickNode` | `(nodeId, event) => void` | `undefined` | Click event on interactive 3D nodes |
|
|
89
|
+
| `onHoverNode` | `(nodeId \| null) => void` | `undefined` | Hover event on interactive 3D nodes |
|
|
90
|
+
| `className` | `string` | `undefined` | Custom CSS class name |
|
|
91
|
+
| `style` | `CSSProperties` | `undefined` | Custom inline styles for wrapper div |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 📜 License
|
|
96
|
+
MIT © ExodeUI
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index'
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(h,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("react/jsx-runtime"),require("react"),require("three"),require("three/addons/controls/OrbitControls.js"),require("three/addons/loaders/SVGLoader.js")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","three","three/addons/controls/OrbitControls.js","three/addons/loaders/SVGLoader.js"],P):(h=typeof globalThis<"u"?globalThis:h||self,P(h.ExodeUIReact3D={},h.jsxRuntime,h.React,h.THREE,h.OrbitControls_js,h.SVGLoader_js))})(this,(function(h,P,b,we,ye,F){"use strict";function ve(e){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const m in e)if(m!=="default"){const i=Object.getOwnPropertyDescriptor(e,m);Object.defineProperty(u,m,i.get?i:{enumerable:!0,get:()=>e[m]})}}return u.default=e,Object.freeze(u)}const s=ve(we);class _{static ease(u,m){const i=Math.max(0,Math.min(1,u));switch(m){case"easeInOutQuad":return i<.5?2*i*i:-1+(4-2*i)*i;case"easeInOutCubic":return i<.5?4*i*i*i:(i-1)*(2*i-2)*(2*i-2)+1;case"easeInOutSine":return-(Math.cos(Math.PI*i)-1)/2;case"spring":return Math.sin(i*Math.PI*2.5)*Math.exp(-i*3)+1;case"linear":default:return i}}static evaluateTrack(u,m){const i=u.keyframes;if(!i||i.length===0)return 0;if(i.length===1||m<=i[0].time)return i[0].value;if(m>=i[i.length-1].time)return i[i.length-1].value;for(let v=0;v<i.length-1;v++){const p=i[v],g=i[v+1];if(m>=p.time&&m<=g.time){const c=g.time-p.time;if(c<=0)return g.value;const C=(m-p.time)/c,S=this.ease(C,g.easing||"linear");return p.value+(g.value-p.value)*S}}return i[i.length-1].value}static evaluateScene(u,m){const i={},v=Array.isArray(u)?u:Object.values(u||{});for(const p of v){const g=p.targetNodeId;if(!g)continue;i[g]||(i[g]={});const c=p.duration||3,C=p.loop?m%c:Math.min(m,c);for(const S of p.tracks||[]){const j=this.evaluateTrack(S,C);i[g][S.property]=j}}return i}}const be=({scene:e,autoRotate:u=!1,autoRotateSpeed:m=2,interactive:i=!1,autoplay:v=!0,className:p,style:g,onReady:c,onClickNode:C,onHoverNode:S})=>{const j=b.useRef(null),xe=b.useRef(null);return b.useEffect(()=>{var J,K,D,ee,te,oe,re,ie,se,ne,ae,le,de,fe,me,ue,ce,he,pe;if(!j.current)return;const M=j.current,q=M.clientWidth||600,V=M.clientHeight||600,R=q/V,f=new s.WebGLRenderer({antialias:!0,alpha:!0,powerPreference:"high-performance"});f.setSize(q,V),f.setPixelRatio(Math.min(window.devicePixelRatio,2)),f.setClearColor(0,0),f.shadowMap.enabled=((J=e==null?void 0:e.lights)==null?void 0:J.shadows)??!0,f.shadowMap.type=s.PCFSoftShadowMap,f.outputColorSpace=s.SRGBColorSpace,M.appendChild(f.domElement);const y=new s.Scene;e!=null&&e.backgroundColor&&e.backgroundColor!=="transparent"?y.background=new s.Color(e.backgroundColor):y.background=null;const Me=((K=e==null?void 0:e.camera)==null?void 0:K.type)==="orthographic";let d;Me?d=new s.OrthographicCamera(-8*R,8*R,8,-8,((D=e==null?void 0:e.camera)==null?void 0:D.near)??.1,((ee=e==null?void 0:e.camera)==null?void 0:ee.far)??1e3):(d=new s.PerspectiveCamera(((te=e==null?void 0:e.camera)==null?void 0:te.fov)??45,R,((oe=e==null?void 0:e.camera)==null?void 0:oe.near)??.1,((re=e==null?void 0:e.camera)==null?void 0:re.far)??1e3),(ie=e==null?void 0:e.camera)!=null&&ie.focalLength&&d.setFocalLength(e.camera.focalLength)),(se=e==null?void 0:e.camera)!=null&&se.zoom&&(d.zoom=e.camera.zoom);const G=((ne=e==null?void 0:e.camera)==null?void 0:ne.position)||{x:5,y:4,z:8},z=((ae=e==null?void 0:e.camera)==null?void 0:ae.target)||{x:0,y:0,z:0};d.position.set(G.x,G.y,G.z),d.lookAt(z.x,z.y,z.z),d.updateProjectionMatrix();const w=new ye.OrbitControls(d,f.domElement);w.target.set(z.x,z.y,z.z),w.enableDamping=((le=e==null?void 0:e.camera)==null?void 0:le.enableDamping)??!0,w.dampingFactor=.05,w.autoRotate=u||((de=e==null?void 0:e.camera)==null?void 0:de.autoRotate)||!1,w.autoRotateSpeed=m||((fe=e==null?void 0:e.camera)==null?void 0:fe.autoRotateSpeed)||2,w.enabled=i,w.enableRotate=i,w.enablePan=i,w.enableZoom=i,w.update();const N=e!=null&&e.nodes?Object.values(e.nodes):[],W=N.filter(o=>o.type==="light"&&o.visible!==!1),O=new Map,k=new Map;if(W.length>0)for(const o of W){const t=o.lightConfig||{lightType:"point",color:"#ffffff",intensity:1},r=new s.Color(t.color||"#ffffff"),n=new s.Color(t.groundColor||"#444444");let l;if(t.lightType==="directional"){const a=new s.DirectionalLight(r,t.intensity??1.5);if(a.castShadow=t.castShadow??!0,a.shadow){a.shadow.bias=t.shadowBias??-5e-4;const x=t.shadowMapSize||1024;a.shadow.mapSize.set(x,x)}t.target&&(a.target.position.set(t.target.x,t.target.y,t.target.z),y.add(a.target)),l=a}else if(t.lightType==="point"){const a=new s.PointLight(r,t.intensity??1.5,t.distance??20,t.decay??2);if(a.castShadow=t.castShadow??!0,a.shadow){a.shadow.bias=t.shadowBias??-5e-4;const x=t.shadowMapSize||512;a.shadow.mapSize.set(x,x)}l=a}else if(t.lightType==="spot"){const a=new s.SpotLight(r,t.intensity??2,t.distance??25,t.angle??Math.PI/4,t.penumbra??.3);if(a.castShadow=t.castShadow??!0,a.shadow){a.shadow.bias=t.shadowBias??-5e-4;const x=t.shadowMapSize||1024;a.shadow.mapSize.set(x,x)}t.target&&(a.target.position.set(t.target.x,t.target.y,t.target.z),y.add(a.target)),l=a}else t.lightType==="hemisphere"?l=new s.HemisphereLight(r,n,t.intensity??1):t.lightType==="rectArea"?l=new s.RectAreaLight(r,t.intensity??2,4,4):l=new s.AmbientLight(r,t.intensity??.85);o.transform&&l.position.set(o.transform.position.x,o.transform.position.y,o.transform.position.z),l.userData={nodeId:o.id},y.add(l),O.set(o.id,l)}else{const o=new s.AmbientLight(16777215,((me=e==null?void 0:e.lights)==null?void 0:me.ambientIntensity)??.85);y.add(o);const t=new s.DirectionalLight(16777215,((ue=e==null?void 0:e.lights)==null?void 0:ue.directionalIntensity)??1.4),r=((ce=e==null?void 0:e.lights)==null?void 0:ce.directionalPosition)||{x:5,y:8,z:5};t.position.set(r.x,r.y,r.z),t.castShadow=((he=e==null?void 0:e.lights)==null?void 0:he.shadows)??!0,t.shadow.mapSize.width=1024,t.shadow.mapSize.height=1024,y.add(t);const n=new s.DirectionalLight(14412542,.4);n.position.set(-5,4,-5),y.add(n)}const ze=(e==null?void 0:e.materials)||{},H=(e==null?void 0:e.animations)||{},U=N.filter(o=>o.type!=="light"&&o.type!=="camera"&&o.visible!==!1);if(U.length===0){const o=new s.BoxGeometry(1.5,1.5,1.5),t=new s.MeshStandardMaterial({color:6514417,roughness:.3,metalness:.2}),r=new s.Mesh(o,t);r.castShadow=!0,r.receiveShadow=!0,y.add(r),k.set("default_cube",r),O.set("default_cube",r)}else for(const o of U){let t;if(o.type==="extruded_vector"&&((pe=o.extrudeConfig)!=null&&pe.svgPath))try{let a=o.extrudeConfig.svgPath.trim();a.startsWith("<svg")||(a=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"><path d="${a}" /></svg>`);const Ee=new F.SVGLoader().parse(a),ge=[];for(const Pe of Ee.paths)ge.push(...F.SVGLoader.createShapes(Pe));t=new s.ExtrudeGeometry(ge,{depth:o.extrudeConfig.depth||.4,bevelEnabled:o.extrudeConfig.bevelEnabled??!0,bevelThickness:o.extrudeConfig.bevelThickness??.05,bevelSize:o.extrudeConfig.bevelSize??.05,bevelSegments:o.extrudeConfig.bevelSegments??4,curveSegments:o.extrudeConfig.curveSegments??12}),t.center(),t.scale(.02,-.02,.02)}catch{t=new s.BoxGeometry(1,1,1)}else{const a=o.primitiveShape||"box";a==="sphere"?t=new s.SphereGeometry(.8,32,32):a==="cylinder"?t=new s.CylinderGeometry(.5,.5,1.2,32):a==="torus"?t=new s.TorusGeometry(.6,.25,24,48):a==="cone"?t=new s.ConeGeometry(.6,1.2,32):a==="capsule"?t=new s.CapsuleGeometry(.5,1,16,32):a==="plane"?t=new s.PlaneGeometry(2,2):t=new s.BoxGeometry(1,1,1)}const r=ze[o.materialId]||{color:"#6366f1"};let n;r.type==="glass"||r.transmission&&r.transmission>0?n=new s.MeshPhysicalMaterial({color:new s.Color(r.color||"#ffffff"),transmission:r.transmission??.9,roughness:r.roughness??.1,metalness:r.metalness??.1,transparent:!0,opacity:r.opacity??1,wireframe:r.wireframe??o.geometryMode==="wireframe"}):r.type==="neon"?n=new s.MeshStandardMaterial({color:new s.Color(r.color||"#38bdf8"),emissive:new s.Color(r.emissive||r.color||"#38bdf8"),emissiveIntensity:r.emissiveIntensity??1.5,roughness:r.roughness??.1,metalness:r.metalness??.1,wireframe:r.wireframe??o.geometryMode==="wireframe"}):r.type==="chrome"?n=new s.MeshStandardMaterial({color:new s.Color(r.color||"#ffffff"),roughness:.05,metalness:.95,wireframe:r.wireframe??o.geometryMode==="wireframe"}):r.type==="toon"?n=new s.MeshToonMaterial({color:new s.Color(r.color||"#6366f1"),wireframe:r.wireframe??o.geometryMode==="wireframe"}):n=new s.MeshStandardMaterial({color:new s.Color(r.color||"#6366f1"),roughness:r.roughness??.3,metalness:r.metalness??.2,transparent:r.transparent??!1,opacity:r.opacity??1,wireframe:r.wireframe??o.geometryMode==="wireframe"});const l=new s.Mesh(t,n);l.userData={nodeId:o.id},o.transform&&(l.position.set(o.transform.position.x,o.transform.position.y,o.transform.position.z),l.rotation.set(o.transform.rotation.x,o.transform.rotation.y,o.transform.rotation.z),l.scale.set(o.transform.scale.x,o.transform.scale.y,o.transform.scale.z)),l.castShadow=o.castShadow??!0,l.receiveShadow=o.receiveShadow??!0,y.add(l),k.set(o.id,l),O.set(o.id,l)}let A=v,L=0,T=0;const X={scene:y,camera:d,renderer:f,getNodeMesh:o=>O.get(o),play:()=>{A=!0,L=performance.now()/1e3-T},pause:()=>{A=!1,T=performance.now()/1e3-L},seek:o=>{T=o,L=performance.now()/1e3-o},setCameraPosition:(o,t)=>{d.position.set(o.x,o.y,o.z),t&&w.target.set(t.x,t.y,t.z),w.update()}};xe.current=X,c&&c(X);const I=new s.Raycaster,E=new s.Vector2,Y=o=>{var n;if(!C)return;const t=f.domElement.getBoundingClientRect();E.x=(o.clientX-t.left)/t.width*2-1,E.y=-((o.clientY-t.top)/t.height)*2+1,I.setFromCamera(E,d);const r=I.intersectObjects(Array.from(k.values()),!1);if(r.length>0){const a=(n=r[0].object.userData)==null?void 0:n.nodeId;a&&C(a,o)}},Q=o=>{var n;if(!S)return;const t=f.domElement.getBoundingClientRect();E.x=(o.clientX-t.left)/t.width*2-1,E.y=-((o.clientY-t.top)/t.height)*2+1,I.setFromCamera(E,d);const r=I.intersectObjects(Array.from(k.values()),!1);if(r.length>0){const l=((n=r[0].object.userData)==null?void 0:n.nodeId)||null;S(l)}else S(null)};f.domElement.addEventListener("click",Y),f.domElement.addEventListener("mousemove",Q);let B;const Z=()=>{const o=A?performance.now()/1e3-L:T;if(Object.keys(H).length>0){const t=_.evaluateScene(H,o);for(const[r,n]of Object.entries(t)){const l=O.get(r);l&&(n["position.x"]!==void 0&&(l.position.x=n["position.x"]),n["position.y"]!==void 0&&(l.position.y=n["position.y"]),n["position.z"]!==void 0&&(l.position.z=n["position.z"]),n["rotation.x"]!==void 0&&(l.rotation.x=n["rotation.x"]),n["rotation.y"]!==void 0&&(l.rotation.y=n["rotation.y"]),n["rotation.z"]!==void 0&&(l.rotation.z=n["rotation.z"]),n["scale.x"]!==void 0&&(l.scale.x=n["scale.x"]),n["scale.y"]!==void 0&&(l.scale.y=n["scale.y"]),n["scale.z"]!==void 0&&(l.scale.z=n["scale.z"]))}}w.update(),f.render(y,d),B=requestAnimationFrame(Z)};B=requestAnimationFrame(Z);const $=new ResizeObserver(()=>{const o=M.clientWidth,t=M.clientHeight;if(o===0||t===0)return;const r=o/t;d instanceof s.PerspectiveCamera?(d.aspect=r,d.updateProjectionMatrix()):d instanceof s.OrthographicCamera&&(d.left=-8*r,d.right=8*r,d.top=8,d.bottom=-8,d.updateProjectionMatrix()),f.setSize(o,t)});return $.observe(M),()=>{cancelAnimationFrame(B),$.disconnect(),f.domElement.removeEventListener("click",Y),f.domElement.removeEventListener("mousemove",Q),w.dispose(),f.dispose(),f.domElement.parentNode&&f.domElement.parentNode.removeChild(f.domElement)}},[e,u,m,i,v,C,S,c]),P.jsx("div",{ref:j,className:p,style:{width:"100%",height:"100%",position:"relative",overflow:"hidden",...g}})};function Ce(){const[e,u]=b.useState(null),m=b.useCallback(c=>{u(c)},[]),i=b.useCallback(()=>{e==null||e.play()},[e]),v=b.useCallback(()=>{e==null||e.pause()},[e]),p=b.useCallback(c=>{e==null||e.seek(c)},[e]),g=b.useCallback((c,C)=>{e==null||e.setCameraPosition(c,C)},[e]);return{controller:e,onReady:m,play:i,pause:v,seek:p,setCameraPosition:g}}const Se={version:"1.0.0"}.version;h.AnimationEvaluator3D=_,h.Exode3DCanvas=be,h.VERSION=Se,h.useExode3D=Ce,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { jsx as be } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as ue, useEffect as xe, useState as Ce, useCallback as E } from "react";
|
|
3
|
+
import * as i from "three";
|
|
4
|
+
import { OrbitControls as Se } from "three/addons/controls/OrbitControls.js";
|
|
5
|
+
import { SVGLoader as ce } from "three/addons/loaders/SVGLoader.js";
|
|
6
|
+
class ze {
|
|
7
|
+
static ease(g, d) {
|
|
8
|
+
const s = Math.max(0, Math.min(1, g));
|
|
9
|
+
switch (d) {
|
|
10
|
+
case "easeInOutQuad":
|
|
11
|
+
return s < 0.5 ? 2 * s * s : -1 + (4 - 2 * s) * s;
|
|
12
|
+
case "easeInOutCubic":
|
|
13
|
+
return s < 0.5 ? 4 * s * s * s : (s - 1) * (2 * s - 2) * (2 * s - 2) + 1;
|
|
14
|
+
case "easeInOutSine":
|
|
15
|
+
return -(Math.cos(Math.PI * s) - 1) / 2;
|
|
16
|
+
case "spring":
|
|
17
|
+
return Math.sin(s * Math.PI * 2.5) * Math.exp(-s * 3) + 1;
|
|
18
|
+
case "linear":
|
|
19
|
+
default:
|
|
20
|
+
return s;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static evaluateTrack(g, d) {
|
|
24
|
+
const s = g.keyframes;
|
|
25
|
+
if (!s || s.length === 0) return 0;
|
|
26
|
+
if (s.length === 1 || d <= s[0].time) return s[0].value;
|
|
27
|
+
if (d >= s[s.length - 1].time) return s[s.length - 1].value;
|
|
28
|
+
for (let y = 0; y < s.length - 1; y++) {
|
|
29
|
+
const u = s[y], c = s[y + 1];
|
|
30
|
+
if (d >= u.time && d <= c.time) {
|
|
31
|
+
const h = c.time - u.time;
|
|
32
|
+
if (h <= 0) return c.value;
|
|
33
|
+
const v = (d - u.time) / h, b = this.ease(v, c.easing || "linear");
|
|
34
|
+
return u.value + (c.value - u.value) * b;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return s[s.length - 1].value;
|
|
38
|
+
}
|
|
39
|
+
static evaluateScene(g, d) {
|
|
40
|
+
const s = {}, y = Array.isArray(g) ? g : Object.values(g || {});
|
|
41
|
+
for (const u of y) {
|
|
42
|
+
const c = u.targetNodeId;
|
|
43
|
+
if (!c) continue;
|
|
44
|
+
s[c] || (s[c] = {});
|
|
45
|
+
const h = u.duration || 3, v = u.loop ? d % h : Math.min(d, h);
|
|
46
|
+
for (const b of u.tracks || []) {
|
|
47
|
+
const M = this.evaluateTrack(b, v);
|
|
48
|
+
s[c][b.property] = M;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return s;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const Te = ({
|
|
55
|
+
scene: e,
|
|
56
|
+
autoRotate: g = !1,
|
|
57
|
+
autoRotateSpeed: d = 2,
|
|
58
|
+
interactive: s = !1,
|
|
59
|
+
autoplay: y = !0,
|
|
60
|
+
className: u,
|
|
61
|
+
style: c,
|
|
62
|
+
onReady: h,
|
|
63
|
+
onClickNode: v,
|
|
64
|
+
onHoverNode: b
|
|
65
|
+
}) => {
|
|
66
|
+
const M = ue(null), pe = ue(null);
|
|
67
|
+
return xe(() => {
|
|
68
|
+
var Q, U, Z, $, J, K, D, ee, te, oe, re, ie, se, ne, ae, le, me, fe, de;
|
|
69
|
+
if (!M.current) return;
|
|
70
|
+
const C = M.current, G = C.clientWidth || 600, B = C.clientHeight || 600, O = G / B, f = new i.WebGLRenderer({
|
|
71
|
+
antialias: !0,
|
|
72
|
+
alpha: !0,
|
|
73
|
+
powerPreference: "high-performance"
|
|
74
|
+
});
|
|
75
|
+
f.setSize(G, B), f.setPixelRatio(Math.min(window.devicePixelRatio, 2)), f.setClearColor(0, 0), f.shadowMap.enabled = ((Q = e == null ? void 0 : e.lights) == null ? void 0 : Q.shadows) ?? !0, f.shadowMap.type = i.PCFSoftShadowMap, f.outputColorSpace = i.SRGBColorSpace, C.appendChild(f.domElement);
|
|
76
|
+
const w = new i.Scene();
|
|
77
|
+
e != null && e.backgroundColor && e.backgroundColor !== "transparent" ? w.background = new i.Color(e.backgroundColor) : w.background = null;
|
|
78
|
+
const ge = ((U = e == null ? void 0 : e.camera) == null ? void 0 : U.type) === "orthographic";
|
|
79
|
+
let m;
|
|
80
|
+
ge ? m = new i.OrthographicCamera(
|
|
81
|
+
-8 * O,
|
|
82
|
+
8 * O,
|
|
83
|
+
8,
|
|
84
|
+
-8,
|
|
85
|
+
((Z = e == null ? void 0 : e.camera) == null ? void 0 : Z.near) ?? 0.1,
|
|
86
|
+
(($ = e == null ? void 0 : e.camera) == null ? void 0 : $.far) ?? 1e3
|
|
87
|
+
) : (m = new i.PerspectiveCamera(
|
|
88
|
+
((J = e == null ? void 0 : e.camera) == null ? void 0 : J.fov) ?? 45,
|
|
89
|
+
O,
|
|
90
|
+
((K = e == null ? void 0 : e.camera) == null ? void 0 : K.near) ?? 0.1,
|
|
91
|
+
((D = e == null ? void 0 : e.camera) == null ? void 0 : D.far) ?? 1e3
|
|
92
|
+
), (ee = e == null ? void 0 : e.camera) != null && ee.focalLength && m.setFocalLength(e.camera.focalLength)), (te = e == null ? void 0 : e.camera) != null && te.zoom && (m.zoom = e.camera.zoom);
|
|
93
|
+
const R = ((oe = e == null ? void 0 : e.camera) == null ? void 0 : oe.position) || { x: 5, y: 4, z: 8 }, S = ((re = e == null ? void 0 : e.camera) == null ? void 0 : re.target) || { x: 0, y: 0, z: 0 };
|
|
94
|
+
m.position.set(R.x, R.y, R.z), m.lookAt(S.x, S.y, S.z), m.updateProjectionMatrix();
|
|
95
|
+
const p = new Se(m, f.domElement);
|
|
96
|
+
p.target.set(S.x, S.y, S.z), p.enableDamping = ((ie = e == null ? void 0 : e.camera) == null ? void 0 : ie.enableDamping) ?? !0, p.dampingFactor = 0.05, p.autoRotate = g || ((se = e == null ? void 0 : e.camera) == null ? void 0 : se.autoRotate) || !1, p.autoRotateSpeed = d || ((ne = e == null ? void 0 : e.camera) == null ? void 0 : ne.autoRotateSpeed) || 2, p.enabled = s, p.enableRotate = s, p.enablePan = s, p.enableZoom = s, p.update();
|
|
97
|
+
const F = e != null && e.nodes ? Object.values(e.nodes) : [], W = F.filter((o) => o.type === "light" && o.visible !== !1), P = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map();
|
|
98
|
+
if (W.length > 0)
|
|
99
|
+
for (const o of W) {
|
|
100
|
+
const t = o.lightConfig || { lightType: "point", color: "#ffffff", intensity: 1 }, r = new i.Color(t.color || "#ffffff"), n = new i.Color(t.groundColor || "#444444");
|
|
101
|
+
let l;
|
|
102
|
+
if (t.lightType === "directional") {
|
|
103
|
+
const a = new i.DirectionalLight(r, t.intensity ?? 1.5);
|
|
104
|
+
if (a.castShadow = t.castShadow ?? !0, a.shadow) {
|
|
105
|
+
a.shadow.bias = t.shadowBias ?? -5e-4;
|
|
106
|
+
const x = t.shadowMapSize || 1024;
|
|
107
|
+
a.shadow.mapSize.set(x, x);
|
|
108
|
+
}
|
|
109
|
+
t.target && (a.target.position.set(t.target.x, t.target.y, t.target.z), w.add(a.target)), l = a;
|
|
110
|
+
} else if (t.lightType === "point") {
|
|
111
|
+
const a = new i.PointLight(r, t.intensity ?? 1.5, t.distance ?? 20, t.decay ?? 2);
|
|
112
|
+
if (a.castShadow = t.castShadow ?? !0, a.shadow) {
|
|
113
|
+
a.shadow.bias = t.shadowBias ?? -5e-4;
|
|
114
|
+
const x = t.shadowMapSize || 512;
|
|
115
|
+
a.shadow.mapSize.set(x, x);
|
|
116
|
+
}
|
|
117
|
+
l = a;
|
|
118
|
+
} else if (t.lightType === "spot") {
|
|
119
|
+
const a = new i.SpotLight(r, t.intensity ?? 2, t.distance ?? 25, t.angle ?? Math.PI / 4, t.penumbra ?? 0.3);
|
|
120
|
+
if (a.castShadow = t.castShadow ?? !0, a.shadow) {
|
|
121
|
+
a.shadow.bias = t.shadowBias ?? -5e-4;
|
|
122
|
+
const x = t.shadowMapSize || 1024;
|
|
123
|
+
a.shadow.mapSize.set(x, x);
|
|
124
|
+
}
|
|
125
|
+
t.target && (a.target.position.set(t.target.x, t.target.y, t.target.z), w.add(a.target)), l = a;
|
|
126
|
+
} else t.lightType === "hemisphere" ? l = new i.HemisphereLight(r, n, t.intensity ?? 1) : t.lightType === "rectArea" ? l = new i.RectAreaLight(r, t.intensity ?? 2, 4, 4) : l = new i.AmbientLight(r, t.intensity ?? 0.85);
|
|
127
|
+
o.transform && l.position.set(o.transform.position.x, o.transform.position.y, o.transform.position.z), l.userData = { nodeId: o.id }, w.add(l), P.set(o.id, l);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const o = new i.AmbientLight(16777215, ((ae = e == null ? void 0 : e.lights) == null ? void 0 : ae.ambientIntensity) ?? 0.85);
|
|
131
|
+
w.add(o);
|
|
132
|
+
const t = new i.DirectionalLight(16777215, ((le = e == null ? void 0 : e.lights) == null ? void 0 : le.directionalIntensity) ?? 1.4), r = ((me = e == null ? void 0 : e.lights) == null ? void 0 : me.directionalPosition) || { x: 5, y: 8, z: 5 };
|
|
133
|
+
t.position.set(r.x, r.y, r.z), t.castShadow = ((fe = e == null ? void 0 : e.lights) == null ? void 0 : fe.shadows) ?? !0, t.shadow.mapSize.width = 1024, t.shadow.mapSize.height = 1024, w.add(t);
|
|
134
|
+
const n = new i.DirectionalLight(14412542, 0.4);
|
|
135
|
+
n.position.set(-5, 4, -5), w.add(n);
|
|
136
|
+
}
|
|
137
|
+
const we = (e == null ? void 0 : e.materials) || {}, _ = (e == null ? void 0 : e.animations) || {}, V = F.filter((o) => o.type !== "light" && o.type !== "camera" && o.visible !== !1);
|
|
138
|
+
if (V.length === 0) {
|
|
139
|
+
const o = new i.BoxGeometry(1.5, 1.5, 1.5), t = new i.MeshStandardMaterial({ color: 6514417, roughness: 0.3, metalness: 0.2 }), r = new i.Mesh(o, t);
|
|
140
|
+
r.castShadow = !0, r.receiveShadow = !0, w.add(r), L.set("default_cube", r), P.set("default_cube", r);
|
|
141
|
+
} else
|
|
142
|
+
for (const o of V) {
|
|
143
|
+
let t;
|
|
144
|
+
if (o.type === "extruded_vector" && ((de = o.extrudeConfig) != null && de.svgPath))
|
|
145
|
+
try {
|
|
146
|
+
let a = o.extrudeConfig.svgPath.trim();
|
|
147
|
+
a.startsWith("<svg") || (a = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"><path d="${a}" /></svg>`);
|
|
148
|
+
const ye = new ce().parse(a), he = [];
|
|
149
|
+
for (const ve of ye.paths)
|
|
150
|
+
he.push(...ce.createShapes(ve));
|
|
151
|
+
t = new i.ExtrudeGeometry(he, {
|
|
152
|
+
depth: o.extrudeConfig.depth || 0.4,
|
|
153
|
+
bevelEnabled: o.extrudeConfig.bevelEnabled ?? !0,
|
|
154
|
+
bevelThickness: o.extrudeConfig.bevelThickness ?? 0.05,
|
|
155
|
+
bevelSize: o.extrudeConfig.bevelSize ?? 0.05,
|
|
156
|
+
bevelSegments: o.extrudeConfig.bevelSegments ?? 4,
|
|
157
|
+
curveSegments: o.extrudeConfig.curveSegments ?? 12
|
|
158
|
+
}), t.center(), t.scale(0.02, -0.02, 0.02);
|
|
159
|
+
} catch {
|
|
160
|
+
t = new i.BoxGeometry(1, 1, 1);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const a = o.primitiveShape || "box";
|
|
164
|
+
a === "sphere" ? t = new i.SphereGeometry(0.8, 32, 32) : a === "cylinder" ? t = new i.CylinderGeometry(0.5, 0.5, 1.2, 32) : a === "torus" ? t = new i.TorusGeometry(0.6, 0.25, 24, 48) : a === "cone" ? t = new i.ConeGeometry(0.6, 1.2, 32) : a === "capsule" ? t = new i.CapsuleGeometry(0.5, 1, 16, 32) : a === "plane" ? t = new i.PlaneGeometry(2, 2) : t = new i.BoxGeometry(1, 1, 1);
|
|
165
|
+
}
|
|
166
|
+
const r = we[o.materialId] || { color: "#6366f1" };
|
|
167
|
+
let n;
|
|
168
|
+
r.type === "glass" || r.transmission && r.transmission > 0 ? n = new i.MeshPhysicalMaterial({
|
|
169
|
+
color: new i.Color(r.color || "#ffffff"),
|
|
170
|
+
transmission: r.transmission ?? 0.9,
|
|
171
|
+
roughness: r.roughness ?? 0.1,
|
|
172
|
+
metalness: r.metalness ?? 0.1,
|
|
173
|
+
transparent: !0,
|
|
174
|
+
opacity: r.opacity ?? 1,
|
|
175
|
+
wireframe: r.wireframe ?? o.geometryMode === "wireframe"
|
|
176
|
+
}) : r.type === "neon" ? n = new i.MeshStandardMaterial({
|
|
177
|
+
color: new i.Color(r.color || "#38bdf8"),
|
|
178
|
+
emissive: new i.Color(r.emissive || r.color || "#38bdf8"),
|
|
179
|
+
emissiveIntensity: r.emissiveIntensity ?? 1.5,
|
|
180
|
+
roughness: r.roughness ?? 0.1,
|
|
181
|
+
metalness: r.metalness ?? 0.1,
|
|
182
|
+
wireframe: r.wireframe ?? o.geometryMode === "wireframe"
|
|
183
|
+
}) : r.type === "chrome" ? n = new i.MeshStandardMaterial({
|
|
184
|
+
color: new i.Color(r.color || "#ffffff"),
|
|
185
|
+
roughness: 0.05,
|
|
186
|
+
metalness: 0.95,
|
|
187
|
+
wireframe: r.wireframe ?? o.geometryMode === "wireframe"
|
|
188
|
+
}) : r.type === "toon" ? n = new i.MeshToonMaterial({
|
|
189
|
+
color: new i.Color(r.color || "#6366f1"),
|
|
190
|
+
wireframe: r.wireframe ?? o.geometryMode === "wireframe"
|
|
191
|
+
}) : n = new i.MeshStandardMaterial({
|
|
192
|
+
color: new i.Color(r.color || "#6366f1"),
|
|
193
|
+
roughness: r.roughness ?? 0.3,
|
|
194
|
+
metalness: r.metalness ?? 0.2,
|
|
195
|
+
transparent: r.transparent ?? !1,
|
|
196
|
+
opacity: r.opacity ?? 1,
|
|
197
|
+
wireframe: r.wireframe ?? o.geometryMode === "wireframe"
|
|
198
|
+
});
|
|
199
|
+
const l = new i.Mesh(t, n);
|
|
200
|
+
l.userData = { nodeId: o.id }, o.transform && (l.position.set(o.transform.position.x, o.transform.position.y, o.transform.position.z), l.rotation.set(o.transform.rotation.x, o.transform.rotation.y, o.transform.rotation.z), l.scale.set(o.transform.scale.x, o.transform.scale.y, o.transform.scale.z)), l.castShadow = o.castShadow ?? !0, l.receiveShadow = o.receiveShadow ?? !0, w.add(l), L.set(o.id, l), P.set(o.id, l);
|
|
201
|
+
}
|
|
202
|
+
let j = y, k = 0, I = 0;
|
|
203
|
+
const q = {
|
|
204
|
+
scene: w,
|
|
205
|
+
camera: m,
|
|
206
|
+
renderer: f,
|
|
207
|
+
getNodeMesh: (o) => P.get(o),
|
|
208
|
+
play: () => {
|
|
209
|
+
j = !0, k = performance.now() / 1e3 - I;
|
|
210
|
+
},
|
|
211
|
+
pause: () => {
|
|
212
|
+
j = !1, I = performance.now() / 1e3 - k;
|
|
213
|
+
},
|
|
214
|
+
seek: (o) => {
|
|
215
|
+
I = o, k = performance.now() / 1e3 - o;
|
|
216
|
+
},
|
|
217
|
+
setCameraPosition: (o, t) => {
|
|
218
|
+
m.position.set(o.x, o.y, o.z), t && p.target.set(t.x, t.y, t.z), p.update();
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
pe.current = q, h && h(q);
|
|
222
|
+
const T = new i.Raycaster(), z = new i.Vector2(), N = (o) => {
|
|
223
|
+
var n;
|
|
224
|
+
if (!v) return;
|
|
225
|
+
const t = f.domElement.getBoundingClientRect();
|
|
226
|
+
z.x = (o.clientX - t.left) / t.width * 2 - 1, z.y = -((o.clientY - t.top) / t.height) * 2 + 1, T.setFromCamera(z, m);
|
|
227
|
+
const r = T.intersectObjects(Array.from(L.values()), !1);
|
|
228
|
+
if (r.length > 0) {
|
|
229
|
+
const a = (n = r[0].object.userData) == null ? void 0 : n.nodeId;
|
|
230
|
+
a && v(a, o);
|
|
231
|
+
}
|
|
232
|
+
}, X = (o) => {
|
|
233
|
+
var n;
|
|
234
|
+
if (!b) return;
|
|
235
|
+
const t = f.domElement.getBoundingClientRect();
|
|
236
|
+
z.x = (o.clientX - t.left) / t.width * 2 - 1, z.y = -((o.clientY - t.top) / t.height) * 2 + 1, T.setFromCamera(z, m);
|
|
237
|
+
const r = T.intersectObjects(Array.from(L.values()), !1);
|
|
238
|
+
if (r.length > 0) {
|
|
239
|
+
const l = ((n = r[0].object.userData) == null ? void 0 : n.nodeId) || null;
|
|
240
|
+
b(l);
|
|
241
|
+
} else
|
|
242
|
+
b(null);
|
|
243
|
+
};
|
|
244
|
+
f.domElement.addEventListener("click", N), f.domElement.addEventListener("mousemove", X);
|
|
245
|
+
let A;
|
|
246
|
+
const Y = () => {
|
|
247
|
+
const o = j ? performance.now() / 1e3 - k : I;
|
|
248
|
+
if (Object.keys(_).length > 0) {
|
|
249
|
+
const t = ze.evaluateScene(_, o);
|
|
250
|
+
for (const [r, n] of Object.entries(t)) {
|
|
251
|
+
const l = P.get(r);
|
|
252
|
+
l && (n["position.x"] !== void 0 && (l.position.x = n["position.x"]), n["position.y"] !== void 0 && (l.position.y = n["position.y"]), n["position.z"] !== void 0 && (l.position.z = n["position.z"]), n["rotation.x"] !== void 0 && (l.rotation.x = n["rotation.x"]), n["rotation.y"] !== void 0 && (l.rotation.y = n["rotation.y"]), n["rotation.z"] !== void 0 && (l.rotation.z = n["rotation.z"]), n["scale.x"] !== void 0 && (l.scale.x = n["scale.x"]), n["scale.y"] !== void 0 && (l.scale.y = n["scale.y"]), n["scale.z"] !== void 0 && (l.scale.z = n["scale.z"]));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
p.update(), f.render(w, m), A = requestAnimationFrame(Y);
|
|
256
|
+
};
|
|
257
|
+
A = requestAnimationFrame(Y);
|
|
258
|
+
const H = new ResizeObserver(() => {
|
|
259
|
+
const o = C.clientWidth, t = C.clientHeight;
|
|
260
|
+
if (o === 0 || t === 0) return;
|
|
261
|
+
const r = o / t;
|
|
262
|
+
m instanceof i.PerspectiveCamera ? (m.aspect = r, m.updateProjectionMatrix()) : m instanceof i.OrthographicCamera && (m.left = -8 * r, m.right = 8 * r, m.top = 8, m.bottom = -8, m.updateProjectionMatrix()), f.setSize(o, t);
|
|
263
|
+
});
|
|
264
|
+
return H.observe(C), () => {
|
|
265
|
+
cancelAnimationFrame(A), H.disconnect(), f.domElement.removeEventListener("click", N), f.domElement.removeEventListener("mousemove", X), p.dispose(), f.dispose(), f.domElement.parentNode && f.domElement.parentNode.removeChild(f.domElement);
|
|
266
|
+
};
|
|
267
|
+
}, [e, g, d, s, y, v, b, h]), /* @__PURE__ */ be(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
ref: M,
|
|
271
|
+
className: u,
|
|
272
|
+
style: {
|
|
273
|
+
width: "100%",
|
|
274
|
+
height: "100%",
|
|
275
|
+
position: "relative",
|
|
276
|
+
overflow: "hidden",
|
|
277
|
+
...c
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
function Oe() {
|
|
283
|
+
const [e, g] = Ce(null), d = E((h) => {
|
|
284
|
+
g(h);
|
|
285
|
+
}, []), s = E(() => {
|
|
286
|
+
e == null || e.play();
|
|
287
|
+
}, [e]), y = E(() => {
|
|
288
|
+
e == null || e.pause();
|
|
289
|
+
}, [e]), u = E((h) => {
|
|
290
|
+
e == null || e.seek(h);
|
|
291
|
+
}, [e]), c = E((h, v) => {
|
|
292
|
+
e == null || e.setCameraPosition(h, v);
|
|
293
|
+
}, [e]);
|
|
294
|
+
return {
|
|
295
|
+
controller: e,
|
|
296
|
+
onReady: d,
|
|
297
|
+
play: s,
|
|
298
|
+
pause: y,
|
|
299
|
+
seek: u,
|
|
300
|
+
setCameraPosition: c
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const Me = "1.0.0", Pe = {
|
|
304
|
+
version: Me
|
|
305
|
+
}, Re = Pe.version;
|
|
306
|
+
export {
|
|
307
|
+
ze as AnimationEvaluator3D,
|
|
308
|
+
Te as Exode3DCanvas,
|
|
309
|
+
Re as VERSION,
|
|
310
|
+
Oe as useExode3D
|
|
311
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropertyTrack3D, Exode3DAnimation } from './types';
|
|
2
|
+
|
|
3
|
+
export declare class AnimationEvaluator3D {
|
|
4
|
+
static ease(t: number, type?: string): number;
|
|
5
|
+
static evaluateTrack(track: PropertyTrack3D, time: number): number;
|
|
6
|
+
static evaluateScene(animations: Record<string, Exode3DAnimation> | Exode3DAnimation[], time: number): Record<string, Record<string, number>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Exode3DScene, Exode3DController } from './types';
|
|
3
|
+
|
|
4
|
+
export interface Exode3DCanvasProps {
|
|
5
|
+
scene?: Exode3DScene | any;
|
|
6
|
+
autoRotate?: boolean;
|
|
7
|
+
autoRotateSpeed?: number;
|
|
8
|
+
interactive?: boolean;
|
|
9
|
+
autoplay?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
onReady?: (controller: Exode3DController) => void;
|
|
13
|
+
onClickNode?: (nodeId: string, event: MouseEvent) => void;
|
|
14
|
+
onHoverNode?: (nodeId: string | null) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const Exode3DCanvas: React.FC<Exode3DCanvasProps>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
export interface Vector3D {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
z: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Exode3DTransform {
|
|
8
|
+
position: Vector3D;
|
|
9
|
+
rotation: Vector3D;
|
|
10
|
+
scale: Vector3D;
|
|
11
|
+
}
|
|
12
|
+
export type PrimitiveShape = 'box' | 'sphere' | 'cylinder' | 'cone' | 'torus' | 'plane' | 'capsule';
|
|
13
|
+
export type LightType = 'ambient' | 'directional' | 'point' | 'spot' | 'hemisphere' | 'rectArea';
|
|
14
|
+
export interface LightConfig {
|
|
15
|
+
lightType: LightType;
|
|
16
|
+
color: string;
|
|
17
|
+
groundColor?: string;
|
|
18
|
+
intensity: number;
|
|
19
|
+
distance?: number;
|
|
20
|
+
decay?: number;
|
|
21
|
+
angle?: number;
|
|
22
|
+
penumbra?: number;
|
|
23
|
+
castShadow?: boolean;
|
|
24
|
+
shadowBias?: number;
|
|
25
|
+
shadowRadius?: number;
|
|
26
|
+
shadowMapSize?: number;
|
|
27
|
+
showHelper?: boolean;
|
|
28
|
+
target?: Vector3D;
|
|
29
|
+
}
|
|
30
|
+
export type CameraType = 'perspective' | 'orthographic';
|
|
31
|
+
export type CameraControlsMode = 'orbit' | 'pan' | 'locked';
|
|
32
|
+
export interface CameraConfig {
|
|
33
|
+
type?: CameraType;
|
|
34
|
+
fov?: number;
|
|
35
|
+
near?: number;
|
|
36
|
+
far?: number;
|
|
37
|
+
focalLength?: number;
|
|
38
|
+
zoom?: number;
|
|
39
|
+
position: Vector3D;
|
|
40
|
+
target: Vector3D;
|
|
41
|
+
controlsMode?: CameraControlsMode;
|
|
42
|
+
autoRotate?: boolean;
|
|
43
|
+
autoRotateSpeed?: number;
|
|
44
|
+
enableDamping?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ExtrudeConfig {
|
|
47
|
+
svgPath: string;
|
|
48
|
+
depth?: number;
|
|
49
|
+
bevelEnabled?: boolean;
|
|
50
|
+
bevelThickness?: number;
|
|
51
|
+
bevelSize?: number;
|
|
52
|
+
bevelSegments?: number;
|
|
53
|
+
curveSegments?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface Exode3DMaterial {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
type: 'standard' | 'physical' | 'glass' | 'chrome' | 'toon' | 'neon';
|
|
59
|
+
color: string;
|
|
60
|
+
roughness?: number;
|
|
61
|
+
metalness?: number;
|
|
62
|
+
transmission?: number;
|
|
63
|
+
emissive?: string;
|
|
64
|
+
emissiveIntensity?: number;
|
|
65
|
+
opacity?: number;
|
|
66
|
+
transparent?: boolean;
|
|
67
|
+
wireframe?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface Exode3DNode {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
type: 'primitive' | 'extruded_vector' | 'compound' | 'light' | 'camera' | 'model_3d' | 'group' | 'text3d';
|
|
73
|
+
primitiveShape?: PrimitiveShape;
|
|
74
|
+
geometryMode?: 'solid' | 'wireframe' | 'points' | 'glass';
|
|
75
|
+
extrudeConfig?: ExtrudeConfig;
|
|
76
|
+
lightConfig?: LightConfig;
|
|
77
|
+
compoundConfig?: any;
|
|
78
|
+
model3dConfig?: any;
|
|
79
|
+
transform: Exode3DTransform;
|
|
80
|
+
materialId: string;
|
|
81
|
+
visible: boolean;
|
|
82
|
+
locked?: boolean;
|
|
83
|
+
castShadow?: boolean;
|
|
84
|
+
receiveShadow?: boolean;
|
|
85
|
+
}
|
|
86
|
+
export interface Keyframe3D {
|
|
87
|
+
time: number;
|
|
88
|
+
value: number;
|
|
89
|
+
easing?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface PropertyTrack3D {
|
|
92
|
+
property: string;
|
|
93
|
+
keyframes: Keyframe3D[];
|
|
94
|
+
}
|
|
95
|
+
export interface Exode3DAnimation {
|
|
96
|
+
id: string;
|
|
97
|
+
name: string;
|
|
98
|
+
targetNodeId: string;
|
|
99
|
+
duration: number;
|
|
100
|
+
loop: boolean;
|
|
101
|
+
autoplay: boolean;
|
|
102
|
+
tracks: PropertyTrack3D[];
|
|
103
|
+
}
|
|
104
|
+
export interface Exode3DScene {
|
|
105
|
+
version: string;
|
|
106
|
+
name: string;
|
|
107
|
+
backgroundColor?: string;
|
|
108
|
+
environment?: {
|
|
109
|
+
preset?: string;
|
|
110
|
+
intensity?: number;
|
|
111
|
+
};
|
|
112
|
+
lights?: {
|
|
113
|
+
ambientIntensity?: number;
|
|
114
|
+
directionalIntensity?: number;
|
|
115
|
+
directionalColor?: string;
|
|
116
|
+
directionalPosition?: Vector3D;
|
|
117
|
+
shadows?: boolean;
|
|
118
|
+
};
|
|
119
|
+
camera?: CameraConfig;
|
|
120
|
+
nodes: Record<string, Exode3DNode>;
|
|
121
|
+
materials: Record<string, Exode3DMaterial>;
|
|
122
|
+
animations?: Record<string, Exode3DAnimation>;
|
|
123
|
+
}
|
|
124
|
+
export interface Exode3DController {
|
|
125
|
+
scene: THREE.Scene;
|
|
126
|
+
camera: THREE.PerspectiveCamera | THREE.OrthographicCamera;
|
|
127
|
+
renderer: THREE.WebGLRenderer;
|
|
128
|
+
getNodeMesh: (nodeId: string) => THREE.Object3D | undefined;
|
|
129
|
+
play: () => void;
|
|
130
|
+
pause: () => void;
|
|
131
|
+
seek: (time: number) => void;
|
|
132
|
+
setCameraPosition: (pos: Vector3D, lookAt?: Vector3D) => void;
|
|
133
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Exode3DController, Vector3D } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function useExode3D(): {
|
|
4
|
+
controller: Exode3DController | null;
|
|
5
|
+
onReady: (ctrl: Exode3DController) => void;
|
|
6
|
+
play: () => void;
|
|
7
|
+
pause: () => void;
|
|
8
|
+
seek: (time: number) => void;
|
|
9
|
+
setCameraPosition: (pos: Vector3D, lookAt?: Vector3D) => void;
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodeui/react-3d",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official 3D React Runtime & Canvas for ExodeUI Motion Engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"dev": "vite build --watch"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=16.8.0",
|
|
26
|
+
"react-dom": ">=16.8.0",
|
|
27
|
+
"three": ">=0.150.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^25.0.9",
|
|
31
|
+
"@types/react": "^19.0.0",
|
|
32
|
+
"@types/react-dom": "^19.0.0",
|
|
33
|
+
"@types/three": "^0.186.0",
|
|
34
|
+
"react": "^19.0.0",
|
|
35
|
+
"react-dom": "^19.0.0",
|
|
36
|
+
"three": "^0.186.0",
|
|
37
|
+
"typescript": "^5.0.0",
|
|
38
|
+
"vite": "^6.0.0",
|
|
39
|
+
"vite-plugin-dts": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"three": "^0.186.0"
|
|
43
|
+
}
|
|
44
|
+
}
|