pixifact-cli 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/editor/assets/Cache-fNcOcM1E.js +1 -0
- package/editor/assets/CanvasPool-BKClwQdf.js +23 -0
- package/editor/assets/Filter-C-9RPzfk.js +1 -0
- package/editor/assets/GCManagedHash-DP1i0eX7.js +221 -0
- package/editor/assets/GraphicsContext-DdtyxZk_.js +1 -0
- package/editor/assets/RenderTargetSystem-ROnUCA9S.js +184 -0
- package/editor/assets/browserAll-B5EqM5Q9.js +14 -0
- package/editor/assets/canvasUtils-B0HNDru7.js +1 -0
- package/editor/assets/capture-9Xl6_ybT.js +1 -0
- package/editor/assets/captureCompilerScenePreview-B5O1JhpJ.js +461 -0
- package/editor/assets/editor-DsAgQsxk.js +4 -0
- package/editor/assets/getTexelRangeRects-CXryyjbK.js +195 -0
- package/editor/assets/getTextureBatchBindGroup-CIH9f4hr.js +1 -0
- package/editor/assets/init-DuDPG7T5.js +83 -0
- package/editor/assets/webworkerAll-BG99WFTY.js +1 -0
- package/editor/capture.html +11 -2
- package/editor/index.html +11 -2
- package/package.json +5 -5
- package/src/automation.ts +16 -16
- package/src/editorServer.ts +37 -3
- package/src/pixifact-cli.ts +1 -1
- package/src/viteTarget.ts +2 -2
- package/editor/assets/browserAll-BJUI9ZxT.js +0 -1
- package/editor/assets/capture-CUhA-7Mo.js +0 -1
- package/editor/assets/captureCompilerScenePreview-4K1ehGWd.js +0 -1126
- package/editor/assets/editor-C18Nctzn.js +0 -5
- package/editor/assets/init-B6Wk-3NE.js +0 -1
- package/editor/assets/webworkerAll-iPsb_ehV.js +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import{L as e,W as t,d as n,i as r,r as i,x as a}from"./CanvasPool-BKClwQdf.js";import{h as o}from"./RenderTargetSystem-ROnUCA9S.js";import{m as s}from"./GCManagedHash-DP1i0eX7.js";var c={name:`local-uniform-bit`,vertex:{header:`
|
|
2
|
+
|
|
3
|
+
struct LocalUniforms {
|
|
4
|
+
uTransformMatrix:mat3x3<f32>,
|
|
5
|
+
uColor:vec4<f32>,
|
|
6
|
+
uRound:f32,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
|
10
|
+
`,main:`
|
|
11
|
+
vColor *= localUniforms.uColor;
|
|
12
|
+
modelMatrix *= localUniforms.uTransformMatrix;
|
|
13
|
+
`,end:`
|
|
14
|
+
if(localUniforms.uRound == 1)
|
|
15
|
+
{
|
|
16
|
+
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
17
|
+
}
|
|
18
|
+
`}},l={...c,vertex:{...c.vertex,header:c.vertex.header.replace(`group(1)`,`group(2)`)}},u={name:`local-uniform-bit`,vertex:{header:`
|
|
19
|
+
|
|
20
|
+
uniform mat3 uTransformMatrix;
|
|
21
|
+
uniform vec4 uColor;
|
|
22
|
+
uniform float uRound;
|
|
23
|
+
`,main:`
|
|
24
|
+
vColor *= uColor;
|
|
25
|
+
modelMatrix = uTransformMatrix;
|
|
26
|
+
`,end:`
|
|
27
|
+
if(uRound == 1.)
|
|
28
|
+
{
|
|
29
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
30
|
+
}
|
|
31
|
+
`}},d={name:`texture-bit`,vertex:{header:`
|
|
32
|
+
|
|
33
|
+
struct TextureUniforms {
|
|
34
|
+
uTextureMatrix:mat3x3<f32>,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
|
|
38
|
+
`,main:`
|
|
39
|
+
uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
40
|
+
`},fragment:{header:`
|
|
41
|
+
@group(2) @binding(0) var uTexture: texture_2d<f32>;
|
|
42
|
+
@group(2) @binding(1) var uSampler: sampler;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
`,main:`
|
|
46
|
+
outColor = textureSample(uTexture, uSampler, vUV);
|
|
47
|
+
`}},f={name:`texture-bit`,vertex:{header:`
|
|
48
|
+
uniform mat3 uTextureMatrix;
|
|
49
|
+
`,main:`
|
|
50
|
+
uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
|
|
51
|
+
`},fragment:{header:`
|
|
52
|
+
uniform sampler2D uTexture;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
`,main:`
|
|
56
|
+
outColor = texture(uTexture, vUV);
|
|
57
|
+
`}};function p(e,t){for(let n in e.attributes){let r=e.attributes[n],i=t[n];i?(r.format??=i.format,r.offset??=i.offset,r.instance??=i.instance):r.format||a(`Attribute ${n} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}m(e)}function m(e){let{buffers:t,attributes:r}=e,i={},a={};for(let e in t){let n=t[e];i[n.uid]=0,a[n.uid]=0}for(let e in r){let t=r[e];i[t.buffer.uid]+=n(t.format).stride}for(let e in r){let t=r[e];t.stride??=i[t.buffer.uid],t.start??=a[t.buffer.uid],a[t.buffer.uid]+=n(t.format).stride}}var h=[];h[s.NONE]=void 0,h[s.DISABLED]={stencilWriteMask:0,stencilReadMask:0},h[s.RENDERING_MASK_ADD]={stencilFront:{compare:`equal`,passOp:`increment-clamp`},stencilBack:{compare:`equal`,passOp:`increment-clamp`}},h[s.RENDERING_MASK_REMOVE]={stencilFront:{compare:`equal`,passOp:`decrement-clamp`},stencilBack:{compare:`equal`,passOp:`decrement-clamp`}},h[s.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:`equal`,passOp:`keep`},stencilBack:{compare:`equal`,passOp:`keep`}},h[s.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:`not-equal`,passOp:`keep`},stencilBack:{compare:`not-equal`,passOp:`keep`}};var g=class{constructor(e){this._syncFunctionHash=Object.create(null),this._adaptor=e,this._systemCheck()}_systemCheck(){if(!o())throw Error(`Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.`)}ensureUniformGroup(e){let t=this.getUniformGroupData(e);e.buffer||=new i({data:new Float32Array(t.layout.size/4),usage:r.UNIFORM|r.COPY_DST})}getUniformGroupData(e){return this._syncFunctionHash[e._signature]||this._initUniformGroup(e)}_initUniformGroup(e){let t=e._signature,n=this._syncFunctionHash[t];if(!n){let r=Object.keys(e.uniformStructures).map(t=>e.uniformStructures[t]),i=this._adaptor.createUboElements(r),a=this._generateUboSync(i.uboElements);n=this._syncFunctionHash[t]={layout:i,syncFunction:a}}return this._syncFunctionHash[t]}_generateUboSync(e){return this._adaptor.generateUboSync(e)}syncUniformGroup(e,t,n){let a=this.getUniformGroupData(e);e.buffer||=new i({data:new Float32Array(a.layout.size/4),usage:r.UNIFORM|r.COPY_DST});let o=null;return t||(t=e.buffer.data,o=e.buffer.dataInt32),n||=0,a.syncFunction(e.uniforms,t,o,n),!0}updateUniformGroup(e){if(e.isStatic&&!e._dirtyId)return!1;e._dirtyId=0;let t=this.syncUniformGroup(e);return e.buffer.update(),t}destroy(){this._syncFunctionHash=null}},_=[{type:`mat3x3<f32>`,test:e=>e.value.a!==void 0,ubo:`
|
|
58
|
+
var matrix = uv[name].toArray(true);
|
|
59
|
+
data[offset] = matrix[0];
|
|
60
|
+
data[offset + 1] = matrix[1];
|
|
61
|
+
data[offset + 2] = matrix[2];
|
|
62
|
+
data[offset + 4] = matrix[3];
|
|
63
|
+
data[offset + 5] = matrix[4];
|
|
64
|
+
data[offset + 6] = matrix[5];
|
|
65
|
+
data[offset + 8] = matrix[6];
|
|
66
|
+
data[offset + 9] = matrix[7];
|
|
67
|
+
data[offset + 10] = matrix[8];
|
|
68
|
+
`,uniform:`
|
|
69
|
+
gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
|
|
70
|
+
`},{type:`vec4<f32>`,test:e=>e.type===`vec4<f32>`&&e.size===1&&e.value.width!==void 0,ubo:`
|
|
71
|
+
v = uv[name];
|
|
72
|
+
data[offset] = v.x;
|
|
73
|
+
data[offset + 1] = v.y;
|
|
74
|
+
data[offset + 2] = v.width;
|
|
75
|
+
data[offset + 3] = v.height;
|
|
76
|
+
`,uniform:`
|
|
77
|
+
cv = ud[name].value;
|
|
78
|
+
v = uv[name];
|
|
79
|
+
if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
|
|
80
|
+
cv[0] = v.x;
|
|
81
|
+
cv[1] = v.y;
|
|
82
|
+
cv[2] = v.width;
|
|
83
|
+
cv[3] = v.height;
|
|
84
|
+
gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
|
|
85
|
+
}
|
|
86
|
+
`},{type:`vec2<f32>`,test:e=>e.type===`vec2<f32>`&&e.size===1&&e.value.x!==void 0,ubo:`
|
|
87
|
+
v = uv[name];
|
|
88
|
+
data[offset] = v.x;
|
|
89
|
+
data[offset + 1] = v.y;
|
|
90
|
+
`,uniform:`
|
|
91
|
+
cv = ud[name].value;
|
|
92
|
+
v = uv[name];
|
|
93
|
+
if (cv[0] !== v.x || cv[1] !== v.y) {
|
|
94
|
+
cv[0] = v.x;
|
|
95
|
+
cv[1] = v.y;
|
|
96
|
+
gl.uniform2f(ud[name].location, v.x, v.y);
|
|
97
|
+
}
|
|
98
|
+
`},{type:`vec4<f32>`,test:e=>e.type===`vec4<f32>`&&e.size===1&&e.value.red!==void 0,ubo:`
|
|
99
|
+
v = uv[name];
|
|
100
|
+
data[offset] = v.red;
|
|
101
|
+
data[offset + 1] = v.green;
|
|
102
|
+
data[offset + 2] = v.blue;
|
|
103
|
+
data[offset + 3] = v.alpha;
|
|
104
|
+
`,uniform:`
|
|
105
|
+
cv = ud[name].value;
|
|
106
|
+
v = uv[name];
|
|
107
|
+
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
|
|
108
|
+
cv[0] = v.red;
|
|
109
|
+
cv[1] = v.green;
|
|
110
|
+
cv[2] = v.blue;
|
|
111
|
+
cv[3] = v.alpha;
|
|
112
|
+
gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
|
|
113
|
+
}
|
|
114
|
+
`},{type:`vec3<f32>`,test:e=>e.type===`vec3<f32>`&&e.size===1&&e.value.red!==void 0,ubo:`
|
|
115
|
+
v = uv[name];
|
|
116
|
+
data[offset] = v.red;
|
|
117
|
+
data[offset + 1] = v.green;
|
|
118
|
+
data[offset + 2] = v.blue;
|
|
119
|
+
`,uniform:`
|
|
120
|
+
cv = ud[name].value;
|
|
121
|
+
v = uv[name];
|
|
122
|
+
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
|
|
123
|
+
cv[0] = v.red;
|
|
124
|
+
cv[1] = v.green;
|
|
125
|
+
cv[2] = v.blue;
|
|
126
|
+
gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
|
|
127
|
+
}
|
|
128
|
+
`}];function v(e,t,n){let r=[`
|
|
129
|
+
var v = null;
|
|
130
|
+
var v2 = null;
|
|
131
|
+
var t = 0;
|
|
132
|
+
var index = 0;
|
|
133
|
+
var name = null;
|
|
134
|
+
var arrayOffset = null;
|
|
135
|
+
`],i=0;for(let a=0;a<e.length;a++){let o=e[a],s=o.data.name,c=!1,l=0;for(let e=0;e<_.length;e++)if(_[e].test(o.data)){l=o.offset/4,r.push(`name = "${s}";`,`offset += ${l-i};`,_[e].ubo),c=!0;break}if(!c){if(o.data.size>1)l=o.offset/4,r.push(n(o,l-i));else{let e=t[o.data.type];l=o.offset/4,r.push(`
|
|
136
|
+
v = uv.${s};
|
|
137
|
+
offset += ${l-i};
|
|
138
|
+
${e};
|
|
139
|
+
`)}}i=l}let a=r.join(`
|
|
140
|
+
`);return Function(`uv`,`data`,`dataInt32`,`offset`,a)}function y(e,t){return`
|
|
141
|
+
for (let i = 0; i < ${e*t}; i++) {
|
|
142
|
+
data[offset + (((i / ${e})|0) * 4) + (i % ${e})] = v[i];
|
|
143
|
+
}
|
|
144
|
+
`}var b={f32:`
|
|
145
|
+
data[offset] = v;`,i32:`
|
|
146
|
+
dataInt32[offset] = v;`,u32:`
|
|
147
|
+
dataInt32[offset] = v;`,"vec2<f32>":`
|
|
148
|
+
data[offset] = v[0];
|
|
149
|
+
data[offset + 1] = v[1];`,"vec3<f32>":`
|
|
150
|
+
data[offset] = v[0];
|
|
151
|
+
data[offset + 1] = v[1];
|
|
152
|
+
data[offset + 2] = v[2];`,"vec4<f32>":`
|
|
153
|
+
data[offset] = v[0];
|
|
154
|
+
data[offset + 1] = v[1];
|
|
155
|
+
data[offset + 2] = v[2];
|
|
156
|
+
data[offset + 3] = v[3];`,"vec2<i32>":`
|
|
157
|
+
dataInt32[offset] = v[0];
|
|
158
|
+
dataInt32[offset + 1] = v[1];`,"vec3<i32>":`
|
|
159
|
+
dataInt32[offset] = v[0];
|
|
160
|
+
dataInt32[offset + 1] = v[1];
|
|
161
|
+
dataInt32[offset + 2] = v[2];`,"vec4<i32>":`
|
|
162
|
+
dataInt32[offset] = v[0];
|
|
163
|
+
dataInt32[offset + 1] = v[1];
|
|
164
|
+
dataInt32[offset + 2] = v[2];
|
|
165
|
+
dataInt32[offset + 3] = v[3];`,"vec2<u32>":`
|
|
166
|
+
dataInt32[offset] = v[0];
|
|
167
|
+
dataInt32[offset + 1] = v[1];`,"vec3<u32>":`
|
|
168
|
+
dataInt32[offset] = v[0];
|
|
169
|
+
dataInt32[offset + 1] = v[1];
|
|
170
|
+
dataInt32[offset + 2] = v[2];`,"vec4<u32>":`
|
|
171
|
+
dataInt32[offset] = v[0];
|
|
172
|
+
dataInt32[offset + 1] = v[1];
|
|
173
|
+
dataInt32[offset + 2] = v[2];
|
|
174
|
+
dataInt32[offset + 3] = v[3];`,"mat2x2<f32>":`
|
|
175
|
+
data[offset] = v[0];
|
|
176
|
+
data[offset + 1] = v[1];
|
|
177
|
+
data[offset + 4] = v[2];
|
|
178
|
+
data[offset + 5] = v[3];`,"mat3x3<f32>":`
|
|
179
|
+
data[offset] = v[0];
|
|
180
|
+
data[offset + 1] = v[1];
|
|
181
|
+
data[offset + 2] = v[2];
|
|
182
|
+
data[offset + 4] = v[3];
|
|
183
|
+
data[offset + 5] = v[4];
|
|
184
|
+
data[offset + 6] = v[5];
|
|
185
|
+
data[offset + 8] = v[6];
|
|
186
|
+
data[offset + 9] = v[7];
|
|
187
|
+
data[offset + 10] = v[8];`,"mat4x4<f32>":`
|
|
188
|
+
for (let i = 0; i < 16; i++) {
|
|
189
|
+
data[offset + i] = v[i];
|
|
190
|
+
}`,"mat3x2<f32>":y(3,2),"mat4x2<f32>":y(4,2),"mat2x3<f32>":y(2,3),"mat4x3<f32>":y(4,3),"mat2x4<f32>":y(2,4),"mat3x4<f32>":y(3,4)},x={...b,"mat2x2<f32>":`
|
|
191
|
+
data[offset] = v[0];
|
|
192
|
+
data[offset + 1] = v[1];
|
|
193
|
+
data[offset + 2] = v[2];
|
|
194
|
+
data[offset + 3] = v[3];
|
|
195
|
+
`},S=class extends t{constructor({buffer:t,offset:n,size:r}){super(),this.uid=e(`buffer`),this._resourceType=`bufferResource`,this._resourceId=e(`resource`),this._bufferResource=!0,this.destroyed=!1,this.buffer=t,this.offset=n|0,this.size=r,this.buffer.on(`change`,this.onBufferChange,this)}get _gcLastUsed(){return this.buffer?._gcLastUsed??-1}set _gcLastUsed(e){this.buffer&&(this.buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=e(`resource`),this.emit(`change`,this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit(`change`,this),this.buffer=null,this.removeAllListeners()}};function C(e,t,n,r,i){if(e=Math.max(0,e),t=Math.min(t,n*r),e>=t)return 0;let a=Math.floor(e/n),o=e-a*n,s=Math.floor(t/n),c=t-s*n;if(a===s)return i[0].set(o,a,c-o,1),1;let l=0,u=a;return o>0&&(i[l++].set(o,a,n-o,1),u++),s>u&&i[l++].set(0,u,n,s-u),c>0&&i[l++].set(0,s,c,1),l}export{v as a,h as c,f as d,c as f,x as i,p as l,l as m,S as n,_ as o,u as p,b as r,g as s,C as t,d as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,w as t}from"./CanvasPool-BKClwQdf.js";var n={};function r(e,t,r){let a=2166136261;for(let n=0;n<t;n++)a^=e[n].uid,a=Math.imul(a,16777619),a>>>=0;return n[a]||i(e,t,a,r)}function i(r,i,a,o){let s={},c=0;for(let e=0;e<o;e++){let n=e<i?r[e]:t.EMPTY.source;s[c++]=n.source,s[c++]=n.style}let l=new e(s);return n[a]=l,l}export{r as t};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import{B as e,C as t,G as n,K as r,c as i,f as a,l as o,n as s,s as c,t as l,u,w as d,x as f}from"./CanvasPool-BKClwQdf.js";import{t as p}from"./canvasUtils-B0HNDru7.js";import{l as m}from"./captureCompilerScenePreview-B5O1JhpJ.js";import{d as h,t as g}from"./Filter-C-9RPzfk.js";var _=new e;function v(e,t){t.clear();let n=t.matrix;for(let n=0;n<e.length;n++){let r=e[n];if(r.globalDisplayStatus<7)continue;let i=r.renderGroup??r.parentRenderGroup;t.matrix=i?.isCachedAsTexture?_.copyFrom(i.textureOffsetInverseTransform).append(r.worldTransform):i?._parentCacheAsTextureRenderGroup?_.copyFrom(i._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(r.groupTransform):r.worldTransform,t.addBounds(r.bounds)}return t.matrix=n,t}function y(e){return typeof e.getCanvasFilterString==`function`}var b=class{constructor(){this.skip=!1,this.useClip=!1,this.filters=null,this.container=null,this.bounds=new t,this.cssFilterString=``}},x=class{constructor(e){this._filterStack=[],this._filterStackIndex=0,this._savedStates=[],this._alphaMultiplier=1,this._warnedFilterTypes=new Set,this.renderer=e}push(e){let t=this._pushFilterFrame(),n=e.filterEffect.filters;if(t.skip=!1,t.useClip=!1,t.filters=n,t.container=e.container,t.cssFilterString=``,n.every(e=>!e.enabled)){t.skip=!0;return}let r=[];for(let e of n){if(!e.enabled)continue;if(!y(e)){this._warnUnsupportedFilter(e);continue}let t=e.getCanvasFilterString();t===null?this._warnUnsupportedFilter(e):t&&r.push(t)}if(r.length===0){t.skip=!0;return}t.cssFilterString=r.join(` `),this._calculateFilterArea(e,t.bounds),t.useClip=!!e.filterEffect.filterArea;let i=this.renderer.canvasContext.activeContext,a=i.filter||`none`;if(this._savedStates.push({filter:a,alphaMultiplier:this._alphaMultiplier}),t.useClip&&Number.isFinite(t.bounds.width)&&Number.isFinite(t.bounds.height)&&t.bounds.width>0&&t.bounds.height>0){let e=this.renderer.canvasContext.activeResolution||1;i.save(),i.setTransform(1,0,0,1,0,0),i.beginPath(),i.rect(t.bounds.x*e,t.bounds.y*e,t.bounds.width*e,t.bounds.height*e),i.clip()}else t.useClip=!1;t.cssFilterString&&(i.filter=a===`none`?t.cssFilterString:`${a} ${t.cssFilterString}`)}pop(){let e=this._popFilterFrame();if(e.skip)return;let t=this._savedStates.pop();if(!t)return;let n=this.renderer.canvasContext.activeContext;e.useClip?n.restore():n.filter=t.filter,this._alphaMultiplier=t.alphaMultiplier}generateFilteredTexture({texture:e,filters:t}){if(!t?.length||t.every(e=>!e.enabled))return e;let n=[];for(let e of t){if(!e.enabled)continue;if(!y(e)){this._warnUnsupportedFilter(e);continue}let t=e.getCanvasFilterString();t===null?this._warnUnsupportedFilter(e):t&&n.push(t)}if(n.length===0)return e;let r=p.getCanvasSource(e);if(!r)return e;let i=e.frame,a=e.source._resolution??e.source.resolution??1,o=i.width,s=i.height,{canvas:c,context:u}=l.getOptimalCanvasAndContext(o,s,a);u.setTransform(1,0,0,1,0,0),u.clearRect(0,0,c.width,c.height),n.length&&(u.filter=n.join(` `));let d=i.x*a,f=i.y*a,h=o*a,g=s*a;return u.drawImage(r,d,f,h,g,0,0,h,g),u.filter=`none`,u.globalAlpha=1,m(c,o,s,a)}_calculateFilterArea(e,t){if(e.renderables?v(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){let n=(e.container.renderGroup||e.container.parentRenderGroup)?.cacheToLocalTransform;n&&t.applyMatrix(n)}}_warnUnsupportedFilter(e){let t=e?.constructor?.name||`Filter`;this._warnedFilterTypes.has(t)||(this._warnedFilterTypes.add(t),console.warn(`CanvasRenderer: filter "${t}" is not supported in Canvas2D and will be skipped.`))}get alphaMultiplier(){return this._alphaMultiplier}_pushFilterFrame(){let e=this._filterStack[this._filterStackIndex];return e||=this._filterStack[this._filterStackIndex]=new b,this._filterStackIndex++,e}_popFilterFrame(){return this._filterStackIndex<=0?this._filterStack[0]:(this._filterStackIndex--,this._filterStack[this._filterStackIndex])}destroy(){this._filterStack=null,this._savedStates=null,this._warnedFilterTypes=null,this._alphaMultiplier=1}};x.extension={type:[n.CanvasSystem],name:`filter`};var S=`in vec2 aPosition;
|
|
2
|
+
out vec2 vTextureCoord;
|
|
3
|
+
|
|
4
|
+
uniform vec4 uInputSize;
|
|
5
|
+
uniform vec4 uOutputFrame;
|
|
6
|
+
uniform vec4 uOutputTexture;
|
|
7
|
+
|
|
8
|
+
vec4 filterVertexPosition( void )
|
|
9
|
+
{
|
|
10
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
11
|
+
|
|
12
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
13
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
14
|
+
|
|
15
|
+
return vec4(position, 0.0, 1.0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
vec2 filterTextureCoord( void )
|
|
19
|
+
{
|
|
20
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void main(void)
|
|
24
|
+
{
|
|
25
|
+
gl_Position = filterVertexPosition();
|
|
26
|
+
vTextureCoord = filterTextureCoord();
|
|
27
|
+
}
|
|
28
|
+
`,C=`in vec2 vTextureCoord;
|
|
29
|
+
out vec4 finalColor;
|
|
30
|
+
uniform sampler2D uTexture;
|
|
31
|
+
void main() {
|
|
32
|
+
finalColor = texture(uTexture, vTextureCoord);
|
|
33
|
+
}
|
|
34
|
+
`,w=`struct GlobalFilterUniforms {
|
|
35
|
+
uInputSize: vec4<f32>,
|
|
36
|
+
uInputPixel: vec4<f32>,
|
|
37
|
+
uInputClamp: vec4<f32>,
|
|
38
|
+
uOutputFrame: vec4<f32>,
|
|
39
|
+
uGlobalFrame: vec4<f32>,
|
|
40
|
+
uOutputTexture: vec4<f32>,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;
|
|
44
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
45
|
+
@group(0) @binding(2) var uSampler: sampler;
|
|
46
|
+
|
|
47
|
+
struct VSOutput {
|
|
48
|
+
@builtin(position) position: vec4<f32>,
|
|
49
|
+
@location(0) uv: vec2<f32>
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
fn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>
|
|
53
|
+
{
|
|
54
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
55
|
+
|
|
56
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
57
|
+
position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
58
|
+
|
|
59
|
+
return vec4(position, 0.0, 1.0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>
|
|
63
|
+
{
|
|
64
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@vertex
|
|
68
|
+
fn mainVertex(
|
|
69
|
+
@location(0) aPosition: vec2<f32>,
|
|
70
|
+
) -> VSOutput {
|
|
71
|
+
return VSOutput(
|
|
72
|
+
filterVertexPosition(aPosition),
|
|
73
|
+
filterTextureCoord(aPosition)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@fragment
|
|
78
|
+
fn mainFragment(
|
|
79
|
+
@location(0) uv: vec2<f32>,
|
|
80
|
+
) -> @location(0) vec4<f32> {
|
|
81
|
+
return textureSample(uTexture, uSampler, uv);
|
|
82
|
+
}
|
|
83
|
+
`,T=class extends g{constructor(){let e=u.from({vertex:{source:w,entryPoint:`mainVertex`},fragment:{source:w,entryPoint:`mainFragment`},name:`passthrough-filter`}),t=a.from({vertex:S,fragment:C,name:`passthrough-filter`});super({gpuProgram:e,glProgram:t})}},E=class{constructor(e){this._renderer=e}push(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`filter`,canBundle:!1,action:`pushFilter`,container:t,filterEffect:e})}pop(e,t,n){this._renderer.renderPipes.batch.break(n),n.add({renderPipeId:`filter`,action:`popFilter`,canBundle:!1})}execute(e){e.action===`pushFilter`?this._renderer.filter.push(e):e.action===`popFilter`&&this._renderer.filter.pop()}destroy(){this._renderer=null}};E.extension={type:[n.WebGLPipes,n.WebGPUPipes,n.CanvasPipes],name:`filter`};var D=new s({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:`float32x2`,stride:8,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])}),O=class{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new t,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.firstEnabledIndex=-1,this.lastEnabledIndex=-1}},k=class{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new o({uInputSize:{value:new Float32Array(4),type:`vec4<f32>`},uInputPixel:{value:new Float32Array(4),type:`vec4<f32>`},uInputClamp:{value:new Float32Array(4),type:`vec4<f32>`},uOutputFrame:{value:new Float32Array(4),type:`vec4<f32>`},uGlobalFrame:{value:new Float32Array(4),type:`vec4<f32>`},uOutputTexture:{value:new Float32Array(4),type:`vec4<f32>`}}),this._globalFilterBindGroup=new i({}),this.renderer=e}get activeBackTexture(){return this._activeFilterData?.backTexture}push(e){let t=this.renderer,n=e.filterEffect.filters,r=this._pushFilterData();r.skip=!1,r.filters=n,r.container=e.container,r.outputRenderSurface=t.renderTarget.renderSurface;let i=t.renderTarget.renderTarget.colorTexture.source,a=i.resolution,o=i.antialias;if(n.every(e=>!e.enabled)){r.skip=!0;return}let s=r.bounds;if(this._calculateFilterArea(e,s),this._calculateFilterBounds(r,t.renderTarget.rootViewPort,o,a,1),r.skip)return;let c=this._getPreviousFilterData();this._setupFilterTextures(r,s,t,c)}generateFilteredTexture({texture:e,filters:t}){if(t.every(e=>!e.enabled))return e;let n=this._pushFilterData();this._activeFilterData=n,n.skip=!1,n.filters=t;let r=e.source,i=r.resolution,a=r.antialias,o=n.bounds;if(o.clear(),o.addRect(e.frame),this._calculateFilterBounds(n,o.rectangle,a,i,0),n.skip)return this._popFilterData(),e;n.outputRenderSurface=h.getOptimalTexture({width:o.width,height:o.height,resolution:n.resolution,antialias:n.antialias}),n.backTexture=d.EMPTY,n.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(n,!0);let s=n.outputRenderSurface;return s.source.alphaMode=`premultiplied-alpha`,this._popFilterData(),s}pop(){let e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&h.returnTexture(t.backTexture),h.returnTexture(t.inputTexture))}getBackTexture(e,t,n){let r=e.colorTexture.source._resolution,i=h.getOptimalTexture({width:t.width,height:t.height,resolution:r}),a=t.minX,o=t.minY;n&&(a-=n.minX,o-=n.minY),a=Math.floor(a*r),o=Math.floor(o*r);let s=Math.ceil(t.width*r),c=Math.ceil(t.height*r);return this.renderer.renderTarget.copyToTexture(e,i,{x:a,y:o},{width:s,height:c},{x:0,y:0}),i}applyFilter(e,t,n,r){let i=this.renderer,a=this._activeFilterData,o=a.outputRenderSurface===n,s=this._findClosestFilterData(),c=s?s.inputTexture.source._resolution:i.renderTarget.rootRenderTarget.colorTexture.source._resolution,l=0,u=0;o&&s&&(l=s.bounds.minX,u=s.bounds.minY),this._updateFilterUniforms(t,n,a,l,u,c,o,r);let d=e.enabled?e:this._getPassthroughFilter();this._setupBindGroupsAndRender(d,t,i)}calculateSpriteMatrix(t,n){let r=this._activeFilterData,i=t.set(r.inputTexture._source.width,0,0,r.inputTexture._source.height,r.bounds.minX,r.bounds.minY),a=n.worldTransform.copyTo(e.shared),o=n.renderGroup||n.parentRenderGroup;return o&&o.cacheToLocalTransform&&a.prepend(o.cacheToLocalTransform),a.invert(),i.prepend(a),i.scale(1/n.texture.orig.width,1/n.texture.orig.height),i.translate(n.anchor.x,n.anchor.y),i}destroy(){this._passthroughFilter?.destroy(!0),this._passthroughFilter=null}_getPassthroughFilter(){return this._passthroughFilter??=new T,this._passthroughFilter}_setupBindGroupsAndRender(e,t,n){if(n.renderPipes.uniformBatch){let e=n.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(e,0)}else this._globalFilterBindGroup.setResource(this._filterGlobalUniforms,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,n.encoder.draw({geometry:D,shader:e,state:e._state,topology:`triangle-list`}),n.type===c.WEBGL&&n.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,n,r){if(e.backTexture=d.EMPTY,e.inputTexture=h.getOptimalTexture({width:t.width,height:t.height,resolution:e.resolution,antialias:e.antialias}),e.blendRequired){n.renderTarget.finishRenderPass();let i=n.renderTarget.getRenderTarget(e.outputRenderSurface);e.backTexture=this.getBackTexture(i,t,r?.bounds)}n.renderTarget.bind({target:e.inputTexture,clear:!0}),n.globalUniforms.push({offset:t})}_updateFilterUniforms(e,t,n,r,i,a,o,s){let c=this._filterGlobalUniforms.uniforms,l=c.uOutputFrame,u=c.uInputSize,f=c.uInputPixel,p=c.uInputClamp,m=c.uGlobalFrame,h=c.uOutputTexture;o?(l[0]=n.bounds.minX-r,l[1]=n.bounds.minY-i):(l[0]=0,l[1]=0),l[2]=e.frame.width,l[3]=e.frame.height,u[0]=e.source.width,u[1]=e.source.height,u[2]=1/u[0],u[3]=1/u[1],f[0]=e.source.pixelWidth,f[1]=e.source.pixelHeight,f[2]=1/f[0],f[3]=1/f[1],p[0]=.5*f[2],p[1]=.5*f[3],p[2]=e.frame.width*u[2]-.5*f[2],p[3]=e.frame.height*u[3]-.5*f[3];let g=this.renderer.renderTarget.rootRenderTarget.colorTexture;m[0]=r*a,m[1]=i*a,m[2]=g.source.width*a,m[3]=g.source.height*a,t instanceof d&&(t.source.resource=null);let _=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind({target:t,clear:!!s}),t instanceof d?(h[0]=t.frame.width,h[1]=t.frame.height):(h[0]=_.width,h[1]=_.height),h[2]=_.isRoot?-1:1,this._filterGlobalUniforms.update()}_findClosestFilterData(){for(let e=this._filterStackIndex-1;e>=0;e--){let t=this._filterStack[e];if(!t.skip)return t}return null}_calculateFilterArea(e,t){if(e.renderables?v(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){let n=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;n&&t.applyMatrix(n)}}_applyFiltersToTexture(e,t){let n=e.inputTexture,r=e.bounds,i=e.filters,a=e.firstEnabledIndex,o=e.lastEnabledIndex;if(this._globalFilterBindGroup.setResource(n.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),a===o)i[a].apply(this,n,e.outputRenderSurface,t);else{let n=e.inputTexture,s=h.getOptimalTexture({width:r.width,height:r.height,resolution:n.source._resolution}),c=s;for(let e=a;e<o;e++){let t=i[e];if(!t.enabled)continue;t.apply(this,n,c,!0);let r=n;n=c,c=r}i[o].apply(this,n,e.outputRenderSurface,t),h.returnTexture(s)}}_calculateFilterBounds(e,t,n,r,i){let a=this.renderer,o=e.bounds,s=e.filters,c=1/0,l=0,u=!0,d=!1,p=!1,m=!0,h=-1,g=-1;for(let e=0;e<s.length;e++){let t=s[e];if(t.enabled){if(h===-1&&(h=e),g=e,c=Math.min(c,t.resolution===`inherit`?r:t.resolution),l+=t.padding,t.antialias===`off`?u=!1:t.antialias===`inherit`&&(u&&=n),t.clipToViewport||(m=!1),!(t.compatibleRenderers&a.type)){p=!1;break}if(t.blendRequired&&!(a.backBuffer?.useBackBuffer??!0)){f("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),p=!1;break}p=!0,d||=t.blendRequired}}p?(m&&o.fitBounds(0,t.width/r,0,t.height/r),o.scale(c).ceil().scale(1/c).pad((l|0)*i),o.isPositive?(e.antialias=u,e.resolution=c,e.blendRequired=d,e.firstEnabledIndex=h,e.lastEnabledIndex=g):e.skip=!0):e.skip=!0}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){for(let e=this._filterStackIndex-2;e>=0;e--){let t=this._filterStack[e];if(!t.skip)return t}return null}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||=this._filterStack[this._filterStackIndex]=new O,this._filterStackIndex++,e}};k.extension={type:[n.WebGLSystem,n.WebGPUSystem],name:`filter`},r.add(k,x),r.add(E);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./captureCompilerScenePreview-B5O1JhpJ.js";import"./init-DuDPG7T5.js";
|
package/editor/capture.html
CHANGED
|
@@ -3,8 +3,17 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<title>Pixifact Scene Capture</title>
|
|
6
|
-
<script type="module" crossorigin src="/assets/capture-
|
|
7
|
-
<link rel="modulepreload" crossorigin href="/assets/
|
|
6
|
+
<script type="module" crossorigin src="/assets/capture-9Xl6_ybT.js"></script>
|
|
7
|
+
<link rel="modulepreload" crossorigin href="/assets/CanvasPool-BKClwQdf.js">
|
|
8
|
+
<link rel="modulepreload" crossorigin href="/assets/Filter-C-9RPzfk.js">
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/canvasUtils-B0HNDru7.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/Cache-fNcOcM1E.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/GCManagedHash-DP1i0eX7.js">
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/RenderTargetSystem-ROnUCA9S.js">
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/getTextureBatchBindGroup-CIH9f4hr.js">
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/GraphicsContext-DdtyxZk_.js">
|
|
15
|
+
<link rel="modulepreload" crossorigin href="/assets/getTexelRangeRects-CXryyjbK.js">
|
|
16
|
+
<link rel="modulepreload" crossorigin href="/assets/captureCompilerScenePreview-B5O1JhpJ.js">
|
|
8
17
|
</head>
|
|
9
18
|
<body>
|
|
10
19
|
</body>
|
package/editor/index.html
CHANGED
|
@@ -4,8 +4,17 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Pixifact Editor</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/editor-
|
|
8
|
-
<link rel="modulepreload" crossorigin href="/assets/
|
|
7
|
+
<script type="module" crossorigin src="/assets/editor-DsAgQsxk.js"></script>
|
|
8
|
+
<link rel="modulepreload" crossorigin href="/assets/CanvasPool-BKClwQdf.js">
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/Filter-C-9RPzfk.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/canvasUtils-B0HNDru7.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/Cache-fNcOcM1E.js">
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/GCManagedHash-DP1i0eX7.js">
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/RenderTargetSystem-ROnUCA9S.js">
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/getTextureBatchBindGroup-CIH9f4hr.js">
|
|
15
|
+
<link rel="modulepreload" crossorigin href="/assets/GraphicsContext-DdtyxZk_.js">
|
|
16
|
+
<link rel="modulepreload" crossorigin href="/assets/getTexelRangeRects-CXryyjbK.js">
|
|
17
|
+
<link rel="modulepreload" crossorigin href="/assets/captureCompilerScenePreview-B5O1JhpJ.js">
|
|
9
18
|
<link rel="stylesheet" crossorigin href="/assets/editor-DmOIioK0.css">
|
|
10
19
|
</head>
|
|
11
20
|
<body>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixifact-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Pixifact Scene 自动化 CLI。",
|
|
5
|
-
"packageManager": "bun@1.
|
|
5
|
+
"packageManager": "bun@1.4.4",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"pixifact": "src/pixifact-cli.ts"
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"start": "bun src/pixifact-cli.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"pixifact": "^0.
|
|
36
|
-
"playwright": "1.
|
|
37
|
-
"vite": "^8.
|
|
35
|
+
"pixifact": "^0.21.0",
|
|
36
|
+
"playwright": "1.65.0",
|
|
37
|
+
"vite": "^8.3.6"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/automation.ts
CHANGED
|
@@ -35,8 +35,8 @@ interface ToolInput {
|
|
|
35
35
|
node?: unknown;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
type CompilerSceneValidationSuccess = ReturnType<typeof validateCompilerSceneFile
|
|
39
|
-
type CompilerSceneValidationFailure = ReturnType<typeof validateCompilerSceneFile
|
|
38
|
+
type CompilerSceneValidationSuccess = Awaited<ReturnType<typeof validateCompilerSceneFile>> & { ok: true };
|
|
39
|
+
type CompilerSceneValidationFailure = Awaited<ReturnType<typeof validateCompilerSceneFile>> & { ok: false };
|
|
40
40
|
|
|
41
41
|
type DetailedCompilerNode = SceneTemplateNode & {
|
|
42
42
|
locator: string;
|
|
@@ -151,7 +151,7 @@ function collectAssetFiles(root: string, directory: string, assets: Set<string>)
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
function collectCompilerSceneInterfaces(root: string, skippedScene?: string) {
|
|
154
|
+
async function collectCompilerSceneInterfaces(root: string, skippedScene?: string) {
|
|
155
155
|
const sceneSources: {
|
|
156
156
|
scenePath: string;
|
|
157
157
|
template: SceneTemplate;
|
|
@@ -182,7 +182,7 @@ function collectCompilerSceneInterfaces(root: string, skippedScene?: string) {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const builtinSources = readBuiltinSceneScriptSourcesSync();
|
|
185
|
-
const descriptors = extractSceneScriptInterfaces([
|
|
185
|
+
const descriptors = await extractSceneScriptInterfaces([
|
|
186
186
|
...builtinSceneAssetIds().map((scene) => {
|
|
187
187
|
const name = builtinSceneNameFromAssetId(scene);
|
|
188
188
|
return {
|
|
@@ -203,7 +203,7 @@ function collectCompilerSceneInterfaces(root: string, skippedScene?: string) {
|
|
|
203
203
|
|
|
204
204
|
for (const source of sceneSources) {
|
|
205
205
|
try {
|
|
206
|
-
const pair = readCompilerScenePairContract(root, source.scenePath, source.template, descriptors[source.scenePath]);
|
|
206
|
+
const pair = await readCompilerScenePairContract(root, source.scenePath, source.template, descriptors[source.scenePath]);
|
|
207
207
|
if (pair.diagnostics.length > 0 || !pair.sceneInterface) {
|
|
208
208
|
continue;
|
|
209
209
|
}
|
|
@@ -273,12 +273,12 @@ function compilerSceneSourceRootFailure(scenePath: string) {
|
|
|
273
273
|
};
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
function readCompilerScenePairContract(
|
|
276
|
+
async function readCompilerScenePairContract(
|
|
277
277
|
root: string,
|
|
278
278
|
scenePath: string,
|
|
279
279
|
template: SceneTemplate,
|
|
280
280
|
descriptor?: SceneScriptInterface,
|
|
281
|
-
): { diagnostics: SceneValidationDiagnostic[]; sceneInterface?: SceneTemplateInterface } {
|
|
281
|
+
): Promise<{ diagnostics: SceneValidationDiagnostic[]; sceneInterface?: SceneTemplateInterface }> {
|
|
282
282
|
const expectedName = sceneLocalName(scenePath);
|
|
283
283
|
if (template.name !== expectedName) {
|
|
284
284
|
return {
|
|
@@ -296,11 +296,11 @@ function readCompilerScenePairContract(
|
|
|
296
296
|
|
|
297
297
|
let sceneDescriptor = descriptor;
|
|
298
298
|
try {
|
|
299
|
-
sceneDescriptor ??= extractSceneScriptInterfaces([{
|
|
299
|
+
sceneDescriptor ??= (await extractSceneScriptInterfaces([{
|
|
300
300
|
scene: scenePath,
|
|
301
301
|
fileName: absoluteScriptPath,
|
|
302
302
|
source: readTextFile(absoluteScriptPath),
|
|
303
|
-
}])[scenePath];
|
|
303
|
+
}]))[scenePath];
|
|
304
304
|
} catch (error) {
|
|
305
305
|
return {
|
|
306
306
|
diagnostics: [compilerSceneScriptContractDiagnostic(error)],
|
|
@@ -390,7 +390,7 @@ function compilerSceneValidationFailure(scenePath: string, content: string, diag
|
|
|
390
390
|
};
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
function validateCompilerSceneFile(root: string, scenePath: string) {
|
|
393
|
+
async function validateCompilerSceneFile(root: string, scenePath: string) {
|
|
394
394
|
const content = readTextFile(path.join(root, scenePath));
|
|
395
395
|
const sourceRootFailure = compilerSceneSourceRootFailure(scenePath);
|
|
396
396
|
if (sourceRootFailure) {
|
|
@@ -405,7 +405,7 @@ function validateCompilerSceneFile(root: string, scenePath: string) {
|
|
|
405
405
|
content,
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
const pair = readCompilerScenePairContract(root, scenePath, template);
|
|
408
|
+
const pair = await readCompilerScenePairContract(root, scenePath, template);
|
|
409
409
|
if (pair.diagnostics.length > 0 || !pair.sceneInterface) {
|
|
410
410
|
return compilerSceneValidationFailure(scenePath, content, pair.diagnostics);
|
|
411
411
|
}
|
|
@@ -413,7 +413,7 @@ function validateCompilerSceneFile(root: string, scenePath: string) {
|
|
|
413
413
|
scene: scenePath,
|
|
414
414
|
content,
|
|
415
415
|
existingAssets: collectProjectAssets(root),
|
|
416
|
-
sceneInterfaces: collectCompilerSceneInterfaces(root, scenePath),
|
|
416
|
+
sceneInterfaces: await collectCompilerSceneInterfaces(root, scenePath),
|
|
417
417
|
sceneInterface: pair.sceneInterface,
|
|
418
418
|
normalizeSceneReference: normalizeCompilerSceneReference(scenePath),
|
|
419
419
|
});
|
|
@@ -426,8 +426,8 @@ function validateCompilerSceneFile(root: string, scenePath: string) {
|
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
function validateAllCompilerScenes(root: string) {
|
|
430
|
-
const results = collectCompilerScenePaths(root).map((scenePath) => validateCompilerSceneFile(root, scenePath));
|
|
429
|
+
async function validateAllCompilerScenes(root: string) {
|
|
430
|
+
const results = await Promise.all(collectCompilerScenePaths(root).map((scenePath) => validateCompilerSceneFile(root, scenePath)));
|
|
431
431
|
const failures = results.filter((result): result is CompilerSceneValidationFailure => !result.ok);
|
|
432
432
|
const scenes = results
|
|
433
433
|
.filter((result): result is CompilerSceneValidationSuccess => result.ok)
|
|
@@ -599,11 +599,11 @@ export function createPixifactAutomation() {
|
|
|
599
599
|
};
|
|
600
600
|
},
|
|
601
601
|
|
|
602
|
-
inspectCompilerScene(input: unknown) {
|
|
602
|
+
async inspectCompilerScene(input: unknown) {
|
|
603
603
|
const args = assertRecord(input, 'input') as ToolInput;
|
|
604
604
|
const loaded = loadCompilerScene(args.projectRoot, args.scenePath);
|
|
605
605
|
const template = parseSceneTemplate(loaded.content);
|
|
606
|
-
const sceneInterface = collectCompilerSceneInterfaces(loaded.root)[loaded.scenePath];
|
|
606
|
+
const sceneInterface = (await collectCompilerSceneInterfaces(loaded.root))[loaded.scenePath];
|
|
607
607
|
if (!sceneInterface) {
|
|
608
608
|
throw new Error(`Scene "${loaded.scenePath}" requires a readable paired @scene contract.`);
|
|
609
609
|
}
|
package/src/editorServer.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import
|
|
4
|
+
import childProcess from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
5
6
|
import {
|
|
6
7
|
normalizeSceneAssetId,
|
|
7
8
|
pairedSceneScriptPath,
|
|
@@ -300,7 +301,7 @@ export function createEditorProjectService(options: EditorProjectServiceOptions)
|
|
|
300
301
|
if (url.pathname === '/api/scene-bindings' && request.method === 'GET') {
|
|
301
302
|
files ??= listProjectFiles(projectRoot);
|
|
302
303
|
bindings ??= readProjectSceneBindings(projectRoot, files);
|
|
303
|
-
return jsonResponse(bindings);
|
|
304
|
+
return jsonResponse(await bindings);
|
|
304
305
|
}
|
|
305
306
|
if (url.pathname === '/api/scene' && request.method === 'PUT') {
|
|
306
307
|
const scenePath = requestPath(url);
|
|
@@ -330,6 +331,29 @@ export function createEditorProjectService(options: EditorProjectServiceOptions)
|
|
|
330
331
|
},
|
|
331
332
|
});
|
|
332
333
|
}
|
|
334
|
+
if (url.pathname === '/api/open-file' && request.method === 'POST') {
|
|
335
|
+
if (request.headers.get('origin') !== url.origin) {
|
|
336
|
+
throw new EditorRequestError(403, '资源打开请求必须来自当前 Editor。');
|
|
337
|
+
}
|
|
338
|
+
let filePath: string;
|
|
339
|
+
try {
|
|
340
|
+
filePath = resolveInsideRoot(projectRoot, requestPath(url));
|
|
341
|
+
if (!fs.statSync(filePath).isFile()) {
|
|
342
|
+
throw new EditorRequestError(400, '只能使用系统默认程序打开项目内的文件。');
|
|
343
|
+
}
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
346
|
+
throw new EditorRequestError(404, '资源文件不存在,请刷新资产列表。');
|
|
347
|
+
}
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
await openSystemFile(filePath);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
throw new EditorRequestError(500, `无法使用系统默认程序打开文件:${error instanceof Error ? error.message : String(error)}`);
|
|
354
|
+
}
|
|
355
|
+
return jsonResponse({ ok: true });
|
|
356
|
+
}
|
|
333
357
|
if (url.pathname.startsWith('/api/')) {
|
|
334
358
|
return jsonResponse({ ok: false, error: 'Editor API route was not found.' }, 404);
|
|
335
359
|
}
|
|
@@ -349,13 +373,23 @@ function defaultEditorStaticRoot() {
|
|
|
349
373
|
return path.resolve(import.meta.dir, '..', 'editor');
|
|
350
374
|
}
|
|
351
375
|
|
|
376
|
+
async function openSystemFile(filePath: string) {
|
|
377
|
+
const command = process.platform === 'win32'
|
|
378
|
+
? [
|
|
379
|
+
'powershell.exe', '-NoProfile', '-NonInteractive', '-Command',
|
|
380
|
+
`Start-Process -FilePath ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${Buffer.from(filePath).toString('base64')}'))) -ErrorAction Stop`,
|
|
381
|
+
]
|
|
382
|
+
: [process.platform === 'darwin' ? 'open' : 'xdg-open', filePath];
|
|
383
|
+
await promisify(childProcess.execFile)(command[0], command.slice(1), { windowsHide: true });
|
|
384
|
+
}
|
|
385
|
+
|
|
352
386
|
function openBrowser(url: string) {
|
|
353
387
|
const command = process.platform === 'darwin'
|
|
354
388
|
? ['open', url]
|
|
355
389
|
: process.platform === 'win32'
|
|
356
390
|
? ['cmd', '/c', 'start', '', url]
|
|
357
391
|
: ['xdg-open', url];
|
|
358
|
-
spawn(command[0], command.slice(1), { detached: true, stdio: 'ignore' }).unref();
|
|
392
|
+
childProcess.spawn(command[0], command.slice(1), { detached: true, stdio: 'ignore' }).unref();
|
|
359
393
|
}
|
|
360
394
|
|
|
361
395
|
export function watchEditorProject(projectRoot: string, onProjectFileChanged: (path: string) => void) {
|
package/src/pixifact-cli.ts
CHANGED
|
@@ -536,7 +536,7 @@ async function executeFileCommand(
|
|
|
536
536
|
assertAllowedFlags(flags, ['scene', 'output', 'project-root'], 'scene screenshot');
|
|
537
537
|
const scenePath = requireFlag(flags, 'scene');
|
|
538
538
|
const output = path.resolve(requireFlag(flags, 'output'));
|
|
539
|
-
const validation = automation.validateCompilerScene({ projectRoot, scenePath });
|
|
539
|
+
const validation = await automation.validateCompilerScene({ projectRoot, scenePath });
|
|
540
540
|
if (!validation.ok) return validation;
|
|
541
541
|
const screenshot = await captureScene({ projectRoot, scenePath: validation.scene });
|
|
542
542
|
fs.mkdirSync(path.dirname(output), { recursive: true });
|
package/src/viteTarget.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createServer,
|
|
6
6
|
resolveConfig,
|
|
7
7
|
type ResolvedServerUrls,
|
|
8
|
-
type
|
|
8
|
+
type Rolldown,
|
|
9
9
|
} from 'vite';
|
|
10
10
|
import {
|
|
11
11
|
parsePixifactProjectConfig,
|
|
@@ -155,7 +155,7 @@ export async function devPixifactTarget(
|
|
|
155
155
|
plugins: [pixifactBuildReporter(validation.platform, (report) => {
|
|
156
156
|
completedReport = report;
|
|
157
157
|
})],
|
|
158
|
-
}) as
|
|
158
|
+
}) as Rolldown.RolldownWatcher;
|
|
159
159
|
watcher.on('event', (event) => {
|
|
160
160
|
if (event.code === 'END' && completedReport) {
|
|
161
161
|
const report = completedReport;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,b as t,f as n,g as r,m as i,p as a,v as o}from"./captureCompilerScenePreview-4K1ehGWd.js";import"./init-B6Wk-3NE.js";t.add(e),t.mixin(o,r),t.add(i),t.add(a),t.mixin(o,n);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as e,E as t,S as n,h as r,i,n as a,r as o,t as s,w as c}from"./captureCompilerScenePreview-4K1ehGWd.js";window.capturePixifactScene=async l=>{let[u,d]=await Promise.all([c(),t(l)]),f=new a,p,m=new r,h=!1;try{return p=await o({cache:f,document:{template:e(d.source),sceneInterfaces:{}},projectTree:n(u),scenePath:l}),await m.init({width:p.width,height:p.height,backgroundAlpha:0,antialias:!0,autoStart:!1,resolution:1}),h=!0,m.stage.addChild(p.root),{scenePath:d.path,revision:d.version,width:p.width,height:p.height,dataUrl:await s(m,p)}}finally{h&&(m.stage.removeChild(p.root),m.destroy({removeView:!0},{children:!1})),i(p),await f.clear()}};
|