Skip to content

Commit

Permalink
wired-scene glxf refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Jul 7, 2024
1 parent 597f002 commit ad2518b
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 97 deletions.
4 changes: 1 addition & 3 deletions spatial/wit/wired-prelude/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ world imports {
import wired:math/types;
import wired:physics/types;
import wired:player/api;
import wired:scene/material;
import wired:scene/mesh;
import wired:scene/node;
include wired:scene/prelude;
}

world script {
Expand Down
136 changes: 136 additions & 0 deletions spatial/wit/wired-scene/gltf.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
interface gltf {
use material.{material};
use mesh.{mesh};
use node.{node};
use scene.{scene};

// A glTF document.
// Can be saved or loaded independently of the rest of the world.
resource gltf {
constructor();

// The currently loaded scene.
active-scene: func() -> option<scene>;
set-active-scene: func(value: option<borrow<scene>>);

// The default active scene, used when an asset is first loaded.
// If not explicitly set, the first scene will be used.
default-scene: func() -> option<scene>;
set-default-scene: func(value: borrow<scene>);

list-materials: func() -> list<material>;
add-material: func(value: borrow<material>);
remove-material: func(value: borrow<material>);

list-meshes: func() -> list<mesh>;
add-mesh: func(value: borrow<mesh>);
remove-mesh: func(value: borrow<mesh>);

list-nodes: func() -> list<node>;
add-node: func(value: borrow<node>);
remove-node: func(value: borrow<node>);

list-scenes: func() -> list<scene>;
add-scene: func(value: borrow<scene>);
remove-scene: func(value: borrow<scene>);
}
}

interface material {
record color {
r: f32,
g: f32,
b: f32,
a: f32,
}

resource material {
constructor();

id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

color: func() -> color;
set-color: func(value: color);
}
}

interface mesh {
use material.{material};

resource primitive {
id: func() -> u32;

material: func() -> option<material>;
set-material: func(value: option<borrow<material>>);

set-indices: func(value: list<u32>);
set-normals: func(value: list<f32>);
set-positions: func(value: list<f32>);
set-uvs: func(value: list<f32>);
}

resource mesh {
constructor();

id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

list-primitives: func() -> list<primitive>;
create-primitive: func() -> primitive;
remove-primitive: func(value: borrow<primitive>);
}
}

interface node {
use mesh.{mesh};
use wired:input/handler.{input-handler};
use wired:math/types.{transform};
use wired:physics/types.{collider, rigid-body};

resource node {
constructor();

id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

children: func() -> list<node>;
add-child: func(value: borrow<node>);
remove-child: func(value: borrow<node>);

parent: func() -> option<node>;

transform: func() -> transform;
set-transform: func(value: transform);

mesh: func() -> option<mesh>;
set-mesh: func(value: option<borrow<mesh>>);

collider: func() -> option<collider>;
set-collider: func(value: option<borrow<collider>>);

rigid-body: func() -> option<rigid-body>;
set-rigid-body: func(value: option<borrow<rigid-body>>);

input-handler: func() -> option<input-handler>;
set-input-handler: func(value: option<borrow<input-handler>>);
}
}

interface scene {
use node.{node};

resource scene {
constructor();

nodes: func() -> list<node>;
add-node: func(value: borrow<node>);
remove-node: func(value: borrow<node>);
}
}
65 changes: 65 additions & 0 deletions spatial/wit/wired-scene/glxf.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
interface glxf {
use gltf.{gltf};
use node.{node};

// Returns the root glXF that the script is attached to.
get-root: func() -> glxf;

// A glXF document.
// Used to compose multiple independent glTF assets together.
resource glxf {
constructor();

list-assets: func() -> list<asset>;
add-asset: func(value: asset);
remove-asset: func(value: asset);

list-nodes: func() -> list<glxf-node>;
add-node: func(value: borrow<glxf-node>);
remove-node: func(value: borrow<glxf-node>);
}

variant asset {
gltf(asset-gltf),
glxf(asset-glxf),
}

resource asset-gltf {
constructor(document: borrow<gltf>);

document: func() -> gltf;

list-nodes: func() -> list<node>;
add-node: func(value: borrow<node>);
remove-node: func(value: borrow<node>);
}

resource asset-glxf {
constructor(document: borrow<glxf>);

document: func() -> glxf;

list-nodes: func() -> list<glxf-node>;
add-node: func(value: borrow<glxf-node>);
remove-node: func(value: borrow<glxf-node>);
}

resource glxf-node {
constructor();

id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

parent: func() -> option<glxf-node>;

children: func() -> children;
set-children: func(value: children);
}

variant children {
asset(asset),
nodes(list<glxf-node>),
}
}
98 changes: 4 additions & 94 deletions spatial/wit/wired-scene/world.wit
Original file line number Diff line number Diff line change
@@ -1,100 +1,10 @@
package wired:scene;

world host {
world prelude {
import gltf;
import glxf;
import material;
import mesh;
import node;
}

interface material {
record color {
r: f32,
g: f32,
b: f32,
a: f32,
}

resource material {
id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

color: func() -> color;
set-color: func(value: color);
}

list-materials: func() -> list<material>;
create-material: func() -> material;
remove-material: func(value: material);
}

interface mesh {
use material.{material};

resource primitive {
id: func() -> u32;

material: func() -> option<material>;
set-material: func(value: option<borrow<material>>);

set-indices: func(value: list<u32>);
set-normals: func(value: list<f32>);
set-positions: func(value: list<f32>);
set-uvs: func(value: list<f32>);
}

resource mesh {
id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

list-primitives: func() -> list<primitive>;
create-primitive: func() -> primitive;
remove-primitive: func(value: primitive);
}

list-meshes: func() -> list<mesh>;
create-mesh: func() -> mesh;
remove-mesh: func(value: mesh);
}

interface node {
use mesh.{mesh};
use wired:input/handler.{input-handler};
use wired:math/types.{transform};
use wired:physics/types.{collider, rigid-body};

resource node {
id: func() -> u32;

name: func() -> string;
set-name: func(value: string);

children: func() -> list<node>;
add-child: func(value: borrow<node>);
remove-child: func(value: borrow<node>);

parent: func() -> option<node>;

transform: func() -> transform;
set-transform: func(value: transform);

mesh: func() -> option<mesh>;
set-mesh: func(value: option<borrow<mesh>>);

collider: func() -> option<collider>;
set-collider: func(value: option<borrow<collider>>);

rigid-body: func() -> option<rigid-body>;
set-rigid-body: func(value: option<borrow<rigid-body>>);

input-handler: func() -> option<input-handler>;
set-input-handler: func(value: option<borrow<input-handler>>);
}

list-nodes: func() -> list<node>;
create-node: func() -> node;
remove-node: func(value: node);
import scene;
}

0 comments on commit ad2518b

Please sign in to comment.