@planara/core 1.4.6 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/editor-renderer.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +16 -18
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-renderer.d.ts","sourceRoot":"","sources":["../../src/core/editor-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"editor-renderer.d.ts","sourceRoot":"","sources":["../../src/core/editor-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAuC,KAAK,IAAI,EAAW,MAAM,KAAK,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,8CAA8C;IAC9C,OAAO,CAAC,KAAK,CAAS;IAEtB,kDAAkD;IAClD,OAAO,CAAC,OAAO,CAAW;IAE1B,0DAA0D;IAC1D,OAAO,CAAC,KAAK,CAAQ;IAErB,4DAA4D;IAC5D,OAAO,CAAC,qBAAqB,CAAW;IAExC;;;;OAIG;gBACgB,MAAM,EAAE,iBAAiB;IAyB5C;;OAEG;IACH,SAAS,CAAC,MAAM;IAKhB;;;;OAIG;IACa,SAAS,CAAC,MAAM,EAAE,MAAM;IA2BxC;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI;IAIrC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;OAEG;IACH,OAAO,CAAC,eAAe,CAerB;IAEF,iBAAiB;IACV,OAAO;CAaf"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
gl_FragColor.rgb = color + lighting * 0.1;
|
|
27
27
|
gl_FragColor.a = 1.0;
|
|
28
28
|
}
|
|
29
|
-
`;return new r.Program(t,{vertex:e,fragment:s,cullFace:!1,uniforms:{uHit:{value:0}}})}class h{gl;scene;camera;canvas;program;meshes;constructor(e){this.canvas=e,this.gl=new r.Renderer({canvas:e,dpr:2}),this.gl.setSize(e.clientWidth,e.clientHeight),this.gl.gl.clearColor(1
|
|
29
|
+
`;return new r.Program(t,{vertex:e,fragment:s,cullFace:!1,uniforms:{uHit:{value:0}}})}class h{gl;scene;camera;canvas;program;meshes;constructor(e){this.canvas=e,this.gl=new r.Renderer({canvas:e,dpr:2}),this.gl.setSize(e.clientWidth,e.clientHeight),this.gl.gl.clearColor(.1,.1,.1,1),this.scene=new r.Transform,this.camera=new r.Camera(this.gl.gl,{fov:45}),this.camera.position.set(1,1,7),this.camera.lookAt([0,0,0]),this.program=d(this.gl.gl),this.meshes=[]}resize(){this.gl.setSize(this.canvas.width,this.canvas.height),this.camera.perspective({aspect:this.canvas.width/this.canvas.height})}render(){this.gl.render({scene:this.scene,camera:this.camera})}update(){}loop(){this.update(),this.render(),requestAnimationFrame(this.loop.bind(this))}addFigure(e){const s=new r.Geometry(this.gl.gl,{position:{size:3,data:new Float32Array(e.position)},normal:{size:3,data:new Float32Array(e.normal??[])},uv:{size:2,data:new Float32Array(e.uv??[])}}),i=new r.Mesh(this.gl.gl,{geometry:s,program:this.program});return i.setParent(this.scene),this.meshes.push(i),i}destroy(){this.meshes&&(this.meshes.length=0,this.meshes=[]),this.scene=null,this.camera=null,this.program=null,this.gl=null,this.canvas=null}}class v extends h{orbit;raycast;mouse;isEventListenersAdded;constructor(e){super(e);const s=new r.GridHelper(this.gl.gl,{size:10,divisions:10});s.position.y=-.001,s.setParent(this.scene),new r.AxesHelper(this.gl.gl,{size:6,symmetric:!0}).setParent(this.scene),this.orbit=new r.Orbit(this.camera,{element:this.canvas}),this.raycast=new r.Raycast,this.mouse=new r.Vec2,this.isEventListenersAdded=!1}update(){this.orbit?.update()}addFigure(e){const s=super.addFigure(e);if(s.geometry){const i=s.geometry.constructor.name;s.geometry.raycast=i.includes("Sphere")?"sphere":"box"}return s.isHit=!1,s.onBeforeRender(({mesh:i})=>{this.updateHitUniform(i)}),this.isEventListenersAdded||this.initMouseListeners(),s}updateHitUniform(e){this.program.uniforms.uHit.value=e.isHit?1:0}initMouseListeners(){document.addEventListener("mousemove",this.handleMouseMove,!1),this.isEventListenersAdded=!0}handleMouseMove=e=>{this.mouse.set(2*(e.x/this.gl.width)-1,2*(1-e.y/this.gl.height)-1),this.raycast.castMouse(this.camera,this.mouse),this.meshes.forEach(i=>i.isHit=!1),this.raycast.intersectBounds(this.meshes).forEach(i=>i.isHit=!0)};destroy(){this.isEventListenersAdded&&(window.removeEventListener("mousemove",this.handleMouseMove,!1),this.isEventListenersAdded=!1),this.orbit=null,this.raycast=null,this.mouse=null,super.destroy()}}class g extends h{orbit;constructor(e){super(e),this.orbit=new r.Orbit(this.camera,{element:this.canvas,target:new r.Vec3(0,0,0),minPolarAngle:Math.PI/2,maxPolarAngle:Math.PI/2,enableRotate:!0,enableZoom:!1,enablePan:!1})}update(){this.orbit?.update()}}class f{type;position;normal;uv;material;constructor(e){this.type=e.type,this.position=e.position,this.normal=e.normal??[],this.uv=e.uv??[],this.material=e.material}}var p=(t=>(t[t.Cube=0]="Cube",t[t.Sphere=1]="Sphere",t[t.Plane=2]="Plane",t[t.Cylinder=3]="Cylinder",t[t.Custom=4]="Custom",t))(p||{});class y{positions=[];normals=[];uvs=[];tmpPositions=[];tmpNormals=[];tmpUVs=[];load(e){const s=e.split(`
|
|
30
30
|
`);for(const a of s){if(!a.trim()||a.startsWith("#"))continue;const n=a.trim().split(/\s+/);switch(n[0]){case"v":this.tmpPositions.push(n.slice(1).map(Number));break;case"vn":this.tmpNormals.push(n.slice(1).map(Number));break;case"vt":this.tmpUVs.push(n.slice(1).map(Number));break;case"f":this.processFaceLine(n);break}}const i={type:p.Custom,position:this.positions,...this.normals.length>0&&{normal:this.normals},...this.uvs.length>0&&{uv:this.uvs}};return new f(i)}processFaceLine(e){for(let s=1;s<e.length;s++){const i=e[s];if(!i)continue;const[a,n,l]=i.split("/"),m=a?parseInt(a,10):void 0,c=n?parseInt(n,10):void 0,u=l?parseInt(l,10):void 0;if(m!==void 0){const o=this.tmpPositions[m-1];o&&this.positions.push(...o)}if(c!==void 0){const o=this.tmpUVs[c-1];o&&this.uvs.push(...o)}if(u!==void 0){const o=this.tmpNormals[u-1];o&&this.normals.push(...o)}}}}exports.EditorRenderer=v;exports.ObjLoader=y;exports.PreviewRenderer=g;exports.Renderer=h;exports.createProgram=d;
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Program as p, Renderer as v, Transform as g, Camera as f, Geometry as y, Mesh as
|
|
2
|
-
function
|
|
1
|
+
import { Program as p, Renderer as v, Transform as g, Camera as f, Geometry as y, Mesh as b, GridHelper as w, AxesHelper as x, Orbit as c, Raycast as M, Vec2 as P, Vec3 as A } from "ogl";
|
|
2
|
+
function H(t) {
|
|
3
3
|
const e = (
|
|
4
4
|
/* glsl */
|
|
5
5
|
`
|
|
@@ -62,7 +62,7 @@ class u {
|
|
|
62
62
|
* @param canvas - HTMLCanvasElement для рендеринга
|
|
63
63
|
*/
|
|
64
64
|
constructor(e) {
|
|
65
|
-
this.canvas = e, this.gl = new v({ canvas: e, dpr: 2 }), this.gl.setSize(e.clientWidth, e.clientHeight), this.gl.gl.clearColor(1, 1, 1, 1), this.scene = new g(), this.camera = new f(this.gl.gl, { fov: 45 }), this.camera.position.set(1, 1, 7), this.camera.lookAt([0, 0, 0]), this.program =
|
|
65
|
+
this.canvas = e, this.gl = new v({ canvas: e, dpr: 2 }), this.gl.setSize(e.clientWidth, e.clientHeight), this.gl.gl.clearColor(0.1, 0.1, 0.1, 1), this.scene = new g(), this.camera = new f(this.gl.gl, { fov: 45 }), this.camera.position.set(1, 1, 7), this.camera.lookAt([0, 0, 0]), this.program = H(this.gl.gl), this.meshes = [];
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Обновляет размер рендерера и камеры при изменении размеров canvas.
|
|
@@ -96,7 +96,7 @@ class u {
|
|
|
96
96
|
position: { size: 3, data: new Float32Array(e.position) },
|
|
97
97
|
normal: { size: 3, data: new Float32Array(e.normal ?? []) },
|
|
98
98
|
uv: { size: 2, data: new Float32Array(e.uv ?? []) }
|
|
99
|
-
}), i = new
|
|
99
|
+
}), i = new b(this.gl.gl, {
|
|
100
100
|
geometry: s,
|
|
101
101
|
program: this.program
|
|
102
102
|
});
|
|
@@ -107,7 +107,7 @@ class u {
|
|
|
107
107
|
this.meshes && (this.meshes.length = 0, this.meshes = []), this.scene = null, this.camera = null, this.program = null, this.gl = null, this.canvas = null;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class z extends u {
|
|
111
111
|
/** Orbit-контроллер для управления камерой */
|
|
112
112
|
orbit;
|
|
113
113
|
/** Raycast для подсветки моделей при наведении */
|
|
@@ -123,7 +123,7 @@ class F extends u {
|
|
|
123
123
|
*/
|
|
124
124
|
constructor(e) {
|
|
125
125
|
super(e);
|
|
126
|
-
const s = new
|
|
126
|
+
const s = new w(this.gl.gl, { size: 10, divisions: 10 });
|
|
127
127
|
s.position.y = -1e-3, s.setParent(this.scene), new x(this.gl.gl, { size: 6, symmetric: !0 }).setParent(this.scene), this.orbit = new c(this.camera, { element: this.canvas }), this.raycast = new M(), this.mouse = new P(), this.isEventListenersAdded = !1;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
@@ -145,7 +145,7 @@ class F extends u {
|
|
|
145
145
|
}
|
|
146
146
|
return s.isHit = !1, s.onBeforeRender(({ mesh: i }) => {
|
|
147
147
|
this.updateHitUniform(i);
|
|
148
|
-
}), this.isEventListenersAdded
|
|
148
|
+
}), this.isEventListenersAdded || this.initMouseListeners(), s;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* Обновление uniform uHit для конкретной 3D-модели
|
|
@@ -157,9 +157,7 @@ class F extends u {
|
|
|
157
157
|
* Инициализация обработчиков мыши для raycast
|
|
158
158
|
*/
|
|
159
159
|
initMouseListeners() {
|
|
160
|
-
|
|
161
|
-
document.addEventListener("mousemove", this.handleMouseMove, !1);
|
|
162
|
-
});
|
|
160
|
+
document.addEventListener("mousemove", this.handleMouseMove, !1), this.isEventListenersAdded = !0;
|
|
163
161
|
}
|
|
164
162
|
/**
|
|
165
163
|
* Обработчик движения мыши
|
|
@@ -172,7 +170,7 @@ class F extends u {
|
|
|
172
170
|
this.isEventListenersAdded && (window.removeEventListener("mousemove", this.handleMouseMove, !1), this.isEventListenersAdded = !1), this.orbit = null, this.raycast = null, this.mouse = null, super.destroy();
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
|
-
class
|
|
173
|
+
class C extends u {
|
|
176
174
|
/** Orbit-контроллер для управления камерой */
|
|
177
175
|
orbit;
|
|
178
176
|
/**
|
|
@@ -197,7 +195,7 @@ class z extends u {
|
|
|
197
195
|
this.orbit?.update();
|
|
198
196
|
}
|
|
199
197
|
}
|
|
200
|
-
class
|
|
198
|
+
class L {
|
|
201
199
|
/** Тип фигуры */
|
|
202
200
|
type;
|
|
203
201
|
/** Позиции вершин */
|
|
@@ -217,7 +215,7 @@ class H {
|
|
|
217
215
|
}
|
|
218
216
|
}
|
|
219
217
|
var d = /* @__PURE__ */ ((t) => (t[t.Cube = 0] = "Cube", t[t.Sphere = 1] = "Sphere", t[t.Plane = 2] = "Plane", t[t.Cylinder = 3] = "Cylinder", t[t.Custom = 4] = "Custom", t))(d || {});
|
|
220
|
-
class
|
|
218
|
+
class E {
|
|
221
219
|
/** Позиции вершин */
|
|
222
220
|
positions = [];
|
|
223
221
|
/** Нормали вершин */
|
|
@@ -259,7 +257,7 @@ class C {
|
|
|
259
257
|
...this.normals.length > 0 && { normal: this.normals },
|
|
260
258
|
...this.uvs.length > 0 && { uv: this.uvs }
|
|
261
259
|
};
|
|
262
|
-
return new
|
|
260
|
+
return new L(i);
|
|
263
261
|
}
|
|
264
262
|
/**
|
|
265
263
|
* Обрабатывает строку face (f) и разворачивает индексы в массивы для рендеринга
|
|
@@ -285,9 +283,9 @@ class C {
|
|
|
285
283
|
}
|
|
286
284
|
}
|
|
287
285
|
export {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
286
|
+
z as EditorRenderer,
|
|
287
|
+
E as ObjLoader,
|
|
288
|
+
C as PreviewRenderer,
|
|
291
289
|
u as Renderer,
|
|
292
|
-
|
|
290
|
+
H as createProgram
|
|
293
291
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("ogl")):typeof define=="function"&&define.amd?define(["exports","ogl"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.PlanaraCore={},n.OGL))})(this,(function(n,i){"use strict";function m(
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("ogl")):typeof define=="function"&&define.amd?define(["exports","ogl"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.PlanaraCore={},n.OGL))})(this,(function(n,i){"use strict";function m(t){const e=`
|
|
2
2
|
attribute vec3 position;
|
|
3
3
|
attribute vec3 normal;
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
vNormal = normalize(normalMatrix * normal);
|
|
13
13
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
14
14
|
}
|
|
15
|
-
`,
|
|
15
|
+
`,s=`
|
|
16
16
|
precision highp float;
|
|
17
17
|
|
|
18
18
|
uniform float uHit;
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
gl_FragColor.rgb = color + lighting * 0.1;
|
|
27
27
|
gl_FragColor.a = 1.0;
|
|
28
28
|
}
|
|
29
|
-
`;return new i.Program(
|
|
30
|
-
`);for(const h of
|
|
29
|
+
`;return new i.Program(t,{vertex:e,fragment:s,cullFace:!1,uniforms:{uHit:{value:0}}})}class l{gl;scene;camera;canvas;program;meshes;constructor(e){this.canvas=e,this.gl=new i.Renderer({canvas:e,dpr:2}),this.gl.setSize(e.clientWidth,e.clientHeight),this.gl.gl.clearColor(.1,.1,.1,1),this.scene=new i.Transform,this.camera=new i.Camera(this.gl.gl,{fov:45}),this.camera.position.set(1,1,7),this.camera.lookAt([0,0,0]),this.program=m(this.gl.gl),this.meshes=[]}resize(){this.gl.setSize(this.canvas.width,this.canvas.height),this.camera.perspective({aspect:this.canvas.width/this.canvas.height})}render(){this.gl.render({scene:this.scene,camera:this.camera})}update(){}loop(){this.update(),this.render(),requestAnimationFrame(this.loop.bind(this))}addFigure(e){const s=new i.Geometry(this.gl.gl,{position:{size:3,data:new Float32Array(e.position)},normal:{size:3,data:new Float32Array(e.normal??[])},uv:{size:2,data:new Float32Array(e.uv??[])}}),r=new i.Mesh(this.gl.gl,{geometry:s,program:this.program});return r.setParent(this.scene),this.meshes.push(r),r}destroy(){this.meshes&&(this.meshes.length=0,this.meshes=[]),this.scene=null,this.camera=null,this.program=null,this.gl=null,this.canvas=null}}class f extends l{orbit;raycast;mouse;isEventListenersAdded;constructor(e){super(e);const s=new i.GridHelper(this.gl.gl,{size:10,divisions:10});s.position.y=-.001,s.setParent(this.scene),new i.AxesHelper(this.gl.gl,{size:6,symmetric:!0}).setParent(this.scene),this.orbit=new i.Orbit(this.camera,{element:this.canvas}),this.raycast=new i.Raycast,this.mouse=new i.Vec2,this.isEventListenersAdded=!1}update(){this.orbit?.update()}addFigure(e){const s=super.addFigure(e);if(s.geometry){const r=s.geometry.constructor.name;s.geometry.raycast=r.includes("Sphere")?"sphere":"box"}return s.isHit=!1,s.onBeforeRender(({mesh:r})=>{this.updateHitUniform(r)}),this.isEventListenersAdded||this.initMouseListeners(),s}updateHitUniform(e){this.program.uniforms.uHit.value=e.isHit?1:0}initMouseListeners(){document.addEventListener("mousemove",this.handleMouseMove,!1),this.isEventListenersAdded=!0}handleMouseMove=e=>{this.mouse.set(2*(e.x/this.gl.width)-1,2*(1-e.y/this.gl.height)-1),this.raycast.castMouse(this.camera,this.mouse),this.meshes.forEach(r=>r.isHit=!1),this.raycast.intersectBounds(this.meshes).forEach(r=>r.isHit=!0)};destroy(){this.isEventListenersAdded&&(window.removeEventListener("mousemove",this.handleMouseMove,!1),this.isEventListenersAdded=!1),this.orbit=null,this.raycast=null,this.mouse=null,super.destroy()}}class g extends l{orbit;constructor(e){super(e),this.orbit=new i.Orbit(this.camera,{element:this.canvas,target:new i.Vec3(0,0,0),minPolarAngle:Math.PI/2,maxPolarAngle:Math.PI/2,enableRotate:!0,enableZoom:!1,enablePan:!1})}update(){this.orbit?.update()}}class y{type;position;normal;uv;material;constructor(e){this.type=e.type,this.position=e.position,this.normal=e.normal??[],this.uv=e.uv??[],this.material=e.material}}var c=(t=>(t[t.Cube=0]="Cube",t[t.Sphere=1]="Sphere",t[t.Plane=2]="Plane",t[t.Cylinder=3]="Cylinder",t[t.Custom=4]="Custom",t))(c||{});class b{positions=[];normals=[];uvs=[];tmpPositions=[];tmpNormals=[];tmpUVs=[];load(e){const s=e.split(`
|
|
30
|
+
`);for(const h of s){if(!h.trim()||h.startsWith("#"))continue;const a=h.trim().split(/\s+/);switch(a[0]){case"v":this.tmpPositions.push(a.slice(1).map(Number));break;case"vn":this.tmpNormals.push(a.slice(1).map(Number));break;case"vt":this.tmpUVs.push(a.slice(1).map(Number));break;case"f":this.processFaceLine(a);break}}const r={type:c.Custom,position:this.positions,...this.normals.length>0&&{normal:this.normals},...this.uvs.length>0&&{uv:this.uvs}};return new y(r)}processFaceLine(e){for(let s=1;s<e.length;s++){const r=e[s];if(!r)continue;const[h,a,u]=r.split("/"),d=h?parseInt(h,10):void 0,p=a?parseInt(a,10):void 0,v=u?parseInt(u,10):void 0;if(d!==void 0){const o=this.tmpPositions[d-1];o&&this.positions.push(...o)}if(p!==void 0){const o=this.tmpUVs[p-1];o&&this.uvs.push(...o)}if(v!==void 0){const o=this.tmpNormals[v-1];o&&this.normals.push(...o)}}}}n.EditorRenderer=f,n.ObjLoader=b,n.PreviewRenderer=g,n.Renderer=l,n.createProgram=m,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|