three-live 1.2.1 → 1.2.3
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 +6 -1
- package/dist/index.d.ts +66 -2
- package/dist/three-author-engine.js +85 -42
- package/dist/three-author.cjs +84 -42
- package/dist/three-author.d.ts +66 -2
- package/dist/three-author.js +84 -42
- package/dist/three-convert.cjs +84 -42
- package/dist/three-convert.d.ts +66 -2
- package/dist/three-convert.js +84 -42
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +66 -2
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +66 -2
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +48 -6
- package/dist/three-live-element.d.ts +66 -2
- package/dist/three-live-element.js +48 -6
- package/dist/three-live-full.cjs +176 -55
- package/dist/three-live-full.js +176 -55
- package/dist/three-live-full.min.js +176 -55
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +510 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +48 -6
- package/dist/three-live-viewer.d.ts +66 -2
- package/dist/three-live-viewer.js +48 -6
- package/dist/three-live-viewer.min.js +48 -6
- package/dist/three-live.cjs +86 -44
- package/dist/three-live.js +86 -44
- package/dist/three-live.min.js +86 -44
- package/dist/three-view.cjs +48 -6
- package/dist/three-view.d.ts +66 -2
- package/dist/three-view.js +48 -6
- package/dist/three-xr.cjs +83 -41
- package/dist/three-xr.d.ts +66 -2
- package/dist/three-xr.js +83 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
|
@@ -48,6 +48,30 @@ import type {
|
|
|
48
48
|
} from './xr-live/src/xr-live-element';
|
|
49
49
|
|
|
50
50
|
export * from './three-live/src/core';
|
|
51
|
+
export {
|
|
52
|
+
cadPlugin,
|
|
53
|
+
installCadExtension,
|
|
54
|
+
MAX_BSP_DEPTH,
|
|
55
|
+
MAX_CSG_TRIANGLES,
|
|
56
|
+
MAX_SHAPE_POINTS,
|
|
57
|
+
MAX_TEXT_GEOMETRY_CHARS,
|
|
58
|
+
type ExtrudeGeometryOptions,
|
|
59
|
+
type TextGeometryOptions,
|
|
60
|
+
} from './three-live/src/plugins/cad';
|
|
61
|
+
export {
|
|
62
|
+
ikPlugin,
|
|
63
|
+
IKSolver,
|
|
64
|
+
quatFromUnitVectors,
|
|
65
|
+
solveFABRIK,
|
|
66
|
+
solveTwoBoneIK,
|
|
67
|
+
type FABRIKSolution,
|
|
68
|
+
type IKQuat,
|
|
69
|
+
type TwoBoneIKSolution,
|
|
70
|
+
} from './three-live/src/plugins/ik';
|
|
71
|
+
export {
|
|
72
|
+
extractNodeInstancing,
|
|
73
|
+
instancingPlugin,
|
|
74
|
+
} from './three-live/src/plugins/instancing';
|
|
51
75
|
export {
|
|
52
76
|
getInteractivityVM,
|
|
53
77
|
interactivityPlugin,
|
|
@@ -63,6 +87,30 @@ export {
|
|
|
63
87
|
type InteractivityValueSocket,
|
|
64
88
|
type InteractivityVariableDef,
|
|
65
89
|
} from './three-live/src/plugins/interactivity';
|
|
90
|
+
export {
|
|
91
|
+
applyMeshoptFilter,
|
|
92
|
+
decodeMeshoptBuffer,
|
|
93
|
+
decodeMeshoptGLB,
|
|
94
|
+
encodeMeshoptBuffer,
|
|
95
|
+
meshoptDecoder,
|
|
96
|
+
meshoptPlugin,
|
|
97
|
+
type MeshoptFilter,
|
|
98
|
+
type MeshoptMode,
|
|
99
|
+
} from './three-live/src/plugins/meshopt';
|
|
100
|
+
export {
|
|
101
|
+
computeOutlineClipOffset,
|
|
102
|
+
evaluateKawaseBloom,
|
|
103
|
+
parseHexRgb,
|
|
104
|
+
postprocessingPlugin,
|
|
105
|
+
resolveViewerBloom,
|
|
106
|
+
} from './three-live/src/plugins/postprocessing';
|
|
107
|
+
export {
|
|
108
|
+
extractMaterialVariants,
|
|
109
|
+
extractPrimitiveVariantMappings,
|
|
110
|
+
selectMaterialVariant,
|
|
111
|
+
variantsPlugin,
|
|
112
|
+
type VariantMapping,
|
|
113
|
+
} from './three-live/src/plugins/variants';
|
|
66
114
|
export {
|
|
67
115
|
ThreeLiveElement,
|
|
68
116
|
type ARLaunchOptions,
|
|
@@ -80,7 +128,7 @@ export {
|
|
|
80
128
|
type XRProfile,
|
|
81
129
|
type XRSimulatorRoom,
|
|
82
130
|
} from './xr-live/src/xr-live-element';
|
|
83
|
-
/** Optional spatial plugins (`xr-live/
|
|
131
|
+
/** Optional spatial plugins (`xr-live/spatial`, `xr-live-spatial.min.js`). */
|
|
84
132
|
export * from './xr-live/src/plugins/index';
|
|
85
133
|
|
|
86
134
|
/**
|
|
@@ -119,7 +167,7 @@ export interface ThreeLiveAttributes {
|
|
|
119
167
|
'shadow-intensity'?: number | string;
|
|
120
168
|
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
121
169
|
'shadow-softness'?: number | string;
|
|
122
|
-
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
170
|
+
/** Tone mapping mode ("neutral", "aces", "agx", "reinhard", "none"). */
|
|
123
171
|
'tone-mapping'?: string;
|
|
124
172
|
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
125
173
|
'camera-controls'?: boolean | string;
|
|
@@ -127,6 +175,8 @@ export interface ThreeLiveAttributes {
|
|
|
127
175
|
'autoplay'?: boolean | string;
|
|
128
176
|
/** Name of specific glTF animation clip to play. */
|
|
129
177
|
'animation-name'?: string;
|
|
178
|
+
/** Name of the active KHR_materials_variants material variant. */
|
|
179
|
+
'variant-name'?: string;
|
|
130
180
|
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
131
181
|
'auto-rotate'?: boolean | string;
|
|
132
182
|
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
@@ -162,6 +212,7 @@ export interface ThreeLiveAttributes {
|
|
|
162
212
|
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
163
213
|
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
164
214
|
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
215
|
+
'onvariant-applied'?: (e: CustomEvent<{variantName: string | null}>) => void;
|
|
165
216
|
'onar-status'?: (
|
|
166
217
|
e: CustomEvent<{
|
|
167
218
|
status: 'session-started' | 'not-presenting' | 'failed';
|
|
@@ -248,6 +299,8 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
248
299
|
'peer-name'?: string;
|
|
249
300
|
/** Local avatar visor & laser color (`#rrggbb`) in `shared-room`. */
|
|
250
301
|
'peer-color'?: string;
|
|
302
|
+
/** Opt-in WebRTC voice signaling relay (offer/answer/ICE) and `voiceGain` helpers in `shared-room`. Apps own `RTCPeerConnection` and audio. */
|
|
303
|
+
'shared-room-voice'?: boolean | string;
|
|
251
304
|
/** xr-live-sim: character camera mode, or `none` to disable the character. */
|
|
252
305
|
'character-controller'?:
|
|
253
306
|
| 'third-person'
|
|
@@ -363,6 +416,17 @@ export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
|
363
416
|
onpeergrabconflict?: (
|
|
364
417
|
e: CustomEvent<{peerId: string; nodeId: string}>,
|
|
365
418
|
) => void;
|
|
419
|
+
onpeerrtcsignal?: (
|
|
420
|
+
e: CustomEvent<{
|
|
421
|
+
peerId: string;
|
|
422
|
+
targetPeerId: string;
|
|
423
|
+
signalType: 'offer' | 'answer' | 'ice';
|
|
424
|
+
sdp: string | null;
|
|
425
|
+
candidate: string | null;
|
|
426
|
+
sdpMid: string | null;
|
|
427
|
+
sdpMLineIndex: number | null;
|
|
428
|
+
}>,
|
|
429
|
+
) => void;
|
|
366
430
|
/** xr-live-sim events. */
|
|
367
431
|
oncharacterjump?: (
|
|
368
432
|
e: CustomEvent<{nodeId: string; position: [number, number, number]}>,
|
|
@@ -0,0 +1,18 @@
|
|
|
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 ge="__THREE_LIVE_REGISTRY__";function he(){let T=typeof globalThis<"u"?globalThis:{};if(!T[ge]){let L={plugins:[],decoders:new Map};try{Object.defineProperty(T,ge,{value:L,writable:!1,configurable:!1,enumerable:!1})}catch{T[ge]=L}}return T[ge]}var Mn=he().plugins;function en(T){let L=he();L.workerExtensionInstallers||(L.workerExtensionInstallers=[]),L.workerExtensionInstallers.includes(T)||L.workerExtensionInstallers.push(T)}function nn(T){let L=he().plugins;L.some(O=>O.name===T.name)||L.push(T),T.onRegister?.()}var vn=8192,Sn=2048,Pn=128,wn=4096;function Me(T,L){if(!T||!T.BufferGeometry)return null;let O=T.Vector2,ke=T.Vector3,sn=T.Quaternion,de=T.Matrix4,on=T.Matrix3,rn=T.Color,X=T.BufferAttribute,ne=T.BufferGeometry,cn=T.Material,Ge=T.MeshStandardMaterial,me=T.Mesh,ue=8192,te=2048,Ce=128,ve=4096,B=(t,e)=>{let n=t==null?NaN:Number(t);return Number.isFinite(n)?n:e};class ye{constructor(e){this.currentPoint=new O(0,0),this.segments=[],Array.isArray(e)&&e.length>0&&this.fromPoints(e)}fromPoints(e){if(!e.length)return this;this.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)this.lineTo(e[n].x,e[n].y);return this}moveTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.currentPoint.set(s,o),this.segments.push({type:"move",pts:[s,o]}),this}lineTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(s,o),this.segments.push({type:"line",pts:[s,o]}),this}quadraticCurveTo(e,n,s,o){let i=this.currentPoint.x,c=this.currentPoint.y,a=Number(e)||0,u=Number(n)||0,r=Number(s)||0,h=Number(o)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[i,c]}),this.currentPoint.set(r,h),this.segments.push({type:"quad",pts:[i,c,a,u,r,h]}),this}bezierCurveTo(e,n,s,o,i,c){let a=this.currentPoint.x,u=this.currentPoint.y,r=Number(e)||0,h=Number(n)||0,m=Number(s)||0,l=Number(o)||0,f=Number(i)||0,x=Number(c)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[a,u]}),this.currentPoint.set(f,x),this.segments.push({type:"cubic",pts:[a,u,r,h,m,l,f,x]}),this}absarc(e,n,s,o,i,c=!1){return this.absellipse(e,n,s,s,o,i,c,0)}arc(e,n,s,o,i,c=!1){return this.absarc(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c)}absellipse(e,n,s,o,i,c,a=!1,u=0){let r=Number(e)||0,h=Number(n)||0,m=Math.max(0,Number(s)||0),l=Math.max(0,Number(o)||0),f=Number(i)||0,x=Number(c)||0,b=a?1:0,p=Number(u)||0;this.segments.push({type:"arc",pts:[r,h,m,l,f,x,b,p]});let y=Math.cos(p),g=Math.sin(p),S=m*Math.cos(x),d=l*Math.sin(x);return this.currentPoint.set(r+S*y-d*g,h+S*g+d*y),this}ellipse(e,n,s,o,i,c,a=!1,u=0){return this.absellipse(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c,a,u)}closePath(){if(this.segments.length>0){let e=this.segments[0],n=0,s=0;if(e.type==="arc"){let o=e.pts[0],i=e.pts[1],c=e.pts[2],a=e.pts[3],u=e.pts[4],r=e.pts[7],h=Math.cos(r),m=Math.sin(r),l=c*Math.cos(u),f=a*Math.sin(u);n=o+l*h-f*m,s=i+l*m+f*h}else n=e.pts[0],s=e.pts[1];Math.hypot(this.currentPoint.x-n,this.currentPoint.y-s)>1e-6&&this.lineTo(n,s)}return this}getPoints(e=12){let n=Math.max(1,Math.min(128,Math.floor(Number(e)||12))),s=[],o=(i,c)=>{if(s.length>0){let a=s[s.length-1];if(Math.hypot(a.x-i,a.y-c)<1e-6)return}s.push(new O(i,c))};for(let i of this.segments){let c=i.pts;if(i.type==="move"||i.type==="line")o(c[0],c[1]);else if(i.type==="quad"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5];o(a,u);for(let f=1;f<=n;f++){let x=f/n,b=1-x;o(b*b*a+2*b*x*r+x*x*m,b*b*u+2*b*x*h+x*x*l)}}else if(i.type==="cubic"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6],x=c[7];o(a,u);for(let b=1;b<=n;b++){let p=b/n,y=1-p,g=y*y,S=p*p;o(g*y*a+3*g*p*r+3*y*S*m+S*p*f,g*y*u+3*g*p*h+3*y*S*l+S*p*x)}}else if(i.type==="arc"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6]!==0,x=c[7],b=Math.PI*2,p=l-m,y=Math.abs(p)<1e-9;for(;p<0;)p+=b;for(;p>b;)p-=b;p<1e-9&&(p=y?0:b),f&&!y&&(p=p===b?-b:p-b);let g=Math.cos(x),S=Math.sin(x),d=Math.max(2,n);for(let G=0;G<=d;G++){let P=G/d,E=m+P*p,M=r*Math.cos(E),C=h*Math.sin(E);o(a+M*g-C*S,u+M*S+C*g)}}}if(s.length>2){let i=s[0],c=s[s.length-1];Math.hypot(i.x-c.x,i.y-c.y)<1e-6&&s.pop()}return s}getSpacedPoints(e=12){return this.getPoints(e)}}class fe extends ye{constructor(e){super(e),this.holes=[]}extractPoints(e=12){return{shape:this.getPoints(e),holes:this.holes.map(n=>n.getPoints(e))}}}function xe(t){let e=0,n=t.length;for(let s=0,o=n-1;s<n;o=s++)e+=t[o].x*t[s].y-t[s].x*t[o].y;return e*.5}function an(t,e,n,s,o,i,c,a){let u=c-n,r=a-s,h=o-n,m=i-s,l=t-n,f=e-s,x=u*u+r*r,b=u*h+r*m,p=u*l+r*f,y=h*h+m*m,g=h*l+m*f,S=x*y-b*b;if(Math.abs(S)<1e-12)return!1;let d=1/S,G=(y*p-b*g)*d,P=(x*g-b*p)*d;return G>=-1e-7&&P>=-1e-7&&G+P<=1+1e-7}function Te(t,e){let n=t.slice();xe(n)<0&&n.reverse();let s=n.map(u=>new O(u.x,u.y)),o=n.map((u,r)=>r),i=[];for(let u of e){if(!u||u.length<3)continue;let r=u.slice();xe(r)>0&&r.reverse();let h=[],m=-1/0,l=0;for(let f=0;f<r.length;f++){let x=r[f],b=s.length;s.push(new O(x.x,x.y)),h.push(b),x.x>m&&(m=x.x,l=f)}i.push({pts:r,indices:h,maxX:m,maxIdx:l})}i.sort((u,r)=>r.maxX-u.maxX);let c=(u,r,h)=>(r.x-u.x)*(h.y-u.y)-(r.y-u.y)*(h.x-u.x),a=(u,r,h)=>{for(let m=0;m<h.length;m++){let l=h[m],f=h[(m+1)%h.length];if(c(u,r,l)*c(u,r,f)<0&&c(l,f,u)*c(l,f,r)<0)return!0}return!1};for(let u of i){let r=u.pts[u.maxIdx],h=r.x,m=o.length,l=o.map(y=>s[y]),f=y=>Math.hypot(l[y].x-h,l[y].y-r.y),x=l.map((y,g)=>g).sort((y,g)=>+(l[y].x<h)-+(l[g].x<h)||f(y)-f(g)),b=x[0];for(let y of x){let g=l[y],S=l[(y+m-1)%m],d=l[(y+1)%m],G=c(g,d,r)>=0,P=c(S,g,r)>=0;if((c(S,g,d)>=0?G&&P:G||P)&&!a(r,g,l)&&!i.some(M=>a(r,g,M.pts))){b=y;break}}let p=[];for(let y=0;y<=b;y++)p.push(o[y]);for(let y=0;y<=u.indices.length;y++){let g=u.indices[(u.maxIdx+y)%u.indices.length];p.push(g)}for(let y=b;y<o.length;y++)p.push(o[y]);o=p}return{merged:o.map(u=>s[u]),mergedIndices:o,allVertices:s}}function Le(t,e){let n=[],s=t.slice();if(s.length<3)return n;let o=s.length*s.length+64,i=0;for(;s.length>2&&o-- >0;){let c=s.length,a=s[(i+c-1)%c],u=s[i%c],r=s[(i+1)%c],h=e[a],m=e[u],l=e[r];if((m.x-h.x)*(l.y-h.y)-(m.y-h.y)*(l.x-h.x)>1e-9){let x=!0;for(let b=0;b<c;b++){let p=s[b];if(p===a||p===u||p===r)continue;let y=e[p];if(an(y.x,y.y,h.x,h.y,m.x,m.y,l.x,l.y)&&Math.hypot(y.x-h.x,y.y-h.y)>=1e-6&&Math.hypot(y.x-m.x,y.y-m.y)>=1e-6&&Math.hypot(y.x-l.x,y.y-l.y)>=1e-6){x=!1;break}}if(x){n.push([a,u,r]),s.splice(i%c,1),i=Math.max(0,i%c-1);continue}}i++,i>=c*2&&(n.push([a,u,r]),s.splice((i-1)%c,1),i=0)}return n}function Ee(t,e){let n=t instanceof fe?t.extractPoints(e):{shape:t.getPoints(e),holes:[]},s=n.shape.length;for(let o of n.holes)s+=o.length;if(s>ve)throw new RangeError(`SecurityError: shape point count (${s}) exceeds MAX_SHAPE_POINTS (${ve})`);return n}class un extends ne{constructor(e=new fe,n=12){super();let s=Array.isArray(e)?e:[e],o=[],i=[],c=[],a=[];for(let u of s){if(!(u instanceof ye))continue;let r=Ee(u,n);if(r.shape.length<3)continue;let{mergedIndices:h,allVertices:m}=Te(r.shape,r.holes),l=Le(h,m),f=o.length/3,x=1/0,b=1/0,p=-1/0,y=-1/0;for(let d of m)d.x<x&&(x=d.x),d.y<b&&(b=d.y),d.x>p&&(p=d.x),d.y>y&&(y=d.y);let g=Math.max(1e-6,p-x),S=Math.max(1e-6,y-b);for(let d of m)o.push(d.x,d.y,0),i.push(0,0,1),c.push((d.x-x)/g,(d.y-b)/S);for(let[d,G,P]of l)a.push(f+d,f+G,f+P)}this.setAttribute("position",new X(new Float32Array(o),3)),this.setAttribute("normal",new X(new Float32Array(i),3)),this.setAttribute("uv",new X(new Float32Array(c),2)),this.setIndex(a)}}function ln(t){let e=t.length,n=[];for(let s=0;s<e;s++){let o=t[(s+e-1)%e],i=t[s],c=t[(s+1)%e],a=i.x-o.x,u=i.y-o.y,r=Math.hypot(a,u)||1;a/=r,u/=r;let h=c.x-i.x,m=c.y-i.y,l=Math.hypot(h,m)||1;h/=l,m/=l;let f=u,x=-a,b=m,p=-h,y=f+b,g=x+p,S=Math.hypot(y,g);if(S>1e-6){y/=S,g/=S;let d=Math.max(.35,y*f+g*x);n.push(new O(y/d,g/d))}else n.push(new O(f,x))}return n}class hn extends ne{constructor(e=new fe,n={}){super();let s=Array.isArray(e)?e:[e],o=Math.max(1,Math.min(64,Math.floor(B(n.curveSegments,12)))),i=B(n.depth??n.amount,1),c=Math.max(1,Math.min(32,Math.floor(B(n.steps,1)))),a=!!(n.bevelEnabled??!1),u=a?Math.max(0,B(n.bevelThickness,.06)):0,r=a?Math.max(0,B(n.bevelSize,u*.8)):0,h=a?B(n.bevelOffset,0):0,m=a?Math.max(1,Math.min(8,Math.floor(B(n.bevelSegments,2)))):0,l=[],f=[],x=[],b=[];for(let p of s){if(!(p instanceof ye))continue;let y=Ee(p,o);if(y.shape.length<3)continue;let g=y.shape.slice();xe(g)<0&&g.reverse();let S=[];for(let v of y.holes){if(v.length<3)continue;let w=v.slice();xe(w)>0&&w.reverse(),S.push(w)}let{mergedIndices:d,allVertices:G}=Te(g,S),P=Le(d,G),E=[g,...S],M=[];for(let v of E){let w=ln(v);for(let k of w)M.push(k)}let C=1/0,z=1/0,V=-1/0,D=-1/0;for(let v of G)v.x<C&&(C=v.x),v.y<z&&(z=v.y),v.x>V&&(V=v.x),v.y>D&&(D=v.y);let I=Math.max(1e-6,V-C),F=Math.max(1e-6,D-z),se=-u,oe=i+u,W=l.length/3;for(let v=0;v<G.length;v++){let w=G[v],k=M[v]??new O(0,0),R=w.x+k.x*h,A=w.y+k.y*h;l.push(R,A,se),f.push(0,0,-1),x.push((R-C)/I,(A-z)/F)}for(let[v,w,k]of P)b.push(W+v,W+k,W+w);let j=l.length/3;for(let v=0;v<G.length;v++){let w=G[v],k=M[v]??new O(0,0),R=w.x+k.x*h,A=w.y+k.y*h;l.push(R,A,oe),f.push(0,0,1),x.push((R-C)/I,(A-z)/F)}for(let[v,w,k]of P)b.push(j+v,j+w,j+k);let _=[];if(a&&m>0)for(let v=0;v<m;v++){let k=v/m*Math.PI/2;_.push({z:-u*Math.cos(k),expand:h+r*Math.sin(k)})}for(let v=0;v<=c;v++){let w=v/c;_.push({z:w*i,expand:h+r})}if(a&&m>0)for(let v=1;v<=m;v++){let k=v/m*Math.PI/2;_.push({z:i+u*Math.sin(k),expand:h+r*Math.cos(k)})}let Y=0;for(let v of E){let w=v.length;for(let k=0;k<_.length-1;k++){let R=_[k],A=_[k+1];for(let N=0;N<w;N++){let H=(N+1)%w,$=v[N],U=v[H],Q=M[Y+N],Z=M[Y+H],K=$.x+Q.x*R.expand,J=$.y+Q.y*R.expand,ee=U.x+Z.x*R.expand,q=U.y+Z.y*R.expand,gn=U.x+Z.x*A.expand,dn=U.y+Z.y*A.expand,Fe=$.x+Q.x*A.expand,Ye=$.y+Q.y*A.expand,He=ee-K,qe=q-J,We=0,je=Fe-K,$e=Ye-J,Ue=A.z-R.z,re=qe*Ue-We*$e,ie=We*je-He*Ue,ce=He*$e-qe*je,we=Math.hypot(re,ie,ce)||1;re/=we,ie/=we,ce/=we;let ae=l.length/3;l.push(K,J,R.z,ee,q,R.z,gn,dn,A.z,Fe,Ye,A.z),f.push(re,ie,ce,re,ie,ce,re,ie,ce,re,ie,ce);let Qe=N/w,Ze=(N+1)/w,Ke=k/(_.length-1),Je=(k+1)/(_.length-1);x.push(Qe,Ke,Ze,Ke,Ze,Je,Qe,Je),b.push(ae,ae+1,ae+2,ae,ae+2,ae+3)}}Y+=w}}this.setAttribute("position",new X(new Float32Array(l),3)),this.setAttribute("normal",new X(new Float32Array(f),3)),this.setAttribute("uv",new X(new Float32Array(x),2)),this.setIndex(b)}}function Re(t){return{x:t.x,y:t.y,z:t.z,nx:t.nx,ny:t.ny,nz:t.nz,u:t.u,v:t.v}}function mn(t){return{x:t.x,y:t.y,z:t.z,nx:-t.nx,ny:-t.ny,nz:-t.nz,u:t.u,v:t.v}}function yn(t,e,n){let s=t.nx+(e.nx-t.nx)*n,o=t.ny+(e.ny-t.ny)*n,i=t.nz+(e.nz-t.nz)*n,c=Math.hypot(s,o,i)||1;return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n,z:t.z+(e.z-t.z)*n,nx:s/c,ny:o/c,nz:i/c,u:t.u+(e.u-t.u)*n,v:t.v+(e.v-t.v)*n}}function fn(t){if(t.length<3)return null;let e=t[0],n=t[1],s=t[2],o=n.x-e.x,i=n.y-e.y,c=n.z-e.z,a=s.x-e.x,u=s.y-e.y,r=s.z-e.z,h=i*r-c*u,m=c*a-o*r,l=o*u-i*a,f=Math.hypot(h,m,l);if(f<1e-9)return null;h/=f,m/=f,l/=f;let x=h*e.x+m*e.y+l*e.z;return{vertices:t,nx:h,ny:m,nz:l,w:x}}function xn(t){t.vertices.reverse();for(let e=0;e<t.vertices.length;e++)t.vertices[e]=mn(t.vertices[e]);t.nx=-t.nx,t.ny=-t.ny,t.nz=-t.nz,t.w=-t.w}let Ae=1e-5,Ve=0,Se=1,be=2,ze=3;function Ie(t,e,n,s,o,i,c,a,u){let r=0,h=[];for(let m=0;m<o.vertices.length;m++){let l=o.vertices[m],f=t*l.x+e*l.y+n*l.z-s,x=f<-Ae?be:f>Ae?Se:Ve;r|=x,h.push(x)}switch(r){case Ve:{t*o.nx+e*o.ny+n*o.nz>0?i.push(o):c.push(o);break}case Se:a.push(o);break;case be:u.push(o);break;case ze:{let m=[],l=[],f=o.vertices.length;for(let g=0;g<f;g++){let S=(g+1)%f,d=h[g],G=h[S],P=o.vertices[g],E=o.vertices[S];if(d!==be&&m.push(P),d!==Se&&l.push(d!==be?Re(P):P),(d|G)===ze){let M=E.x-P.x,C=E.y-P.y,z=E.z-P.z,V=t*M+e*C+n*z,D=Math.abs(V)>1e-12?(s-(t*P.x+e*P.y+n*P.z))/V:.5,I=yn(P,E,Math.max(0,Math.min(1,D)));m.push(I),l.push(Re(I))}}let{nx:x,ny:b,nz:p,w:y}=o;m.length>=3&&a.push({vertices:m,nx:x,ny:b,nz:p,w:y}),l.length>=3&&u.push({vertices:l,nx:x,ny:b,nz:p,w:y});break}default:break}}class le{constructor(e,n=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,e&&e.length>0&&this.build(e,n)}invert(){for(let n=0;n<this.polygons.length;n++)xn(this.polygons[n]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let e=this.front;this.front=this.back,this.back=e}clipPolygons(e,n=0){if(!this.hasPlane||e.length===0)return e.slice();if(n>=te)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${te})`);let s=[],o=[];for(let i=0;i<e.length;i++)Ie(this.nx,this.ny,this.nz,this.w,e[i],s,o,s,o);return this.front&&s.length>0&&(s=this.front.clipPolygons(s,n+1)),this.back?o=o.length>0?this.back.clipPolygons(o,n+1):[]:o=[],s.concat(o)}clipTo(e,n=0){this.polygons.length>0&&(this.polygons=e.clipPolygons(this.polygons,0)),n<te&&(this.front&&this.front.clipTo(e,n+1),this.back&&this.back.clipTo(e,n+1))}allPolygons(e=[]){for(let n=0;n<this.polygons.length;n++)e.push(this.polygons[n]);return this.front&&this.front.allPolygons(e),this.back&&this.back.allPolygons(e),e}build(e,n=0){if(!e.length)return;if(!this.hasPlane){let i=e[0];this.nx=i.nx,this.ny=i.ny,this.nz=i.nz,this.w=i.w,this.hasPlane=!0}if(n>=te)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${te})`);let s=[],o=[];for(let i=0;i<e.length;i++)Ie(this.nx,this.ny,this.nz,this.w,e[i],this.polygons,this.polygons,s,o);s.length>0&&(this.front||(this.front=new le),this.front.build(s,n+1)),o.length>0&&(this.back||(this.back=new le),this.back.build(o,n+1))}}function _e(t,e){let n=t.attributes.position;if(!n||n.count===0)return[];let s=t.attributes.normal,o=t.attributes.uv,i=t.index?t.index.array:null,c=Math.floor(i?i.length/3:n.count/3);if(c>ue)throw new RangeError(`SecurityError: CSG input triangle count (${c}) exceeds MAX_CSG_TRIANGLES (${ue})`);let a=e?e.elements:null,u=a?a[0]*(a[5]*a[10]-a[9]*a[6])-a[4]*(a[1]*a[10]-a[9]*a[2])+a[8]*(a[1]*a[6]-a[5]*a[2])<0:!1,r=a?new on().getNormalMatrix(e).elements:null,h=l=>{let f=n.getX(l),x=n.getY(l),b=n.getZ(l),p=s?s.getX(l):NaN,y=s?s.getY(l):NaN,g=s?s.getZ(l):NaN;if(a&&r){let G=a[0]*f+a[4]*x+a[8]*b+a[12],P=a[1]*f+a[5]*x+a[9]*b+a[13],E=a[2]*f+a[6]*x+a[10]*b+a[14];f=G,x=P,b=E;let M=r[0]*p+r[3]*y+r[6]*g,C=r[1]*p+r[4]*y+r[7]*g,z=r[2]*p+r[5]*y+r[8]*g,V=Math.hypot(M,C,z)||1;p=M/V,y=C/V,g=z/V}let S=o?o.getX(l):0,d=o?o.getY(l):0;return{x:f,y:x,z:b,nx:p,ny:y,nz:g,u:S,v:d}},m=[];for(let l=0;l<c;l++){let f=i?i[l*3]:l*3,x=i?i[l*3+1]:l*3+1,b=i?i[l*3+2]:l*3+2,p=fn(u?[h(f),h(b),h(x)]:[h(f),h(x),h(b)]);p&&m.push(p)}return m}function bn(t){let e=[],n=[],s=[],o=[];for(let c of t){let a=c.vertices;if(a.length<3)continue;let u=e.length/3;for(let r of a)e.push(r.x,r.y,r.z),Number.isFinite(r.nx)&&r.nx*r.nx+r.ny*r.ny+r.nz*r.nz>.5?n.push(r.nx,r.ny,r.nz):n.push(c.nx,c.ny,c.nz),s.push(r.u,r.v);for(let r=1;r<a.length-1;r++)o.push(u,u+r,u+r+1)}let i=new ne;return i.setAttribute("position",new X(new Float32Array(e),3)),i.setAttribute("normal",new X(new Float32Array(n),3)),i.setAttribute("uv",new X(new Float32Array(s),2)),i.setIndex(o),i}function pn(t,e,n){if(t.length+e.length>ue)throw new RangeError(`SecurityError: Combined CSG triangle count (${t.length+e.length}) exceeds MAX_CSG_TRIANGLES (${ue})`);if(t.length===0)return n==="union"?e:[];if(e.length===0)return n==="intersect"?[]:t;let s=new le(t),o=new le(e);return n==="union"?(s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.allPolygons()):n==="subtract"?(s.invert(),s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.invert(),s.allPolygons()):(s.invert(),o.clipTo(s),o.invert(),s.clipTo(o),o.clipTo(s),s.build(o.allPolygons()),s.invert(),s.allPolygons())}function Ne(t,e,n,s=null,o=null){let i=_e(t,s),c=_e(e,o);return bn(pn(i,c,n))}function Pe(t,e,n){let s=t instanceof me||!!t?.isMesh,o=e instanceof me||!!e?.isMesh,i=s?t.geometry:t,c=o?e.geometry:e,a=null;if(o)if(e.updateMatrix(),s){t.updateMatrix();let m=new de().makeScale(1/(t.scale.x||1),1/(t.scale.y||1),1/(t.scale.z||1)),l=Math.hypot(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w)||1,f=new de().compose(new ke(0,0,0),new sn(-t.quaternion.x/l,-t.quaternion.y/l,-t.quaternion.z/l,t.quaternion.w/l),new ke(1,1,1)),x=new de().makeTranslation(-t.position.x,-t.position.y,-t.position.z);a=m.multiply(f).multiply(x).multiply(e.matrix)}else a=e.matrix;let u=Ne(i,c,n,null,a),r=s?t.material:new Ge,h=new me(u,r);return s&&(h.position.copy(t.position),h.quaternion.copy(t.quaternion),h.scale.copy(t.scale),h.name=t.name),h}let pe={toGeometry:Ne,subtract(t,e){return Pe(t,e,"subtract")},union(t,e){return Pe(t,e,"union")},intersect(t,e){return Pe(t,e,"intersect")}},Xe={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class De extends ne{constructor(e="",n={}){super();let s=String(e??"").slice(0,Ce),o=Math.max(.005,Math.min(100,B(n.size,.2))),i=!!(n.bevelEnabled??!1),c=i?Math.max(0,Math.min(2,B(n.bevelThickness,o*.04))):0,a=i?Math.max(0,Math.min(2,B(n.bevelSize,o*.03))):0,u=Math.max(.001,Math.min(20,B(n.depth??n.height,o*.2)))+c*2,r=o*.085+a,h=o*.68,m=o*.82,l=[],f=[],x=[],b=[],p=(S,d,G,P,E,M,C)=>{let z=G-S,V=P-d,D=Math.hypot(z,V),I=1,F=0;D>1e-6&&(I=z/D,F=V/D);let se=-F*E,oe=I*E,W=I*E*.6,j=F*E*.6,_=S-W+se,Y=d-j+oe,v=S-W-se,w=d-j-oe,k=G+W-se,R=P+j-oe,A=G+W+se,N=P+j+oe,H=($,U,Q,Z,K,J,ee)=>{let q=l.length/3;l.push($[0],$[1],$[2],U[0],U[1],U[2],Q[0],Q[1],Q[2],Z[0],Z[1],Z[2]),f.push(K,J,ee,K,J,ee,K,J,ee,K,J,ee),x.push(0,0,1,0,1,1,0,1),b.push(q,q+1,q+2,q,q+2,q+3)};H([_,Y,C],[v,w,C],[k,R,C],[A,N,C],0,0,1),H([v,w,M],[_,Y,M],[A,N,M],[k,R,M],0,0,-1),H([_,Y,M],[v,w,M],[v,w,C],[_,Y,C],-I,-F,0),H([k,R,M],[A,N,M],[A,N,C],[k,R,C],I,F,0),H([v,w,M],[k,R,M],[k,R,C],[v,w,C],F,-I,0),H([A,N,M],[_,Y,M],[_,Y,C],[A,N,C],-F,I,0)},y=0,g=0;for(let S=0;S<s.length;S++){let d=s[S];if(d===`
|
|
18
|
+
`){y=0,g-=o*1.35;continue}if(d===" "||d===" "){y+=m*(d===" "?.75:3);continue}if(d==="\r")continue;let G=d.toUpperCase(),P=d!==G&&d>="a"&&d<="z",E=Xe[G]??Xe["?"],M=P?o*.76:o,C=P?h*.88:h;for(let z of E)for(let V=0;V<z.length-1;V++){let D=z[V],I=z[V+1];p(y+D[0]*C,g+D[1]*M,y+I[0]*C,g+I[1]*M,r,-u*.5,u*.5)}y+=P?m*.88:m}this.setAttribute("position",new X(new Float32Array(l),3)),this.setAttribute("normal",new X(new Float32Array(f),3)),this.setAttribute("uv",new X(new Float32Array(x),2)),this.setIndex(b),n.center!==!1?this.center():this.computeBoundingBox()}}function Be(t){if(!t)return;let e=t,n=t.userData?.xr?.text;if(n!=null&&n!==!1){let o=e.geometry?.attributes?.position;if((!o||o.count===0)&&t.userData._textApplied!==!0){let i="",c=.08,a=.015,u;if(typeof n=="string"||typeof n=="number")i=String(n);else if(typeof n=="object"){let r=n;i=String(r.text??r.value??""),r.size!==void 0&&(c=Number(r.size)||.08),(r.depth!==void 0||r.height!==void 0)&&(a=Number(r.depth??r.height)||c*.2),(typeof r.color=="string"||typeof r.color=="number")&&(u=r.color)}i.trim().length>0&&(e.geometry=new De(i,{size:c,depth:a}),t.userData._textApplied=!0,e.material instanceof cn?u!==void 0&&t.userData._autoTextColorApplied!==!0&&(e.material.color=new rn(u),t.userData._autoTextColorApplied=!0):e.material=new Ge({color:u??16317180}))}}let s=t.userData?.csg;if(s&&typeof s=="object"&&t.userData._csgApplied!==!0&&e.geometry instanceof ne&&e.geometry.attributes.position?.count>0){t.userData._csgApplied=!0;let o=Array.isArray(s)?s:[s],i=e.geometry;for(let c of o){if(!c||typeof c!="object")continue;let a=c,u=String(a.op??a.operation??"subtract"),r=u==="union"||u==="intersect"?u:"subtract",h=a.target??a.mesh??a.geometry;if(h instanceof me||h instanceof ne)try{let m=r==="union"?pe.union(e,h):r==="intersect"?pe.intersect(e,h):pe.subtract(e,h);e.geometry!==i&&e.geometry.dispose?.(),e.geometry=m.geometry}catch(m){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",m)}}}}let Oe={Path:ye,Shape:fe,ShapeGeometry:un,ExtrudeGeometry:hn,TextGeometry:De,CSG:pe,MAX_CSG_TRIANGLES:ue,MAX_BSP_DEPTH:te,MAX_TEXT_GEOMETRY_CHARS:Ce,MAX_SHAPE_POINTS:ve,materializeDeclarativeGeometry:Be};return L&&typeof L=="object"&&(L.authorNamespace||(L.authorNamespace={}),Object.assign(L.authorNamespace,Oe),L.materializeDeclarativeGeometry=Be),Oe}var tn={name:"cad",onRegister(){en(Me);let T=he(),L=T.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);L&&Me(L,T)}};nn(tn);export{Sn as MAX_BSP_DEPTH,vn as MAX_CSG_TRIANGLES,wn as MAX_SHAPE_POINTS,Pn as MAX_TEXT_GEOMETRY_CHARS,tn as cadPlugin,Me as installCadExtension};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 ThreeLiveCAD=(()=>{var Ce=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var Gn=Object.getOwnPropertyNames;var Cn=Object.prototype.hasOwnProperty;var Tn=(P,C)=>{for(var _ in C)Ce(P,_,{get:C[_],enumerable:!0})},Ln=(P,C,_,le)=>{if(C&&typeof C=="object"||typeof C=="function")for(let ee of Gn(C))!Cn.call(P,ee)&&ee!==_&&Ce(P,ee,{get:()=>C[ee],enumerable:!(le=kn(C,ee))||le.enumerable});return P};var En=P=>Ln(Ce({},"__esModule",{value:!0}),P);var Rn={};Tn(Rn,{MAX_BSP_DEPTH:()=>cn,MAX_CSG_TRIANGLES:()=>rn,MAX_SHAPE_POINTS:()=>un,MAX_TEXT_GEOMETRY_CHARS:()=>an,cadPlugin:()=>Te,installCadExtension:()=>Se});var ve="__THREE_LIVE_REGISTRY__";function ye(){let P=typeof globalThis<"u"?globalThis:{};if(!P[ve]){let C={plugins:[],decoders:new Map};try{Object.defineProperty(P,ve,{value:C,writable:!1,configurable:!1,enumerable:!1})}catch{P[ve]=C}}return P[ve]}var Vn=ye().plugins;function sn(P){let C=ye();C.workerExtensionInstallers||(C.workerExtensionInstallers=[]),C.workerExtensionInstallers.includes(P)||C.workerExtensionInstallers.push(P)}function on(P){let C=ye().plugins;C.some(_=>_.name===P.name)||C.push(P),P.onRegister?.()}var rn=8192,cn=2048,an=128,un=4096;function Se(P,C){if(!P||!P.BufferGeometry)return null;let _=P.Vector2,le=P.Vector3,ee=P.Quaternion,Pe=P.Matrix4,ln=P.Matrix3,hn=P.Color,D=P.BufferAttribute,te=P.BufferGeometry,mn=P.Material,Le=P.MeshStandardMaterial,fe=P.Mesh,he=8192,se=2048,Ee=128,we=4096,O=(t,e)=>{let n=t==null?NaN:Number(t);return Number.isFinite(n)?n:e};class xe{constructor(e){this.currentPoint=new _(0,0),this.segments=[],Array.isArray(e)&&e.length>0&&this.fromPoints(e)}fromPoints(e){if(!e.length)return this;this.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)this.lineTo(e[n].x,e[n].y);return this}moveTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.currentPoint.set(s,o),this.segments.push({type:"move",pts:[s,o]}),this}lineTo(e,n){let s=Number(e)||0,o=Number(n)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(s,o),this.segments.push({type:"line",pts:[s,o]}),this}quadraticCurveTo(e,n,s,o){let i=this.currentPoint.x,c=this.currentPoint.y,a=Number(e)||0,u=Number(n)||0,r=Number(s)||0,h=Number(o)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[i,c]}),this.currentPoint.set(r,h),this.segments.push({type:"quad",pts:[i,c,a,u,r,h]}),this}bezierCurveTo(e,n,s,o,i,c){let a=this.currentPoint.x,u=this.currentPoint.y,r=Number(e)||0,h=Number(n)||0,m=Number(s)||0,l=Number(o)||0,f=Number(i)||0,x=Number(c)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[a,u]}),this.currentPoint.set(f,x),this.segments.push({type:"cubic",pts:[a,u,r,h,m,l,f,x]}),this}absarc(e,n,s,o,i,c=!1){return this.absellipse(e,n,s,s,o,i,c,0)}arc(e,n,s,o,i,c=!1){return this.absarc(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c)}absellipse(e,n,s,o,i,c,a=!1,u=0){let r=Number(e)||0,h=Number(n)||0,m=Math.max(0,Number(s)||0),l=Math.max(0,Number(o)||0),f=Number(i)||0,x=Number(c)||0,b=a?1:0,p=Number(u)||0;this.segments.push({type:"arc",pts:[r,h,m,l,f,x,b,p]});let y=Math.cos(p),g=Math.sin(p),S=m*Math.cos(x),d=l*Math.sin(x);return this.currentPoint.set(r+S*y-d*g,h+S*g+d*y),this}ellipse(e,n,s,o,i,c,a=!1,u=0){return this.absellipse(this.currentPoint.x+(Number(e)||0),this.currentPoint.y+(Number(n)||0),s,o,i,c,a,u)}closePath(){if(this.segments.length>0){let e=this.segments[0],n=0,s=0;if(e.type==="arc"){let o=e.pts[0],i=e.pts[1],c=e.pts[2],a=e.pts[3],u=e.pts[4],r=e.pts[7],h=Math.cos(r),m=Math.sin(r),l=c*Math.cos(u),f=a*Math.sin(u);n=o+l*h-f*m,s=i+l*m+f*h}else n=e.pts[0],s=e.pts[1];Math.hypot(this.currentPoint.x-n,this.currentPoint.y-s)>1e-6&&this.lineTo(n,s)}return this}getPoints(e=12){let n=Math.max(1,Math.min(128,Math.floor(Number(e)||12))),s=[],o=(i,c)=>{if(s.length>0){let a=s[s.length-1];if(Math.hypot(a.x-i,a.y-c)<1e-6)return}s.push(new _(i,c))};for(let i of this.segments){let c=i.pts;if(i.type==="move"||i.type==="line")o(c[0],c[1]);else if(i.type==="quad"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5];o(a,u);for(let f=1;f<=n;f++){let x=f/n,b=1-x;o(b*b*a+2*b*x*r+x*x*m,b*b*u+2*b*x*h+x*x*l)}}else if(i.type==="cubic"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6],x=c[7];o(a,u);for(let b=1;b<=n;b++){let p=b/n,y=1-p,g=y*y,S=p*p;o(g*y*a+3*g*p*r+3*y*S*m+S*p*f,g*y*u+3*g*p*h+3*y*S*l+S*p*x)}}else if(i.type==="arc"){let a=c[0],u=c[1],r=c[2],h=c[3],m=c[4],l=c[5],f=c[6]!==0,x=c[7],b=Math.PI*2,p=l-m,y=Math.abs(p)<1e-9;for(;p<0;)p+=b;for(;p>b;)p-=b;p<1e-9&&(p=y?0:b),f&&!y&&(p=p===b?-b:p-b);let g=Math.cos(x),S=Math.sin(x),d=Math.max(2,n);for(let T=0;T<=d;T++){let w=T/d,E=m+w*p,k=r*Math.cos(E),L=h*Math.sin(E);o(a+k*g-L*S,u+k*S+L*g)}}}if(s.length>2){let i=s[0],c=s[s.length-1];Math.hypot(i.x-c.x,i.y-c.y)<1e-6&&s.pop()}return s}getSpacedPoints(e=12){return this.getPoints(e)}}class be extends xe{constructor(e){super(e),this.holes=[]}extractPoints(e=12){return{shape:this.getPoints(e),holes:this.holes.map(n=>n.getPoints(e))}}}function pe(t){let e=0,n=t.length;for(let s=0,o=n-1;s<n;o=s++)e+=t[o].x*t[s].y-t[s].x*t[o].y;return e*.5}function yn(t,e,n,s,o,i,c,a){let u=c-n,r=a-s,h=o-n,m=i-s,l=t-n,f=e-s,x=u*u+r*r,b=u*h+r*m,p=u*l+r*f,y=h*h+m*m,g=h*l+m*f,S=x*y-b*b;if(Math.abs(S)<1e-12)return!1;let d=1/S,T=(y*p-b*g)*d,w=(x*g-b*p)*d;return T>=-1e-7&&w>=-1e-7&&T+w<=1+1e-7}function Re(t,e){let n=t.slice();pe(n)<0&&n.reverse();let s=n.map(u=>new _(u.x,u.y)),o=n.map((u,r)=>r),i=[];for(let u of e){if(!u||u.length<3)continue;let r=u.slice();pe(r)>0&&r.reverse();let h=[],m=-1/0,l=0;for(let f=0;f<r.length;f++){let x=r[f],b=s.length;s.push(new _(x.x,x.y)),h.push(b),x.x>m&&(m=x.x,l=f)}i.push({pts:r,indices:h,maxX:m,maxIdx:l})}i.sort((u,r)=>r.maxX-u.maxX);let c=(u,r,h)=>(r.x-u.x)*(h.y-u.y)-(r.y-u.y)*(h.x-u.x),a=(u,r,h)=>{for(let m=0;m<h.length;m++){let l=h[m],f=h[(m+1)%h.length];if(c(u,r,l)*c(u,r,f)<0&&c(l,f,u)*c(l,f,r)<0)return!0}return!1};for(let u of i){let r=u.pts[u.maxIdx],h=r.x,m=o.length,l=o.map(y=>s[y]),f=y=>Math.hypot(l[y].x-h,l[y].y-r.y),x=l.map((y,g)=>g).sort((y,g)=>+(l[y].x<h)-+(l[g].x<h)||f(y)-f(g)),b=x[0];for(let y of x){let g=l[y],S=l[(y+m-1)%m],d=l[(y+1)%m],T=c(g,d,r)>=0,w=c(S,g,r)>=0;if((c(S,g,d)>=0?T&&w:T||w)&&!a(r,g,l)&&!i.some(k=>a(r,g,k.pts))){b=y;break}}let p=[];for(let y=0;y<=b;y++)p.push(o[y]);for(let y=0;y<=u.indices.length;y++){let g=u.indices[(u.maxIdx+y)%u.indices.length];p.push(g)}for(let y=b;y<o.length;y++)p.push(o[y]);o=p}return{merged:o.map(u=>s[u]),mergedIndices:o,allVertices:s}}function Ae(t,e){let n=[],s=t.slice();if(s.length<3)return n;let o=s.length*s.length+64,i=0;for(;s.length>2&&o-- >0;){let c=s.length,a=s[(i+c-1)%c],u=s[i%c],r=s[(i+1)%c],h=e[a],m=e[u],l=e[r];if((m.x-h.x)*(l.y-h.y)-(m.y-h.y)*(l.x-h.x)>1e-9){let x=!0;for(let b=0;b<c;b++){let p=s[b];if(p===a||p===u||p===r)continue;let y=e[p];if(yn(y.x,y.y,h.x,h.y,m.x,m.y,l.x,l.y)&&Math.hypot(y.x-h.x,y.y-h.y)>=1e-6&&Math.hypot(y.x-m.x,y.y-m.y)>=1e-6&&Math.hypot(y.x-l.x,y.y-l.y)>=1e-6){x=!1;break}}if(x){n.push([a,u,r]),s.splice(i%c,1),i=Math.max(0,i%c-1);continue}}i++,i>=c*2&&(n.push([a,u,r]),s.splice((i-1)%c,1),i=0)}return n}function Ve(t,e){let n=t instanceof be?t.extractPoints(e):{shape:t.getPoints(e),holes:[]},s=n.shape.length;for(let o of n.holes)s+=o.length;if(s>we)throw new RangeError(`SecurityError: shape point count (${s}) exceeds MAX_SHAPE_POINTS (${we})`);return n}class fn extends te{constructor(e=new be,n=12){super();let s=Array.isArray(e)?e:[e],o=[],i=[],c=[],a=[];for(let u of s){if(!(u instanceof xe))continue;let r=Ve(u,n);if(r.shape.length<3)continue;let{mergedIndices:h,allVertices:m}=Re(r.shape,r.holes),l=Ae(h,m),f=o.length/3,x=1/0,b=1/0,p=-1/0,y=-1/0;for(let d of m)d.x<x&&(x=d.x),d.y<b&&(b=d.y),d.x>p&&(p=d.x),d.y>y&&(y=d.y);let g=Math.max(1e-6,p-x),S=Math.max(1e-6,y-b);for(let d of m)o.push(d.x,d.y,0),i.push(0,0,1),c.push((d.x-x)/g,(d.y-b)/S);for(let[d,T,w]of l)a.push(f+d,f+T,f+w)}this.setAttribute("position",new D(new Float32Array(o),3)),this.setAttribute("normal",new D(new Float32Array(i),3)),this.setAttribute("uv",new D(new Float32Array(c),2)),this.setIndex(a)}}function xn(t){let e=t.length,n=[];for(let s=0;s<e;s++){let o=t[(s+e-1)%e],i=t[s],c=t[(s+1)%e],a=i.x-o.x,u=i.y-o.y,r=Math.hypot(a,u)||1;a/=r,u/=r;let h=c.x-i.x,m=c.y-i.y,l=Math.hypot(h,m)||1;h/=l,m/=l;let f=u,x=-a,b=m,p=-h,y=f+b,g=x+p,S=Math.hypot(y,g);if(S>1e-6){y/=S,g/=S;let d=Math.max(.35,y*f+g*x);n.push(new _(y/d,g/d))}else n.push(new _(f,x))}return n}class bn extends te{constructor(e=new be,n={}){super();let s=Array.isArray(e)?e:[e],o=Math.max(1,Math.min(64,Math.floor(O(n.curveSegments,12)))),i=O(n.depth??n.amount,1),c=Math.max(1,Math.min(32,Math.floor(O(n.steps,1)))),a=!!(n.bevelEnabled??!1),u=a?Math.max(0,O(n.bevelThickness,.06)):0,r=a?Math.max(0,O(n.bevelSize,u*.8)):0,h=a?O(n.bevelOffset,0):0,m=a?Math.max(1,Math.min(8,Math.floor(O(n.bevelSegments,2)))):0,l=[],f=[],x=[],b=[];for(let p of s){if(!(p instanceof xe))continue;let y=Ve(p,o);if(y.shape.length<3)continue;let g=y.shape.slice();pe(g)<0&&g.reverse();let S=[];for(let v of y.holes){if(v.length<3)continue;let M=v.slice();pe(M)>0&&M.reverse(),S.push(M)}let{mergedIndices:d,allVertices:T}=Re(g,S),w=Ae(d,T),E=[g,...S],k=[];for(let v of E){let M=xn(v);for(let G of M)k.push(G)}let L=1/0,z=1/0,V=-1/0,B=-1/0;for(let v of T)v.x<L&&(L=v.x),v.y<z&&(z=v.y),v.x>V&&(V=v.x),v.y>B&&(B=v.y);let I=Math.max(1e-6,V-L),F=Math.max(1e-6,B-z),oe=-u,re=i+u,W=l.length/3;for(let v=0;v<T.length;v++){let M=T[v],G=k[v]??new _(0,0),R=M.x+G.x*h,A=M.y+G.y*h;l.push(R,A,oe),f.push(0,0,-1),x.push((R-L)/I,(A-z)/F)}for(let[v,M,G]of w)b.push(W+v,W+G,W+M);let j=l.length/3;for(let v=0;v<T.length;v++){let M=T[v],G=k[v]??new _(0,0),R=M.x+G.x*h,A=M.y+G.y*h;l.push(R,A,re),f.push(0,0,1),x.push((R-L)/I,(A-z)/F)}for(let[v,M,G]of w)b.push(j+v,j+M,j+G);let N=[];if(a&&m>0)for(let v=0;v<m;v++){let G=v/m*Math.PI/2;N.push({z:-u*Math.cos(G),expand:h+r*Math.sin(G)})}for(let v=0;v<=c;v++){let M=v/c;N.push({z:M*i,expand:h+r})}if(a&&m>0)for(let v=1;v<=m;v++){let G=v/m*Math.PI/2;N.push({z:i+u*Math.sin(G),expand:h+r*Math.cos(G)})}let Y=0;for(let v of E){let M=v.length;for(let G=0;G<N.length-1;G++){let R=N[G],A=N[G+1];for(let X=0;X<M;X++){let H=(X+1)%M,$=v[X],U=v[H],Q=k[Y+X],Z=k[Y+H],K=$.x+Q.x*R.expand,J=$.y+Q.y*R.expand,ne=U.x+Z.x*R.expand,q=U.y+Z.y*R.expand,wn=U.x+Z.x*A.expand,Mn=U.y+Z.y*A.expand,qe=$.x+Q.x*A.expand,We=$.y+Q.y*A.expand,je=ne-K,$e=q-J,Ue=0,Qe=qe-K,Ze=We-J,Ke=A.z-R.z,ie=$e*Ke-Ue*Ze,ce=Ue*Qe-je*Ke,ae=je*Ze-$e*Qe,Ge=Math.hypot(ie,ce,ae)||1;ie/=Ge,ce/=Ge,ae/=Ge;let ue=l.length/3;l.push(K,J,R.z,ne,q,R.z,wn,Mn,A.z,qe,We,A.z),f.push(ie,ce,ae,ie,ce,ae,ie,ce,ae,ie,ce,ae);let Je=X/M,en=(X+1)/M,nn=G/(N.length-1),tn=(G+1)/(N.length-1);x.push(Je,nn,en,nn,en,tn,Je,tn),b.push(ue,ue+1,ue+2,ue,ue+2,ue+3)}}Y+=M}}this.setAttribute("position",new D(new Float32Array(l),3)),this.setAttribute("normal",new D(new Float32Array(f),3)),this.setAttribute("uv",new D(new Float32Array(x),2)),this.setIndex(b)}}function ze(t){return{x:t.x,y:t.y,z:t.z,nx:t.nx,ny:t.ny,nz:t.nz,u:t.u,v:t.v}}function pn(t){return{x:t.x,y:t.y,z:t.z,nx:-t.nx,ny:-t.ny,nz:-t.nz,u:t.u,v:t.v}}function gn(t,e,n){let s=t.nx+(e.nx-t.nx)*n,o=t.ny+(e.ny-t.ny)*n,i=t.nz+(e.nz-t.nz)*n,c=Math.hypot(s,o,i)||1;return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n,z:t.z+(e.z-t.z)*n,nx:s/c,ny:o/c,nz:i/c,u:t.u+(e.u-t.u)*n,v:t.v+(e.v-t.v)*n}}function dn(t){if(t.length<3)return null;let e=t[0],n=t[1],s=t[2],o=n.x-e.x,i=n.y-e.y,c=n.z-e.z,a=s.x-e.x,u=s.y-e.y,r=s.z-e.z,h=i*r-c*u,m=c*a-o*r,l=o*u-i*a,f=Math.hypot(h,m,l);if(f<1e-9)return null;h/=f,m/=f,l/=f;let x=h*e.x+m*e.y+l*e.z;return{vertices:t,nx:h,ny:m,nz:l,w:x}}function vn(t){t.vertices.reverse();for(let e=0;e<t.vertices.length;e++)t.vertices[e]=pn(t.vertices[e]);t.nx=-t.nx,t.ny=-t.ny,t.nz=-t.nz,t.w=-t.w}let Ie=1e-5,_e=0,Me=1,ge=2,Ne=3;function Xe(t,e,n,s,o,i,c,a,u){let r=0,h=[];for(let m=0;m<o.vertices.length;m++){let l=o.vertices[m],f=t*l.x+e*l.y+n*l.z-s,x=f<-Ie?ge:f>Ie?Me:_e;r|=x,h.push(x)}switch(r){case _e:{t*o.nx+e*o.ny+n*o.nz>0?i.push(o):c.push(o);break}case Me:a.push(o);break;case ge:u.push(o);break;case Ne:{let m=[],l=[],f=o.vertices.length;for(let g=0;g<f;g++){let S=(g+1)%f,d=h[g],T=h[S],w=o.vertices[g],E=o.vertices[S];if(d!==ge&&m.push(w),d!==Me&&l.push(d!==ge?ze(w):w),(d|T)===Ne){let k=E.x-w.x,L=E.y-w.y,z=E.z-w.z,V=t*k+e*L+n*z,B=Math.abs(V)>1e-12?(s-(t*w.x+e*w.y+n*w.z))/V:.5,I=gn(w,E,Math.max(0,Math.min(1,B)));m.push(I),l.push(ze(I))}}let{nx:x,ny:b,nz:p,w:y}=o;m.length>=3&&a.push({vertices:m,nx:x,ny:b,nz:p,w:y}),l.length>=3&&u.push({vertices:l,nx:x,ny:b,nz:p,w:y});break}default:break}}class me{constructor(e,n=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,e&&e.length>0&&this.build(e,n)}invert(){for(let n=0;n<this.polygons.length;n++)vn(this.polygons[n]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let e=this.front;this.front=this.back,this.back=e}clipPolygons(e,n=0){if(!this.hasPlane||e.length===0)return e.slice();if(n>=se)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${se})`);let s=[],o=[];for(let i=0;i<e.length;i++)Xe(this.nx,this.ny,this.nz,this.w,e[i],s,o,s,o);return this.front&&s.length>0&&(s=this.front.clipPolygons(s,n+1)),this.back?o=o.length>0?this.back.clipPolygons(o,n+1):[]:o=[],s.concat(o)}clipTo(e,n=0){this.polygons.length>0&&(this.polygons=e.clipPolygons(this.polygons,0)),n<se&&(this.front&&this.front.clipTo(e,n+1),this.back&&this.back.clipTo(e,n+1))}allPolygons(e=[]){for(let n=0;n<this.polygons.length;n++)e.push(this.polygons[n]);return this.front&&this.front.allPolygons(e),this.back&&this.back.allPolygons(e),e}build(e,n=0){if(!e.length)return;if(!this.hasPlane){let i=e[0];this.nx=i.nx,this.ny=i.ny,this.nz=i.nz,this.w=i.w,this.hasPlane=!0}if(n>=se)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${se})`);let s=[],o=[];for(let i=0;i<e.length;i++)Xe(this.nx,this.ny,this.nz,this.w,e[i],this.polygons,this.polygons,s,o);s.length>0&&(this.front||(this.front=new me),this.front.build(s,n+1)),o.length>0&&(this.back||(this.back=new me),this.back.build(o,n+1))}}function De(t,e){let n=t.attributes.position;if(!n||n.count===0)return[];let s=t.attributes.normal,o=t.attributes.uv,i=t.index?t.index.array:null,c=Math.floor(i?i.length/3:n.count/3);if(c>he)throw new RangeError(`SecurityError: CSG input triangle count (${c}) exceeds MAX_CSG_TRIANGLES (${he})`);let a=e?e.elements:null,u=a?a[0]*(a[5]*a[10]-a[9]*a[6])-a[4]*(a[1]*a[10]-a[9]*a[2])+a[8]*(a[1]*a[6]-a[5]*a[2])<0:!1,r=a?new ln().getNormalMatrix(e).elements:null,h=l=>{let f=n.getX(l),x=n.getY(l),b=n.getZ(l),p=s?s.getX(l):NaN,y=s?s.getY(l):NaN,g=s?s.getZ(l):NaN;if(a&&r){let T=a[0]*f+a[4]*x+a[8]*b+a[12],w=a[1]*f+a[5]*x+a[9]*b+a[13],E=a[2]*f+a[6]*x+a[10]*b+a[14];f=T,x=w,b=E;let k=r[0]*p+r[3]*y+r[6]*g,L=r[1]*p+r[4]*y+r[7]*g,z=r[2]*p+r[5]*y+r[8]*g,V=Math.hypot(k,L,z)||1;p=k/V,y=L/V,g=z/V}let S=o?o.getX(l):0,d=o?o.getY(l):0;return{x:f,y:x,z:b,nx:p,ny:y,nz:g,u:S,v:d}},m=[];for(let l=0;l<c;l++){let f=i?i[l*3]:l*3,x=i?i[l*3+1]:l*3+1,b=i?i[l*3+2]:l*3+2,p=dn(u?[h(f),h(b),h(x)]:[h(f),h(x),h(b)]);p&&m.push(p)}return m}function Sn(t){let e=[],n=[],s=[],o=[];for(let c of t){let a=c.vertices;if(a.length<3)continue;let u=e.length/3;for(let r of a)e.push(r.x,r.y,r.z),Number.isFinite(r.nx)&&r.nx*r.nx+r.ny*r.ny+r.nz*r.nz>.5?n.push(r.nx,r.ny,r.nz):n.push(c.nx,c.ny,c.nz),s.push(r.u,r.v);for(let r=1;r<a.length-1;r++)o.push(u,u+r,u+r+1)}let i=new te;return i.setAttribute("position",new D(new Float32Array(e),3)),i.setAttribute("normal",new D(new Float32Array(n),3)),i.setAttribute("uv",new D(new Float32Array(s),2)),i.setIndex(o),i}function Pn(t,e,n){if(t.length+e.length>he)throw new RangeError(`SecurityError: Combined CSG triangle count (${t.length+e.length}) exceeds MAX_CSG_TRIANGLES (${he})`);if(t.length===0)return n==="union"?e:[];if(e.length===0)return n==="intersect"?[]:t;let s=new me(t),o=new me(e);return n==="union"?(s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.allPolygons()):n==="subtract"?(s.invert(),s.clipTo(o),o.clipTo(s),o.invert(),o.clipTo(s),o.invert(),s.build(o.allPolygons()),s.invert(),s.allPolygons()):(s.invert(),o.clipTo(s),o.invert(),s.clipTo(o),o.clipTo(s),s.build(o.allPolygons()),s.invert(),s.allPolygons())}function Be(t,e,n,s=null,o=null){let i=De(t,s),c=De(e,o);return Sn(Pn(i,c,n))}function ke(t,e,n){let s=t instanceof fe||!!t?.isMesh,o=e instanceof fe||!!e?.isMesh,i=s?t.geometry:t,c=o?e.geometry:e,a=null;if(o)if(e.updateMatrix(),s){t.updateMatrix();let m=new Pe().makeScale(1/(t.scale.x||1),1/(t.scale.y||1),1/(t.scale.z||1)),l=Math.hypot(t.quaternion.x,t.quaternion.y,t.quaternion.z,t.quaternion.w)||1,f=new Pe().compose(new le(0,0,0),new ee(-t.quaternion.x/l,-t.quaternion.y/l,-t.quaternion.z/l,t.quaternion.w/l),new le(1,1,1)),x=new Pe().makeTranslation(-t.position.x,-t.position.y,-t.position.z);a=m.multiply(f).multiply(x).multiply(e.matrix)}else a=e.matrix;let u=Be(i,c,n,null,a),r=s?t.material:new Le,h=new fe(u,r);return s&&(h.position.copy(t.position),h.quaternion.copy(t.quaternion),h.scale.copy(t.scale),h.name=t.name),h}let de={toGeometry:Be,subtract(t,e){return ke(t,e,"subtract")},union(t,e){return ke(t,e,"union")},intersect(t,e){return ke(t,e,"intersect")}},Oe={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class Fe extends te{constructor(e="",n={}){super();let s=String(e??"").slice(0,Ee),o=Math.max(.005,Math.min(100,O(n.size,.2))),i=!!(n.bevelEnabled??!1),c=i?Math.max(0,Math.min(2,O(n.bevelThickness,o*.04))):0,a=i?Math.max(0,Math.min(2,O(n.bevelSize,o*.03))):0,u=Math.max(.001,Math.min(20,O(n.depth??n.height,o*.2)))+c*2,r=o*.085+a,h=o*.68,m=o*.82,l=[],f=[],x=[],b=[],p=(S,d,T,w,E,k,L)=>{let z=T-S,V=w-d,B=Math.hypot(z,V),I=1,F=0;B>1e-6&&(I=z/B,F=V/B);let oe=-F*E,re=I*E,W=I*E*.6,j=F*E*.6,N=S-W+oe,Y=d-j+re,v=S-W-oe,M=d-j-re,G=T+W-oe,R=w+j-re,A=T+W+oe,X=w+j+re,H=($,U,Q,Z,K,J,ne)=>{let q=l.length/3;l.push($[0],$[1],$[2],U[0],U[1],U[2],Q[0],Q[1],Q[2],Z[0],Z[1],Z[2]),f.push(K,J,ne,K,J,ne,K,J,ne,K,J,ne),x.push(0,0,1,0,1,1,0,1),b.push(q,q+1,q+2,q,q+2,q+3)};H([N,Y,L],[v,M,L],[G,R,L],[A,X,L],0,0,1),H([v,M,k],[N,Y,k],[A,X,k],[G,R,k],0,0,-1),H([N,Y,k],[v,M,k],[v,M,L],[N,Y,L],-I,-F,0),H([G,R,k],[A,X,k],[A,X,L],[G,R,L],I,F,0),H([v,M,k],[G,R,k],[G,R,L],[v,M,L],F,-I,0),H([A,X,k],[N,Y,k],[N,Y,L],[A,X,L],-F,I,0)},y=0,g=0;for(let S=0;S<s.length;S++){let d=s[S];if(d===`
|
|
18
|
+
`){y=0,g-=o*1.35;continue}if(d===" "||d===" "){y+=m*(d===" "?.75:3);continue}if(d==="\r")continue;let T=d.toUpperCase(),w=d!==T&&d>="a"&&d<="z",E=Oe[T]??Oe["?"],k=w?o*.76:o,L=w?h*.88:h;for(let z of E)for(let V=0;V<z.length-1;V++){let B=z[V],I=z[V+1];p(y+B[0]*L,g+B[1]*k,y+I[0]*L,g+I[1]*k,r,-u*.5,u*.5)}y+=w?m*.88:m}this.setAttribute("position",new D(new Float32Array(l),3)),this.setAttribute("normal",new D(new Float32Array(f),3)),this.setAttribute("uv",new D(new Float32Array(x),2)),this.setIndex(b),n.center!==!1?this.center():this.computeBoundingBox()}}function Ye(t){if(!t)return;let e=t,n=t.userData?.xr?.text;if(n!=null&&n!==!1){let o=e.geometry?.attributes?.position;if((!o||o.count===0)&&t.userData._textApplied!==!0){let i="",c=.08,a=.015,u;if(typeof n=="string"||typeof n=="number")i=String(n);else if(typeof n=="object"){let r=n;i=String(r.text??r.value??""),r.size!==void 0&&(c=Number(r.size)||.08),(r.depth!==void 0||r.height!==void 0)&&(a=Number(r.depth??r.height)||c*.2),(typeof r.color=="string"||typeof r.color=="number")&&(u=r.color)}i.trim().length>0&&(e.geometry=new Fe(i,{size:c,depth:a}),t.userData._textApplied=!0,e.material instanceof mn?u!==void 0&&t.userData._autoTextColorApplied!==!0&&(e.material.color=new hn(u),t.userData._autoTextColorApplied=!0):e.material=new Le({color:u??16317180}))}}let s=t.userData?.csg;if(s&&typeof s=="object"&&t.userData._csgApplied!==!0&&e.geometry instanceof te&&e.geometry.attributes.position?.count>0){t.userData._csgApplied=!0;let o=Array.isArray(s)?s:[s],i=e.geometry;for(let c of o){if(!c||typeof c!="object")continue;let a=c,u=String(a.op??a.operation??"subtract"),r=u==="union"||u==="intersect"?u:"subtract",h=a.target??a.mesh??a.geometry;if(h instanceof fe||h instanceof te)try{let m=r==="union"?de.union(e,h):r==="intersect"?de.intersect(e,h):de.subtract(e,h);e.geometry!==i&&e.geometry.dispose?.(),e.geometry=m.geometry}catch(m){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",m)}}}}let He={Path:xe,Shape:be,ShapeGeometry:fn,ExtrudeGeometry:bn,TextGeometry:Fe,CSG:de,MAX_CSG_TRIANGLES:he,MAX_BSP_DEPTH:se,MAX_TEXT_GEOMETRY_CHARS:Ee,MAX_SHAPE_POINTS:we,materializeDeclarativeGeometry:Ye};return C&&typeof C=="object"&&(C.authorNamespace||(C.authorNamespace={}),Object.assign(C.authorNamespace,He),C.materializeDeclarativeGeometry=Ye),He}var Te={name:"cad",onRegister(){sn(Se);let P=ye(),C=P.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);C&&Se(C,P)}};on(Te);return En(Rn);})();
|