Skip to content

Commit ea8f6df

Browse files
committed
Update engine, new js editor version
1 parent ed4315e commit ea8f6df

5 files changed

Lines changed: 149 additions & 43 deletions

File tree

libraries/wgpuEngine

Submodule wgpuEngine updated 46 files

www/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (ENVIRONMENT_IS_NODE) {
3131

3232
// --pre-jses are emitted after the Module integration code, so that they can
3333
// refer to Module (if they choose; they can also define Module)
34-
// include: C:\Users\alexr\AppData\Local\Temp\tmpnmfrgbwu.js
34+
// include: C:\Users\alexr\AppData\Local\Temp\tmpyqskrwfr.js
3535

3636
Module['expectedDataFileDownloads'] ??= 0;
3737
Module['expectedDataFileDownloads']++;
@@ -221,7 +221,7 @@ Module['FS_createPath']("/data/textures", "environments", true, true);
221221

222222
})();
223223

224-
// end include: C:\Users\alexr\AppData\Local\Temp\tmpnmfrgbwu.js
224+
// end include: C:\Users\alexr\AppData\Local\Temp\tmpyqskrwfr.js
225225

226226

227227
var arguments_ = [];
@@ -11940,15 +11940,23 @@ var dynCall_vifiii = Module['dynCall_vifiii'] = (a0, a1, a2, a3, a4, a5) => (dyn
1194011940
var dynCall_viifiii = Module['dynCall_viifiii'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_viifiii = Module['dynCall_viifiii'] = wasmExports['dynCall_viifiii'])(a0, a1, a2, a3, a4, a5, a6);
1194111941
var dynCall_viffii = Module['dynCall_viffii'] = (a0, a1, a2, a3, a4, a5) => (dynCall_viffii = Module['dynCall_viffii'] = wasmExports['dynCall_viffii'])(a0, a1, a2, a3, a4, a5);
1194211942
var dynCall_viiffii = Module['dynCall_viiffii'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_viiffii = Module['dynCall_viiffii'] = wasmExports['dynCall_viiffii'])(a0, a1, a2, a3, a4, a5, a6);
11943+
var dynCall_vifffiiiii = Module['dynCall_vifffiiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) => (dynCall_vifffiiiii = Module['dynCall_vifffiiiii'] = wasmExports['dynCall_vifffiiiii'])(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
11944+
var dynCall_viifffiiiii = Module['dynCall_viifffiiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => (dynCall_viifffiiiii = Module['dynCall_viifffiiiii'] = wasmExports['dynCall_viifffiiiii'])(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
1194311945
var dynCall_vifi = Module['dynCall_vifi'] = (a0, a1, a2, a3) => (dynCall_vifi = Module['dynCall_vifi'] = wasmExports['dynCall_vifi'])(a0, a1, a2, a3);
1194411946
var dynCall_viifi = Module['dynCall_viifi'] = (a0, a1, a2, a3, a4) => (dynCall_viifi = Module['dynCall_viifi'] = wasmExports['dynCall_viifi'])(a0, a1, a2, a3, a4);
11947+
var dynCall_iiffiiii = Module['dynCall_iiffiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7) => (dynCall_iiffiiii = Module['dynCall_iiffiiii'] = wasmExports['dynCall_iiffiiii'])(a0, a1, a2, a3, a4, a5, a6, a7);
11948+
var dynCall_iifffi = Module['dynCall_iifffi'] = (a0, a1, a2, a3, a4, a5) => (dynCall_iifffi = Module['dynCall_iifffi'] = wasmExports['dynCall_iifffi'])(a0, a1, a2, a3, a4, a5);
11949+
var dynCall_iifiii = Module['dynCall_iifiii'] = (a0, a1, a2, a3, a4, a5) => (dynCall_iifiii = Module['dynCall_iifiii'] = wasmExports['dynCall_iifiii'])(a0, a1, a2, a3, a4, a5);
11950+
var dynCall_iiffiii = Module['dynCall_iiffiii'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_iiffiii = Module['dynCall_iiffiii'] = wasmExports['dynCall_iiffiii'])(a0, a1, a2, a3, a4, a5, a6);
11951+
var dynCall_iifffiiiii = Module['dynCall_iifffiiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) => (dynCall_iifffiiiii = Module['dynCall_iifffiiiii'] = wasmExports['dynCall_iifffiiiii'])(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
11952+
var dynCall_iiiiiiiii = Module['dynCall_iiiiiiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7, a8) => (dynCall_iiiiiiiii = Module['dynCall_iiiiiiiii'] = wasmExports['dynCall_iiiiiiiii'])(a0, a1, a2, a3, a4, a5, a6, a7, a8);
11953+
var dynCall_iiffii = Module['dynCall_iiffii'] = (a0, a1, a2, a3, a4, a5) => (dynCall_iiffii = Module['dynCall_iiffii'] = wasmExports['dynCall_iiffii'])(a0, a1, a2, a3, a4, a5);
1194511954
var dynCall_viifff = Module['dynCall_viifff'] = (a0, a1, a2, a3, a4, a5) => (dynCall_viifff = Module['dynCall_viifff'] = wasmExports['dynCall_viifff'])(a0, a1, a2, a3, a4, a5);
1194611955
var dynCall_viiifff = Module['dynCall_viiifff'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_viiifff = Module['dynCall_viiifff'] = wasmExports['dynCall_viiifff'])(a0, a1, a2, a3, a4, a5, a6);
1194711956
var dynCall_viji = Module['dynCall_viji'] = (a0, a1, a2, a3) => (dynCall_viji = Module['dynCall_viji'] = wasmExports['dynCall_viji'])(a0, a1, a2, a3);
1194811957
var dynCall_jiji = Module['dynCall_jiji'] = (a0, a1, a2, a3) => (dynCall_jiji = Module['dynCall_jiji'] = wasmExports['dynCall_jiji'])(a0, a1, a2, a3);
1194911958
var dynCall_iidiiii = Module['dynCall_iidiiii'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_iidiiii = Module['dynCall_iidiiii'] = wasmExports['dynCall_iidiiii'])(a0, a1, a2, a3, a4, a5, a6);
1195011959
var dynCall_viijii = Module['dynCall_viijii'] = (a0, a1, a2, a3, a4, a5) => (dynCall_viijii = Module['dynCall_viijii'] = wasmExports['dynCall_viijii'])(a0, a1, a2, a3, a4, a5);
11951-
var dynCall_iiiiiiiii = Module['dynCall_iiiiiiiii'] = (a0, a1, a2, a3, a4, a5, a6, a7, a8) => (dynCall_iiiiiiiii = Module['dynCall_iiiiiiiii'] = wasmExports['dynCall_iiiiiiiii'])(a0, a1, a2, a3, a4, a5, a6, a7, a8);
1195211960
var dynCall_iiiiij = Module['dynCall_iiiiij'] = (a0, a1, a2, a3, a4, a5) => (dynCall_iiiiij = Module['dynCall_iiiiij'] = wasmExports['dynCall_iiiiij'])(a0, a1, a2, a3, a4, a5);
1195311961
var dynCall_iiiiid = Module['dynCall_iiiiid'] = (a0, a1, a2, a3, a4, a5) => (dynCall_iiiiid = Module['dynCall_iiiiid'] = wasmExports['dynCall_iiiiid'])(a0, a1, a2, a3, a4, a5);
1195411962
var dynCall_iiiiijj = Module['dynCall_iiiiijj'] = (a0, a1, a2, a3, a4, a5, a6) => (dynCall_iiiiijj = Module['dynCall_iiiiijj'] = wasmExports['dynCall_iiiiijj'])(a0, a1, a2, a3, a4, a5, a6);

www/index.wasm

118 KB
Binary file not shown.

www/script.js

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@ this.onRender = function() {
122122
gridMaterial.type = WGE.MaterialType.MATERIAL_UNLIT;
123123
gridMaterial.setShader( WGE.RendererStorage.getShaderFromName( "mesh_grid", gridMaterial ) );
124124

125-
const surface = WGE.RendererStorage.getSurface( "quad" );
126125
const grid = new WGE.MeshInstance3D();
127126
grid.name = "Grid";
128-
grid.addSurface( surface );
127+
grid.mesh = new WGE.QuadMesh();
129128
grid.setPosition( new WGE.vec3(0.0) );
130129
grid.rotate( WGE.radians( 90.0 ), new WGE.vec3(1.0, 0.0, 0.0) );
131130
grid.scale( new WGE.vec3(10.0) );
132131
grid.setFrustumCullingEnabled( false );
133-
grid.setSurfaceMaterialOverride( surface, gridMaterial );
132+
grid.setSurfaceMaterialOverride( grid.getSurface( 0 ), gridMaterial );
134133
this.grid = grid;
135134
}
136135

@@ -157,12 +156,11 @@ this.onRender = function() {
157156
this.shaderData[ shader.path ] = shaderContent;
158157
});
159158

160-
const surface = WGE.RendererStorage.getSurface("box");
161159
const box = new WGE.MeshInstance3D();
162160
box.name = "Box";
163-
box.addSurface( surface );
161+
box.mesh = new WGE.BoxMesh();
164162
box.setPosition( new WGE.vec3(1.0, 0, -5.0) );
165-
box.setSurfaceMaterialOverride( surface, boxMaterial );
163+
box.setSurfaceMaterialOverride( box.getSurface( 0 ), boxMaterial );
166164
scene.addNode( box, -1 );
167165
window.box = box;
168166
}
@@ -241,6 +239,8 @@ this.onRender = function() {
241239
{ name: "Mesh", submenu: [
242240
{ name: "Box", callback: this.onAddMesh.bind( this ) },
243241
{ name: "Sphere", callback: this.onAddMesh.bind( this ) },
242+
{ name: "Capsule", callback: this.onAddMesh.bind( this ) },
243+
{ name: "Cylinder", callback: this.onAddMesh.bind( this ) },
244244
{ name: "Torus", callback: this.onAddMesh.bind( this ) }
245245
] },
246246
{ name: "Light", submenu: [
@@ -397,9 +397,9 @@ this.onRender = function() {
397397
case LX.TreeEvent.NODE_SELECTED:
398398
this.selectNode( event.node );
399399
break;
400-
// case LX.TreeEvent.NODE_DELETED:
401-
// this.deleteNode( event.node.node );
402-
// break;
400+
case LX.TreeEvent.NODE_DELETED:
401+
this.deleteNode( event.node.node );
402+
break;
403403
// case LX.TreeEvent.NODE_DBLCLICKED:
404404
// console.log(event.node.id + " dbl clicked");
405405
// break;
@@ -562,36 +562,24 @@ this.onRender = function() {
562562

563563
onAddMesh( geometryType ) {
564564

565-
const mesh = new WGE.MeshInstance3D();
566-
mesh.name = `${ geometryType }_${ LX.guidGenerator() }`;
565+
const meshInstance = new WGE.MeshInstance3D();
567566

568-
// Add a surface
569-
let surface = null;
570-
571-
if( geometryType === "Sphere" )
572-
{
573-
surface = WGE.RendererStorage.getSurface("sphere");
574-
}
575-
else if( geometryType === "Torus" )
576-
{
577-
surface = WGE.RendererStorage.getSurface("torus");
578-
}
579-
else if( geometryType === "Box" )
580-
{
581-
surface = WGE.RendererStorage.getSurface("box");
582-
}
583-
else
567+
// Create a mesh instance
568+
const geometryClass = WGE[ `${ geometryType }Mesh` ];
569+
570+
if( !geometryClass )
584571
{
585572
throw new Error( `Unknown geometry type: ${ geometryType }` );
586573
}
587574

588-
mesh.addSurface( surface );
575+
meshInstance.name = `${ geometryType }_${ LX.guidGenerator() }`;
576+
meshInstance.mesh = new geometryClass();
589577

590578
// Add a material
591579
const material = new WGE.Material();
592580
material.setShader( WGE.RendererStorage.getShaderFromName( "mesh_forward", material ) );
593-
mesh.setSurfaceMaterialOverride( surface, material );
594-
this.scene.addNode( mesh, -1 );
581+
meshInstance.setSurfaceMaterialOverride( meshInstance.getSurface( 0 ), material );
582+
this.scene.addNode( meshInstance, -1 );
595583

596584
this.sceneTreePanel.refresh();
597585
},
@@ -654,8 +642,21 @@ this.onRender = function() {
654642
// Has geometry?
655643
if( node instanceof WGE.MeshInstance3D )
656644
{
657-
const surface = node.getSurface( 0 );
658-
this.inspectPropertiesAndMethods( node, surface, this.geometryPanel );
645+
this.inspectPropertiesAndMethods( node, node.mesh, this.geometryPanel, true, { propertiesTitle: node.mesh.type, propertiesIcon: WGE[ node.mesh.type ]?.icon } );
646+
647+
const surfaces = node.mesh.surfaces;
648+
649+
if( surfaces.size() > 0 )
650+
{
651+
this.geometryPanel.addSeparator();
652+
}
653+
654+
for( let i = 0; i < surfaces.size(); i++ )
655+
{
656+
const surface = surfaces.get( i );
657+
this.inspectPropertiesAndMethods( node, surface, this.geometryPanel, false, { propertiesTitle: `${ surface.name } (Surface)` } );
658+
}
659+
659660
hasGeometry = true;
660661
}
661662
else
@@ -691,13 +692,17 @@ this.onRender = function() {
691692
this.nodePanelTabs.tabDOMs[ "Script" ].classList.toggle( "hidden", !hasScript );
692693
},
693694

694-
inspectPropertiesAndMethods( node, obj, panel, options = {} ) {
695+
inspectPropertiesAndMethods( node, obj, panel, clearPanel, options = {} ) {
696+
697+
if( clearPanel ?? true )
698+
{
699+
panel.clear();
700+
}
695701

696-
panel.clear();
697702

698703
if( obj.constructor.properties?.length )
699704
{
700-
panel.branch( "Properties" );
705+
panel.branch( options.propertiesTitle ?? "Properties", { icon: options.propertiesIcon } );
701706

702707
for( let p of obj.constructor.properties )
703708
{
@@ -828,7 +833,7 @@ this.onRender = function() {
828833
const filename = file.name;
829834
Module._writeFile( filename, data );
830835
p.setter.call( obj, filename );
831-
this.inspectPropertiesAndMethods( node, obj, panel, options );
836+
this.inspectPropertiesAndMethods( node, obj, panel, clearPanel, options );
832837
LX.emit( `@on_${ p.name }_changed`, { obj, value } );
833838
}, { fileInput: true, fileInputType: "buffer", disabled: p.disabled, icon: "EllipsisVertical" } );
834839
break;

www/wgpuengine.module.js

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ for( const key in Module )
1717
wgpuEngine[ key ] = Module[ key ];
1818
}
1919

20-
// Custom wrappers for some classes
20+
/*
21+
____ _ __ __
22+
/ ___| _ ___| |_ ___ _ __ ___ \ \ / / __ __ _ _ __ _ __ ___ _ __ ___
23+
| | | | | / __| __/ _ \| '_ ` _ \ \ \ /\ / / '__/ _` | '_ \| '_ \ / _ \ '__/ __|
24+
| |__| |_| \__ \ || (_) | | | | | | \ V V /| | | (_| | |_) | |_) | __/ | \__ \
25+
\____\__,_|___/\__\___/|_| |_| |_| \_/\_/ |_| \__,_| .__/| .__/ \___|_| |___/
26+
|_| |_|
27+
28+
* Add custom wrapper functions to adapt C++ features to JavaScript
29+
*/
2130

2231
wgpuEngine.RendererStorage.getTexture = async function( texturePath, textureFlags, onLoad ) {
2332
const textureFilePath = Module._getFilename( texturePath );
@@ -86,7 +95,37 @@ wgpuEngine.parseObj = async function( objPath, createAABB, onLoad ) {
8695
}).catch(( err ) => console.error( `${ Module._getCurrentFunctionName() }: ${ err }` ) );
8796
}
8897

89-
// Expose data for creating user interfaces
98+
/*
99+
____ _ ____ _ _
100+
/ ___| _ ___| |_ ___ _ __ ___ | _ \ _ __ ___ _ __ ___ _ __| |_(_) ___ ___
101+
| | | | | / __| __/ _ \| '_ ` _ \ | |_) | '__/ _ \| '_ \ / _ \ '__| __| |/ _ \/ __|
102+
| |__| |_| \__ \ || (_) | | | | | | | __/| | | (_) | |_) | __/ | | |_| | __/\__ \
103+
\____\__,_|___/\__\___/|_| |_| |_| |_| |_| \___/| .__/ \___|_| \__|_|\___||___/
104+
|_|
105+
106+
* Define properties that couldn't be binded from C++ due to limitations of Embind
107+
*/
108+
109+
Object.defineProperty( wgpuEngine.Mesh.prototype, "skeleton", {
110+
get: function() { return this._getSkeleton(); },
111+
set: function( value ) { this._setSkeleton( value ); }
112+
});
113+
114+
Object.defineProperty( wgpuEngine.MeshInstance3D.prototype, "mesh", {
115+
get: function() { return this._getMesh(); },
116+
set: function( value ) { this._setMesh( value ); }
117+
});
118+
119+
/*
120+
____ _ _____ _
121+
| _ \ __ _| |_ __ _ | ____|_ ___ __ ___ ___(_)_ __ __ _
122+
| | | |/ _` | __/ _` | | _| \ \/ / '_ \ / _ \/ __| | '_ \ / _` |
123+
| |_| | (_| | || (_| | | |___ > <| |_) | (_) \__ \ | | | | (_| |
124+
|____/ \__,_|\__\__,_| |_____/_/\_\ .__/ \___/|___/_|_| |_|\__, |
125+
|_| |___/
126+
127+
* Expose data for creating user interfaces
128+
*/
90129

91130
/* Camera */
92131

@@ -106,6 +145,60 @@ wgpuEngine.Camera.properties = [
106145
wgpuEngine.FlyoverCamera.icon = "Camera";
107146
wgpuEngine.FlyoverCamera.properties = wgpuEngine.Camera.properties.concat( [] );
108147

148+
/* Meshes */
149+
150+
wgpuEngine.Mesh.properties = [];
151+
152+
wgpuEngine.QuadMesh.icon = "Square";
153+
wgpuEngine.QuadMesh.properties = wgpuEngine.Mesh.properties.concat( [
154+
{ name: "width", prettyName: "Width", type: Number, min: 0.01, max: 4, step: 0.01 },
155+
{ name: "height", prettyName: "Height", type: Number, min: 0.01, max: 4, step: 0.01 },
156+
{ name: "subdivisions", prettyName: "Subdivisions", type: Number, min: 0, max: 64, step: 1 },
157+
{ name: "centered", prettyName: "Centered", type: Boolean },
158+
{ name: "flipY", prettyName: "Flip Y", type: Boolean }
159+
] );
160+
161+
wgpuEngine.BoxMesh.icon = "Box";
162+
wgpuEngine.BoxMesh.properties = wgpuEngine.Mesh.properties.concat( [
163+
{ name: "width", prettyName: "Width", type: Number, min: 0.01, max: 4, step: 0.01 },
164+
{ name: "height", prettyName: "Height", type: Number, min: 0.01, max: 4, step: 0.01 },
165+
{ name: "depth", prettyName: "Depth", type: Number, min: 0.01, max: 4, step: 0.01 },
166+
] );
167+
168+
wgpuEngine.SphereMesh.icon = "Circle";
169+
wgpuEngine.SphereMesh.properties = wgpuEngine.Mesh.properties.concat( [
170+
{ name: "radius", prettyName: "Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
171+
{ name: "rings", prettyName: "Rings", type: Number, min: 1, max: 64, step: 1 },
172+
{ name: "ringSegments", prettyName: "Ring Segments", type: Number, min: 4, max: 64, step: 1 }
173+
] );
174+
175+
wgpuEngine.CapsuleMesh.icon = "Pill";
176+
wgpuEngine.CapsuleMesh.properties = wgpuEngine.Mesh.properties.concat( [
177+
{ name: "radius", prettyName: "Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
178+
{ name: "height", prettyName: "Height", type: Number, min: 0.01, max: 4, step: 0.01 },
179+
{ name: "rings", prettyName: "Rings", type: Number, min: 3, max: 64, step: 1 },
180+
{ name: "ringSegments", prettyName: "Ring Segments", type: Number, min: 3, max: 64, step: 1 }
181+
] );
182+
183+
wgpuEngine.CylinderMesh.icon = "Cylinder";
184+
wgpuEngine.CylinderMesh.properties = wgpuEngine.Mesh.properties.concat( [
185+
{ name: "topRadius", prettyName: "Top Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
186+
{ name: "bottomRadius", prettyName: "Bottom Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
187+
{ name: "height", prettyName: "Height", type: Number, min: 0.01, max: 4, step: 0.01 },
188+
{ name: "rings", prettyName: "Rings", type: Number, min: 3, max: 64, step: 1 },
189+
{ name: "ringSegments", prettyName: "Ring Segments", type: Number, min: 3, max: 64, step: 1 },
190+
{ name: "capTop", prettyName: "Cap Top", type: Boolean },
191+
{ name: "capBottom", prettyName: "Cap Bottom", type: Boolean },
192+
] );
193+
194+
wgpuEngine.TorusMesh.icon = "Torus";
195+
wgpuEngine.TorusMesh.properties = wgpuEngine.Mesh.properties.concat( [
196+
{ name: "ringRadius", prettyName: "Ring Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
197+
{ name: "tubeRadius", prettyName: "Tube Radius", type: Number, min: 0.01, max: 4, step: 0.01 },
198+
{ name: "rings", prettyName: "Rings", type: Number, min: 3, max: 64, step: 1 },
199+
{ name: "ringSegments", prettyName: "Ring Segments", type: Number, min: 3, max: 64, step: 1 },
200+
] );
201+
109202
/* AABB */
110203

111204
wgpuEngine.AABB.icon = "Box";
@@ -275,7 +368,7 @@ fn fs_main(in: VertexOutput, @builtin(front_facing) is_front_facing: bool) -> Fr
275368
var out: FragmentOutput;
276369
var dummy = camera_data.eye;
277370
278-
out.color = vec4f(1.0, 0.0,0.0, 1.0);
371+
out.color = vec4f(1.0, 0.0, 0.0, 1.0);
279372
280373
return out;
281374
}`;

0 commit comments

Comments
 (0)