three-live 0.0.1-alpha.0 → 1.1.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/LICENSE +202 -0
- package/README.md +58 -0
- package/dist/index.d.ts +224 -0
- package/dist/three-author-engine.js +292 -0
- package/dist/three-author.cjs +292 -0
- package/dist/three-author.d.ts +224 -0
- package/dist/three-author.js +292 -0
- package/dist/three-convert.cjs +286 -0
- package/dist/three-convert.d.ts +224 -0
- package/dist/three-convert.js +286 -0
- package/dist/three-live-animation.cjs +36 -0
- package/dist/three-live-animation.d.ts +224 -0
- package/dist/three-live-animation.js +36 -0
- package/dist/three-live-animation.min.js +36 -0
- package/dist/three-live-element.cjs +217 -0
- package/dist/three-live-element.d.ts +224 -0
- package/dist/three-live-element.js +217 -0
- package/dist/three-live-extras.cjs +42 -0
- package/dist/three-live-extras.d.ts +224 -0
- package/dist/three-live-extras.js +42 -0
- package/dist/three-live-extras.min.js +42 -0
- package/dist/three-live-full.cjs +336 -0
- package/dist/three-live-full.js +336 -0
- package/dist/three-live-full.min.js +336 -0
- package/dist/three-live-sandbox.html +157 -0
- package/dist/three-live-viewer.cjs +217 -0
- package/dist/three-live-viewer.d.ts +224 -0
- package/dist/three-live-viewer.js +217 -0
- package/dist/three-live-viewer.min.js +217 -0
- package/dist/three-live.cjs +294 -0
- package/dist/three-live.js +294 -0
- package/dist/three-live.min.js +294 -0
- package/dist/three-view.cjs +217 -0
- package/dist/three-view.d.ts +224 -0
- package/dist/three-view.js +217 -0
- package/dist/three-xr.cjs +286 -0
- package/dist/three-xr.d.ts +224 -0
- package/dist/three-xr.js +286 -0
- package/package.json +78 -6
- package/index.js +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Ambient and module declarations for three-live and xr-live.
|
|
17
|
+
* Enables zero-config, type-safe usage of <three-live> and <xr-live> in React 19,
|
|
18
|
+
* Next.js, Vue, Svelte, and modern TSX/JSX environments.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
CameraState,
|
|
23
|
+
ThreeLiveElement,
|
|
24
|
+
} from './three-live/src/three-live-element';
|
|
25
|
+
import type {
|
|
26
|
+
CameraDetail,
|
|
27
|
+
GLBData,
|
|
28
|
+
HitDetail,
|
|
29
|
+
ThreeView,
|
|
30
|
+
} from './three-live/src/three-view';
|
|
31
|
+
import type {ARLaunchResult, ARMode} from './three-live/src/three-xr';
|
|
32
|
+
import type {TranscriptEvent} from './xr-live/src/plugins/gemini-live';
|
|
33
|
+
import type {Detection3D} from './xr-live/src/plugins/world-understanding';
|
|
34
|
+
import type {
|
|
35
|
+
XRAnchorElement,
|
|
36
|
+
XRDepthMode,
|
|
37
|
+
XRHandsMode,
|
|
38
|
+
XRLiveElement,
|
|
39
|
+
XRMode,
|
|
40
|
+
XRProfile,
|
|
41
|
+
XRSimulatorRoom,
|
|
42
|
+
} from './xr-live/src/xr-live-element';
|
|
43
|
+
|
|
44
|
+
export * from './three-live/src/core';
|
|
45
|
+
export {
|
|
46
|
+
getInteractivityVM,
|
|
47
|
+
interactivityPlugin,
|
|
48
|
+
InteractivityVM,
|
|
49
|
+
parseSafeGltfPointer,
|
|
50
|
+
sendInteractivityEvent,
|
|
51
|
+
type InteractivityDeclaration,
|
|
52
|
+
type InteractivityEventDef,
|
|
53
|
+
type InteractivityFlowTarget,
|
|
54
|
+
type InteractivityGraph,
|
|
55
|
+
type InteractivityNode,
|
|
56
|
+
type InteractivityValue,
|
|
57
|
+
type InteractivityValueSocket,
|
|
58
|
+
type InteractivityVariableDef,
|
|
59
|
+
} from './three-live/src/plugins/interactivity';
|
|
60
|
+
export {
|
|
61
|
+
ThreeLiveElement,
|
|
62
|
+
type ARLaunchOptions,
|
|
63
|
+
type ARLaunchResult,
|
|
64
|
+
type ARMode,
|
|
65
|
+
type ARProvider,
|
|
66
|
+
type CameraState,
|
|
67
|
+
} from './three-live/src/three-live-element';
|
|
68
|
+
export {
|
|
69
|
+
XRAnchorElement,
|
|
70
|
+
XRLiveElement,
|
|
71
|
+
type XRDepthMode,
|
|
72
|
+
type XRHandsMode,
|
|
73
|
+
type XRMode,
|
|
74
|
+
type XRProfile,
|
|
75
|
+
type XRSimulatorRoom,
|
|
76
|
+
} from './xr-live/src/xr-live-element';
|
|
77
|
+
/** Optional XR Blocks plugins (`xr-live/blocks`, `xr-live-blocks.min.js`). */
|
|
78
|
+
export * from './xr-live/src/plugins/index';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Declarative JSX / HTML attributes supported by the <three-live> custom element.
|
|
82
|
+
*/
|
|
83
|
+
export interface ThreeLiveAttributes {
|
|
84
|
+
/** URL to glTF 2.0 binary (.glb) model. */
|
|
85
|
+
'src'?: string;
|
|
86
|
+
/** URL to Apple Universal Scene Description (.usdz) model for iOS Quick Look. */
|
|
87
|
+
'ios-src'?: string;
|
|
88
|
+
/** URL or inline script for procedural Three.js scene generation. */
|
|
89
|
+
'script-src'?: string;
|
|
90
|
+
/** Responsive image preview shown before 3D model finishes hydration. */
|
|
91
|
+
'poster'?: string;
|
|
92
|
+
/** Uniform or per-axis scale multiplier ("x y z"). */
|
|
93
|
+
'scale'?: string;
|
|
94
|
+
/** Initial camera orbit angles and distance: "theta phi [radius]" (e.g. "0deg 75deg 3m") or JSON string. */
|
|
95
|
+
'camera-orbit'?: string | CameraState;
|
|
96
|
+
/** Orbit center coordinate "x y z". */
|
|
97
|
+
'camera-target'?: string;
|
|
98
|
+
/** Lower bounds for camera orbit ("theta phi radius"). */
|
|
99
|
+
'min-camera-orbit'?: string;
|
|
100
|
+
/** Upper bounds for camera orbit ("theta phi radius"). */
|
|
101
|
+
'max-camera-orbit'?: string;
|
|
102
|
+
/** Vertical field of view angle (e.g. "45deg"). */
|
|
103
|
+
'field-of-view'?: string;
|
|
104
|
+
/** Sub-mesh name to highlight with interactive selection color. */
|
|
105
|
+
'selected-mesh'?: string;
|
|
106
|
+
/** Exposure / lighting multiplier for studio IBL lighting (default: 1.0). */
|
|
107
|
+
'exposure'?: number | string;
|
|
108
|
+
/** Equirectangular HDR/LDR environment map URL. */
|
|
109
|
+
'environment-image'?: string;
|
|
110
|
+
/** Visible background equirectangular skybox image URL. */
|
|
111
|
+
'skybox-image'?: string;
|
|
112
|
+
/** Ground contact shadow opacity (0.0 to 1.0). */
|
|
113
|
+
'shadow-intensity'?: number | string;
|
|
114
|
+
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
115
|
+
'shadow-softness'?: number | string;
|
|
116
|
+
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
117
|
+
'tone-mapping'?: string;
|
|
118
|
+
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
119
|
+
'camera-controls'?: boolean | string;
|
|
120
|
+
/** Automatically start keyframe animation playback. */
|
|
121
|
+
'autoplay'?: boolean | string;
|
|
122
|
+
/** Name of specific glTF animation clip to play. */
|
|
123
|
+
'animation-name'?: string;
|
|
124
|
+
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
125
|
+
'auto-rotate'?: boolean | string;
|
|
126
|
+
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
127
|
+
'auto-rotate-delay'?: number | string;
|
|
128
|
+
/** Rate of turntable auto-rotation (e.g. "30deg", "0.5rad", "100%", default: "30deg"). */
|
|
129
|
+
'rotation-per-second'?: string;
|
|
130
|
+
/** Enable one-tap Augmented Reality button overlay. */
|
|
131
|
+
'ar'?: boolean | string;
|
|
132
|
+
/** Ordered list of AR launch targets ('webxr', 'quick-look', 'scene-viewer'). */
|
|
133
|
+
'ar-modes'?: string;
|
|
134
|
+
/** Controls whether the model can be scaled in AR ("auto" or "fixed"). */
|
|
135
|
+
'ar-scale'?: 'auto' | 'fixed';
|
|
136
|
+
/** Controls whether the model is placed on horizontal surfaces ("floor") or vertical surfaces ("wall"). */
|
|
137
|
+
'ar-placement'?: 'floor' | 'wall';
|
|
138
|
+
/**
|
|
139
|
+
* Mandatory isolation level for procedural scripts. Defaults to `'worker'`,
|
|
140
|
+
* which runs the script in a dedicated Web Worker with network, storage and
|
|
141
|
+
* thread-spawning capabilities revoked across the prototype chain. `'iframe'`
|
|
142
|
+
* runs the Worker inside an opaque-origin `<iframe sandbox="allow-scripts">`
|
|
143
|
+
* (`three-live-sandbox.html`) with a strict `connect-src 'none'` Content
|
|
144
|
+
* Security Policy.
|
|
145
|
+
*/
|
|
146
|
+
sandbox?: 'worker' | 'iframe';
|
|
147
|
+
/**
|
|
148
|
+
* Opt-in attribute allowing client-modified Three.js script strings
|
|
149
|
+
* (`executeScript(code)` and inline `<script type="text/three-live">`).
|
|
150
|
+
* Server-generated scripts (`script-src`) are enabled by default.
|
|
151
|
+
*/
|
|
152
|
+
'allow-client-scripts'?: boolean | string;
|
|
153
|
+
|
|
154
|
+
// React 19 / JSX Event Listeners
|
|
155
|
+
onload?: (e: CustomEvent<{model: GLBData}>) => void;
|
|
156
|
+
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
157
|
+
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
158
|
+
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
159
|
+
'onar-status'?: (
|
|
160
|
+
e: CustomEvent<{
|
|
161
|
+
status: 'session-started' | 'not-presenting' | 'failed';
|
|
162
|
+
error?: any;
|
|
163
|
+
}>,
|
|
164
|
+
) => void;
|
|
165
|
+
|
|
166
|
+
// Standard HTML / JSX attributes
|
|
167
|
+
id?: string;
|
|
168
|
+
className?: string;
|
|
169
|
+
class?: string;
|
|
170
|
+
style?: any;
|
|
171
|
+
ref?: any;
|
|
172
|
+
key?: any;
|
|
173
|
+
slot?: string;
|
|
174
|
+
tabIndex?: number;
|
|
175
|
+
role?: string;
|
|
176
|
+
'aria-label'?: string;
|
|
177
|
+
children?: any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Declarative JSX / HTML attributes supported by the <xr-live> spatial computing element.
|
|
182
|
+
*/
|
|
183
|
+
export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
184
|
+
/** WebXR session target mode ("ar", "vr", "inline", or "auto"). */
|
|
185
|
+
'xr-mode'?: XRMode;
|
|
186
|
+
/** Real-world hardware depth occlusion or physics mode ("occlusion", "occlusion-physics", "mesh", "none"). */
|
|
187
|
+
'xr-depth'?: XRDepthMode;
|
|
188
|
+
/** 25-joint hand tracking and gesture recognition mode ("gestures", "joints", "pinch", "none"). */
|
|
189
|
+
'xr-hands'?: XRHandsMode;
|
|
190
|
+
/** Desktop room simulator environment ("living-room", "office", "tabletop", "none"). */
|
|
191
|
+
'xr-simulator'?: XRSimulatorRoom;
|
|
192
|
+
/** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
|
|
193
|
+
'xr-profile'?: XRProfile;
|
|
194
|
+
/** XR Blocks: enables plane/mesh detection; include "reticle" for a gaze reticle. */
|
|
195
|
+
'world-understanding'?: boolean | string;
|
|
196
|
+
/** XR Blocks: pinch in empty space to paint 3D tubes (optional `#rrggbb` color). */
|
|
197
|
+
'spatial-paint'?: boolean | string;
|
|
198
|
+
'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
|
|
199
|
+
'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
|
|
200
|
+
'onxr-hold-to-ask'?: (
|
|
201
|
+
e: CustomEvent<{mesh: string; transcript: string; prompt: string}>,
|
|
202
|
+
) => void;
|
|
203
|
+
'onxr-handles-change'?: (
|
|
204
|
+
e: CustomEvent<{mesh: string; scale: number; yawDeg: number}>,
|
|
205
|
+
) => void;
|
|
206
|
+
'onxr-paint-stroke'?: (
|
|
207
|
+
e: CustomEvent<{index: number; points: number; lengthMeters: number}>,
|
|
208
|
+
) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare global {
|
|
212
|
+
namespace JSX {
|
|
213
|
+
interface IntrinsicElements {
|
|
214
|
+
'three-live': ThreeLiveAttributes;
|
|
215
|
+
'xr-live': XRLiveAttributes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface HTMLElementTagNameMap {
|
|
220
|
+
'three-live': ThreeLiveElement;
|
|
221
|
+
'xr-live': XRLiveElement;
|
|
222
|
+
'xr-anchor': XRAnchorElement;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var M="__THREE_LIVE_REGISTRY__";function I(){let e=typeof globalThis<"u"?globalThis:{};if(!e[M]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,M,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[M]=t}}return e[M]}var J=I().plugins;function S(e){let t=I().plugins;t.some(r=>r.name===e.name)||t.push(e)}function R(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function z(e,t,r){let i=t[0],n=t[1],c=t[2],f=t[3],u=t[4],s=t[5],b=t[6],o=t[7],a=t[8],m=t[9],l=t[10],p=t[11],A=t[12],h=t[13],x=t[14],d=t[15],y=r[0],g=r[1],T=r[2],P=r[3];return e[0]=y*i+g*u+T*a+P*A,e[1]=y*n+g*s+T*m+P*h,e[2]=y*c+g*b+T*l+P*x,e[3]=y*f+g*o+T*p+P*d,y=r[4],g=r[5],T=r[6],P=r[7],e[4]=y*i+g*u+T*a+P*A,e[5]=y*n+g*s+T*m+P*h,e[6]=y*c+g*b+T*l+P*x,e[7]=y*f+g*o+T*p+P*d,y=r[8],g=r[9],T=r[10],P=r[11],e[8]=y*i+g*u+T*a+P*A,e[9]=y*n+g*s+T*m+P*h,e[10]=y*c+g*b+T*l+P*x,e[11]=y*f+g*o+T*p+P*d,y=r[12],g=r[13],T=r[14],P=r[15],e[12]=y*i+g*u+T*a+P*A,e[13]=y*n+g*s+T*m+P*h,e[14]=y*c+g*b+T*l+P*x,e[15]=y*f+g*o+T*p+P*d,e}function _(e,t,r,i){let n=t[0],c=t[1],f=t[2],u=t[3],s=n+n,b=c+c,o=f+f,a=n*s,m=n*b,l=n*o,p=c*b,A=c*o,h=f*o,x=u*s,d=u*b,y=u*o,g=i[0],T=i[1],P=i[2];return e[0]=(1-(p+h))*g,e[1]=(m+y)*g,e[2]=(l-d)*g,e[3]=0,e[4]=(m-y)*T,e[5]=(1-(a+h))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+d)*P,e[9]=(A-x)*P,e[10]=(1-(a+p))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function W(e,t){let r=t[0],i=t[1],n=t[2],c=t[4],f=t[5],u=t[6],s=t[8],b=t[9],o=t[10],a=o*f-u*b,m=-o*c+u*s,l=b*c-f*s,p=r*a+i*m+n*l;return p&&(p=1/p,e[0]=a*p,e[1]=(-o*i+n*b)*p,e[2]=(u*i-n*f)*p,e[3]=m*p,e[4]=(o*r-n*s)*p,e[5]=(-u*r+n*c)*p,e[6]=l*p,e[7]=(-b*r+i*s)*p,e[8]=(f*r-i*c)*p),e}function D(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(R());if(r===0)return i;let n=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let a of o.children)n.add(a);let c=new Set,f=128,u=(o,a,m=0)=>{if(m>f||o<0||o>=r||c.has(o))return;c.add(o);let l=e.nodes[o];if(!l)return;let p=R();if(t&&t[o])p.set(t[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let h=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],d=l.scale||[1,1,1];_(p,x,h,d)}let A=i[o];if(a?z(A,a,p):A.set(p),Array.isArray(l.children))for(let h of l.children)typeof h=="number"&&u(h,A,m+1)},s=[],b=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(b&&Array.isArray(b.nodes))s.push(...b.nodes);else for(let o=0;o<r;o++)n.has(o)||s.push(o);for(let o of s)u(o,null);for(let o=0;o<r;o++)!n.has(o)&&!s.includes(o)&&u(o,null);return i}function w(e,t,r){return t%4===0?new Float32Array(e,t,r):new Float32Array(e.slice(t,t+r*4))}function O(e,t,r,i){let n=t[0],c=t[1],f=t[2],u=t[3],s=r[0],b=r[1],o=r[2],a=r[3],m=n*s+c*b+f*o+u*a;if(m<0&&(s=-s,b=-b,o=-o,a=-a,m=-m),Math.abs(m)>=1)return e[0]=n,e[1]=c,e[2]=f,e[3]=u,e;let l=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(n+s),e[1]=.5*(c+b),e[2]=.5*(f+o),e[3]=.5*(u+a),e;let A=Math.sin((1-i)*l)/p,h=Math.sin(i*l)/p;return e[0]=n*A+s*h,e[1]=c*A+b*h,e[2]=f*A+o*h,e[3]=u*A+a*h,e}function B(e,t,r,i){return e[0]=t[0]+i*(r[0]-t[0]),e[1]=t[1]+i*(r[1]-t[1]),e[2]=t[2]+i*(r[2]-t[2]),e}function k(e,t){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let n=e.animations[i],c=n.name||`Animation_${i}`,f=[],u=0;if(Array.isArray(n.channels)&&Array.isArray(n.samplers))for(let s of n.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let b=n.samplers[s.sampler];if(!b)continue;let o=e.accessors?.[b.input],a=e.accessors?.[b.output];if(!o||!a)continue;let m=e.bufferViews?.[o.bufferView],l=e.bufferViews?.[a.bufferView];if(!m||!l)continue;let p=(m.byteOffset||0)+(o.byteOffset||0),A=(l.byteOffset||0)+(a.byteOffset||0),h=w(t,p,o.count);h.length>0&&h[h.length-1]>u&&(u=h[h.length-1]);let x=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(a.count/Math.max(1,o.count))):3,d=w(t,A,a.count*(s.target.path==="weights"?1:x)),y=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:h,values:d,interpolation:y})}f.length>0&&r.push({name:c,duration:u,channels:f})}return r}function F(e,t,r){let{times:i,values:n,path:c,interpolation:f}=e,u=i.length;if(u===0)return;let s=c==="rotation"?4:c==="weights"?Math.max(1,Math.round(n.length/u)):3;if(t<=i[0]){for(let d=0;d<s;d++)r[d]=n[d];return}if(t>=i[u-1]){let d=(u-1)*s;for(let y=0;y<s;y++)r[y]=n[d+y];return}let b=0,o=u-1;for(;b<=o;){let d=b+o>>1;i[d]<=t?b=d+1:o=d-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let d=a*s;for(let y=0;y<s;y++)r[y]=n[d+y];return}let l=i[a],p=i[m],A=(t-l)/Math.max(1e-5,p-l),h=a*s,x=m*s;if(c==="rotation"){let d=[n[h],n[h+1],n[h+2],n[h+3]],y=[n[x],n[x+1],n[x+2],n[x+3]];O(r,d,y,A)}else for(let d=0;d<s;d++)r[d]=n[h+d]+A*(n[x+d]-n[h+d])}var E=new WeakMap;function G(e,t,r=.3){if(!e?.animations)return;let i=e.animations.find(u=>u.name===t);if(!i)return;let n=E.get(e);n||(n=[],e.currentClip&&n.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),E.set(e,n));let c=r>0?1/r:1e3;for(let u of n)u.clip.name!==t&&(u.fadeSpeed=-c);let f=n.find(u=>u.clip.name===t);f?f.fadeSpeed=c:n.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:c}),e.currentClip=i,e.isPlayingAnimation=!0}function L(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=E.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,n=[];for(let a=0;a<i;a++){let m=e.initialNodeTransforms[a];m?n.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):n.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let c=[0,0,0],f=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let a of r){let m=Math.max(0,Math.min(1,a.weight));if(!(m<=1e-4))for(let l of a.clip.channels){if(l.nodeIndex<0||l.nodeIndex>=i)continue;let p=n[l.nodeIndex];if(l.path==="translation")F(l,a.time,c),B(p.t,p.t,c,m);else if(l.path==="rotation")F(l,a.time,f),O(p.r,p.r,f,m);else if(l.path==="scale")F(l,a.time,u),B(p.s,p.s,u,m);else if(l.path==="weights"&&(F(l,a.time,s),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===l.nodeIndex){for(let h of A.primitives)if(h.pluginData?.morph?.weights){let x=h.pluginData.morph.weights,d=h.pluginData.morph.numTargets||x.length;for(let y=0;y<d;y++)x[y]=x[y]*(1-m)+s[y]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=R(),{t:l,r:p,s:A}=n[a];_(m,p,l,A),b.push(m)}let o=D(e.gltf,b);e.worldMatrices=o;for(let a of e.meshes)a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),W(a.normalMatrix,a.transform))}var V={name:"keyframes",evaluateAnimation:L,crossFadeTo:G,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=k(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let r=E.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let n=r[i];if(n.time+=t,n.clip.duration>0&&(n.time%=n.clip.duration),n.fadeSpeed!==0)if(n.weight+=n.fadeSpeed*t,n.weight<=0){r.splice(i,1);continue}else n.weight>=1&&(n.weight=1,n.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),L(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),L(e,e.animationTime))}};var v=64;function j(e,t,r){if(!(!e?.meshes||t<0||t>=v))for(let i of e.meshes)for(let n of i.primitives){let c=n.pluginData?.morph;c?.weights&&(c.weights[t]=r)}}var U={name:"morph",onResolveShader(e,t,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let n=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
18
|
+
uniform sampler2D uMorphDeltasTex;
|
|
19
|
+
uniform float uMorphWeights[${v}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return n=n.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${v}; m++) {
|
|
22
|
+
if (m >= uNumMorphTargets) break;
|
|
23
|
+
float w = uMorphWeights[m];
|
|
24
|
+
if (abs(w) > 0.0001) {
|
|
25
|
+
morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,v),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],h=i.bufferViews?.[A?.bufferView];if(!A||!h)continue;let x=(h.byteOffset||0)+(A.byteOffset||0),d=w(n,x,s*3),y=l*s*4;for(let g=0;g<s;g++)o[y+g*4]=d[g*3],o[y+g*4+1]=d[g*3+1],o[y+g*4+2]=d[g*3+2],o[y+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(v);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,t,r,i,n,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(t,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(t,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(t,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var C=64,N={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
|
|
29
|
+
layout(location=4) in uvec4 aJoints;
|
|
30
|
+
layout(location=5) in vec4 aWeights;
|
|
31
|
+
uniform mat4 uJointMatrix[${C}];`),c=n.includes("morphedPos")?"morphedPos":"aPosition";return n=n.replace(`vec4 world=uModel*vec4(${c},1.0);`,`mat4 skinMatrix =
|
|
32
|
+
aWeights.x * uJointMatrix[int(aJoints.x)] +
|
|
33
|
+
aWeights.y * uJointMatrix[int(aJoints.y)] +
|
|
34
|
+
aWeights.z * uJointMatrix[int(aJoints.z)] +
|
|
35
|
+
aWeights.w * uJointMatrix[int(aJoints.w)];
|
|
36
|
+
vec4 world=uModel*(skinMatrix*vec4(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(n,o,f.count*4):new Uint16Array(n,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let h=new Float32Array(n,a,u.count*4);return e.bufferData(34962,h,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,t,r,i,n,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(C*16);for(let a=0;a<s.length&&a<C;a++){let m=s[a],l=n[m]||R();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(t,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};S(U);S(V);S(N);export{G as crossFadeTo,V as keyframeAnimationPlugin,U as morphPlugin,k as parseAnimations,F as sampleChannel,j as setMorphTargetWeight,N as skinningPlugin};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
"use strict";var ThreeLiveAnimation=(()=>{var _=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var $=(e,n)=>{for(var r in n)_(e,r,{get:n[r],enumerable:!0})},Y=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of X(n))!H.call(e,t)&&t!==r&&_(e,t,{get:()=>n[t],enumerable:!(i=J(n,t))||i.enumerable});return e};var q=e=>Y(_({},"__esModule",{value:!0}),e);var Q={};$(Q,{crossFadeTo:()=>W,keyframeAnimationPlugin:()=>D,morphPlugin:()=>B,parseAnimations:()=>I,sampleChannel:()=>F,setMorphTargetWeight:()=>j,skinningPlugin:()=>k});var M="__THREE_LIVE_REGISTRY__";function G(){let e=typeof globalThis<"u"?globalThis:{};if(!e[M]){let n={plugins:[],decoders:new Map};try{Object.defineProperty(e,M,{value:n,writable:!1,configurable:!1,enumerable:!1})}catch{e[M]=n}}return e[M]}var ee=G().plugins;function S(e){let n=G().plugins;n.some(r=>r.name===e.name)||n.push(e)}function R(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function K(e,n,r){let i=n[0],t=n[1],c=n[2],f=n[3],u=n[4],s=n[5],b=n[6],o=n[7],a=n[8],m=n[9],l=n[10],p=n[11],A=n[12],h=n[13],x=n[14],d=n[15],y=r[0],g=r[1],T=r[2],P=r[3];return e[0]=y*i+g*u+T*a+P*A,e[1]=y*t+g*s+T*m+P*h,e[2]=y*c+g*b+T*l+P*x,e[3]=y*f+g*o+T*p+P*d,y=r[4],g=r[5],T=r[6],P=r[7],e[4]=y*i+g*u+T*a+P*A,e[5]=y*t+g*s+T*m+P*h,e[6]=y*c+g*b+T*l+P*x,e[7]=y*f+g*o+T*p+P*d,y=r[8],g=r[9],T=r[10],P=r[11],e[8]=y*i+g*u+T*a+P*A,e[9]=y*t+g*s+T*m+P*h,e[10]=y*c+g*b+T*l+P*x,e[11]=y*f+g*o+T*p+P*d,y=r[12],g=r[13],T=r[14],P=r[15],e[12]=y*i+g*u+T*a+P*A,e[13]=y*t+g*s+T*m+P*h,e[14]=y*c+g*b+T*l+P*x,e[15]=y*f+g*o+T*p+P*d,e}function L(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=t+t,b=c+c,o=f+f,a=t*s,m=t*b,l=t*o,p=c*b,A=c*o,h=f*o,x=u*s,d=u*b,y=u*o,g=i[0],T=i[1],P=i[2];return e[0]=(1-(p+h))*g,e[1]=(m+y)*g,e[2]=(l-d)*g,e[3]=0,e[4]=(m-y)*T,e[5]=(1-(a+h))*T,e[6]=(A+x)*T,e[7]=0,e[8]=(l+d)*P,e[9]=(A-x)*P,e[10]=(1-(a+p))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function V(e,n){let r=n[0],i=n[1],t=n[2],c=n[4],f=n[5],u=n[6],s=n[8],b=n[9],o=n[10],a=o*f-u*b,m=-o*c+u*s,l=b*c-f*s,p=r*a+i*m+t*l;return p&&(p=1/p,e[0]=a*p,e[1]=(-o*i+t*b)*p,e[2]=(u*i-t*f)*p,e[3]=m*p,e[4]=(o*r-t*s)*p,e[5]=(-u*r+t*c)*p,e[6]=l*p,e[7]=(-b*r+i*s)*p,e[8]=(f*r-i*c)*p),e}function U(e,n){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(R());if(r===0)return i;let t=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let a of o.children)t.add(a);let c=new Set,f=128,u=(o,a,m=0)=>{if(m>f||o<0||o>=r||c.has(o))return;c.add(o);let l=e.nodes[o];if(!l)return;let p=R();if(n&&n[o])p.set(n[o]);else if(l.matrix&&l.matrix.length===16)p.set(l.matrix);else{let h=l.translation||[0,0,0],x=l.rotation||[0,0,0,1],d=l.scale||[1,1,1];L(p,x,h,d)}let A=i[o];if(a?K(A,a,p):A.set(p),Array.isArray(l.children))for(let h of l.children)typeof h=="number"&&u(h,A,m+1)},s=[],b=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(b&&Array.isArray(b.nodes))s.push(...b.nodes);else for(let o=0;o<r;o++)t.has(o)||s.push(o);for(let o of s)u(o,null);for(let o=0;o<r;o++)!t.has(o)&&!s.includes(o)&&u(o,null);return i}function w(e,n,r){return n%4===0?new Float32Array(e,n,r):new Float32Array(e.slice(n,n+r*4))}function z(e,n,r,i){let t=n[0],c=n[1],f=n[2],u=n[3],s=r[0],b=r[1],o=r[2],a=r[3],m=t*s+c*b+f*o+u*a;if(m<0&&(s=-s,b=-b,o=-o,a=-a,m=-m),Math.abs(m)>=1)return e[0]=t,e[1]=c,e[2]=f,e[3]=u,e;let l=Math.acos(m),p=Math.sqrt(1-m*m);if(Math.abs(p)<.001)return e[0]=.5*(t+s),e[1]=.5*(c+b),e[2]=.5*(f+o),e[3]=.5*(u+a),e;let A=Math.sin((1-i)*l)/p,h=Math.sin(i*l)/p;return e[0]=t*A+s*h,e[1]=c*A+b*h,e[2]=f*A+o*h,e[3]=u*A+a*h,e}function N(e,n,r,i){return e[0]=n[0]+i*(r[0]-n[0]),e[1]=n[1]+i*(r[1]-n[1]),e[2]=n[2]+i*(r[2]-n[2]),e}function I(e,n){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let t=e.animations[i],c=t.name||`Animation_${i}`,f=[],u=0;if(Array.isArray(t.channels)&&Array.isArray(t.samplers))for(let s of t.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let b=t.samplers[s.sampler];if(!b)continue;let o=e.accessors?.[b.input],a=e.accessors?.[b.output];if(!o||!a)continue;let m=e.bufferViews?.[o.bufferView],l=e.bufferViews?.[a.bufferView];if(!m||!l)continue;let p=(m.byteOffset||0)+(o.byteOffset||0),A=(l.byteOffset||0)+(a.byteOffset||0),h=w(n,p,o.count);h.length>0&&h[h.length-1]>u&&(u=h[h.length-1]);let x=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(a.count/Math.max(1,o.count))):3,d=w(n,A,a.count*(s.target.path==="weights"?1:x)),y=b.interpolation==="STEP"?"STEP":"LINEAR";f.push({nodeIndex:s.target.node,path:s.target.path,times:h,values:d,interpolation:y})}f.length>0&&r.push({name:c,duration:u,channels:f})}return r}function F(e,n,r){let{times:i,values:t,path:c,interpolation:f}=e,u=i.length;if(u===0)return;let s=c==="rotation"?4:c==="weights"?Math.max(1,Math.round(t.length/u)):3;if(n<=i[0]){for(let d=0;d<s;d++)r[d]=t[d];return}if(n>=i[u-1]){let d=(u-1)*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let b=0,o=u-1;for(;b<=o;){let d=b+o>>1;i[d]<=n?b=d+1:o=d-1}let a=Math.max(0,o),m=Math.min(u-1,a+1);if(f==="STEP"||a===m){let d=a*s;for(let y=0;y<s;y++)r[y]=t[d+y];return}let l=i[a],p=i[m],A=(n-l)/Math.max(1e-5,p-l),h=a*s,x=m*s;if(c==="rotation"){let d=[t[h],t[h+1],t[h+2],t[h+3]],y=[t[x],t[x+1],t[x+2],t[x+3]];z(r,d,y,A)}else for(let d=0;d<s;d++)r[d]=t[h+d]+A*(t[x+d]-t[h+d])}var E=new WeakMap;function W(e,n,r=.3){if(!e?.animations)return;let i=e.animations.find(u=>u.name===n);if(!i)return;let t=E.get(e);t||(t=[],e.currentClip&&t.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),E.set(e,t));let c=r>0?1/r:1e3;for(let u of t)u.clip.name!==n&&(u.fadeSpeed=-c);let f=t.find(u=>u.clip.name===n);f?f.fadeSpeed=c:t.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:c}),e.currentClip=i,e.isPlayingAnimation=!0}function C(e,n){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=E.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:n,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,t=[];for(let a=0;a<i;a++){let m=e.initialNodeTransforms[a];m?t.push({t:[m.t[0],m.t[1],m.t[2]],r:[m.r[0],m.r[1],m.r[2],m.r[3]],s:[m.s[0],m.s[1],m.s[2]]}):t.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let c=[0,0,0],f=[0,0,0,1],u=[1,1,1],s=new Float32Array(64);for(let a of r){let m=Math.max(0,Math.min(1,a.weight));if(!(m<=1e-4))for(let l of a.clip.channels){if(l.nodeIndex<0||l.nodeIndex>=i)continue;let p=t[l.nodeIndex];if(l.path==="translation")F(l,a.time,c),N(p.t,p.t,c,m);else if(l.path==="rotation")F(l,a.time,f),z(p.r,p.r,f,m);else if(l.path==="scale")F(l,a.time,u),N(p.s,p.s,u,m);else if(l.path==="weights"&&(F(l,a.time,s),e.meshes)){for(let A of e.meshes)if(A.nodeIndex===l.nodeIndex){for(let h of A.primitives)if(h.pluginData?.morph?.weights){let x=h.pluginData.morph.weights,d=h.pluginData.morph.numTargets||x.length;for(let y=0;y<d;y++)x[y]=x[y]*(1-m)+s[y]*m}}}}}let b=[];for(let a=0;a<i;a++){let m=R(),{t:l,r:p,s:A}=t[a];L(m,p,l,A),b.push(m)}let o=U(e.gltf,b);e.worldMatrices=o;for(let a of e.meshes)a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),V(a.normalMatrix,a.transform))}var D={name:"keyframes",evaluateAnimation:C,crossFadeTo:W,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=I(e.gltf,e.bin))},onUpdate(e,n){if(!e.isPlayingAnimation)return;let r=E.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let t=r[i];if(t.time+=n,t.clip.duration>0&&(t.time%=t.clip.duration),t.fadeSpeed!==0)if(t.weight+=t.fadeSpeed*n,t.weight<=0){r.splice(i,1);continue}else t.weight>=1&&(t.weight=1,t.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),C(e,e.animationTime)}else e.currentClip&&(e.animationTime+=n,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),C(e,e.animationTime))}};var v=64;function j(e,n,r){if(!(!e?.meshes||n<0||n>=v))for(let i of e.meshes)for(let t of i.primitives){let c=t.pluginData?.morph;c?.weights&&(c.weights[n]=r)}}var B={name:"morph",onResolveShader(e,n,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let t=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
|
|
18
|
+
uniform sampler2D uMorphDeltasTex;
|
|
19
|
+
uniform float uMorphWeights[${v}];
|
|
20
|
+
uniform int uNumMorphTargets;`);return t=t.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
|
|
21
|
+
for (int m = 0; m < ${v}; m++) {
|
|
22
|
+
if (m >= uNumMorphTargets) break;
|
|
23
|
+
float w = uMorphWeights[m];
|
|
24
|
+
if (abs(w) > 0.0001) {
|
|
25
|
+
morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.targets;if(!Array.isArray(c)||c.length===0)return null;let f=r.attributes?.POSITION,u=i?.accessors?.[f];if(!u)return null;let s=u.count,b=Math.min(c.length,v),o=new Float32Array(s*b*4);for(let l=0;l<b;l++){let p=c[l].POSITION;if(p===void 0)continue;let A=i.accessors?.[p],h=i.bufferViews?.[A?.bufferView];if(!A||!h)continue;let x=(h.byteOffset||0)+(A.byteOffset||0),d=w(t,x,s*3),y=l*s*4;for(let g=0;g<s;g++)o[y+g*4]=d[g*3],o[y+g*4+1]=d[g*3+1],o[y+g*4+2]=d[g*3+2],o[y+g*4+3]=0}let a=e.createTexture();e.bindTexture(3553,a),e.texImage2D(3553,0,34836,s,b,0,6408,5126,o),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let m=new Float32Array(v);return{hasMorph:!0,morphTex:a,numTargets:b,vertexCount:s,weights:m}},onBeforeDrawPrimitive(e,n,r,i,t,c){let f=r.pluginData?.morph;if(!f?.hasMorph||!f.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,f.morphTex);let u=e.getUniformLocation(n,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(n,"uNumMorphTargets");s&&e.uniform1i(s,f.numTargets);let b=e.getUniformLocation(n,"uMorphWeights[0]");b&&e.uniform1fv(b,f.weights)}};var O=64,k={name:"skinning",onResolveShader(e,n,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let t=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
|
|
29
|
+
layout(location=4) in uvec4 aJoints;
|
|
30
|
+
layout(location=5) in vec4 aWeights;
|
|
31
|
+
uniform mat4 uJointMatrix[${O}];`),c=t.includes("morphedPos")?"morphedPos":"aPosition";return t=t.replace(`vec4 world=uModel*vec4(${c},1.0);`,`mat4 skinMatrix =
|
|
32
|
+
aWeights.x * uJointMatrix[int(aJoints.x)] +
|
|
33
|
+
aWeights.y * uJointMatrix[int(aJoints.y)] +
|
|
34
|
+
aWeights.z * uJointMatrix[int(aJoints.z)] +
|
|
35
|
+
aWeights.w * uJointMatrix[int(aJoints.w)];
|
|
36
|
+
vec4 world=uModel*(skinMatrix*vec4(${c},1.0));`).replace(`gl_Position=uMVP*vec4(${c},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${c},1.0));`),{vs:t,fs:i}},onBuildPrimitiveVAO(e,n,r,i,t){let c=r?.attributes;if(!c||c.JOINTS_0===void 0||c.WEIGHTS_0===void 0)return null;let f=i.accessors[c.JOINTS_0],u=i.accessors[c.WEIGHTS_0];if(!f||!u)return null;let s=i.bufferViews[f.bufferView],b=i.bufferViews[u.bufferView];if(!s||!b)return null;let o=(s.byteOffset||0)+(f.byteOffset||0),a=(b.byteOffset||0)+(u.byteOffset||0),m=e.createBuffer();e.bindBuffer(34962,m);let l=f.componentType===5121?5121:5123,p=l===5121?new Uint8Array(t,o,f.count*4):new Uint16Array(t,o,f.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,l,0,0);let A=e.createBuffer();e.bindBuffer(34962,A);let h=new Float32Array(t,a,u.count*4);return e.bufferData(34962,h,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[m,A]}},onBeforeDrawPrimitive(e,n,r,i,t,c){if(!r.pluginData?.skinning?.hasSkin)return;let f=c?.nodes?.[i.nodeIndex]?.skin;if(f===void 0||!c.skins||!c.skins[f])return;let s=c.skins[f].joints||[],b=new Float32Array(O*16);for(let a=0;a<s.length&&a<O;a++){let m=s[a],l=t[m]||R();b.subarray(a*16,(a+1)*16).set(l)}let o=e.getUniformLocation(n,"uJointMatrix[0]");o&&e.uniformMatrix4fv(o,!1,b)}};S(B);S(D);S(k);return q(Q);})();
|