Source file: /examples/render/webgl/basictriangle.js
import {
createCamera3D,
Mesh,
World,
EntityCommands,
createBasicMesh3D,
BasicMaterial,
BasicMaterialAssets,
MeshAssets,
App,
AppSchedule,
DOMWindowPlugin,
DefaultPlugin,
FPSDebugger,
WebglRendererPlugin
} from 'wima'
const app = new App()
app
.registerPlugin(new WebglRendererPlugin())
.registerPlugin(new DefaultPlugin())
.registerPlugin(new DOMWindowPlugin())
.registerDebugger(new FPSDebugger())
.registerSystem({ schedule: AppSchedule.Startup, system: spawnMesh })
.registerSystem({ schedule: AppSchedule.Startup, system: addDefaultCamera3D })
.run()
/**
* @param {World} world
*/
function addDefaultCamera3D(world) {
const commands = new EntityCommands(world)
commands
.spawn()
.insertPrefab([...createCamera3D(0, 0, 2)])
.build()
}
/**
* @param {World} world
*/
function spawnMesh(world) {
const commands = new EntityCommands(world)
const meshes = world.getResource(MeshAssets)
const materials = world.getResource(BasicMaterialAssets)
const mesh = meshes.add(Mesh.triangle3D())
const material = materials.add(new BasicMaterial())
commands
.spawn()
.insertPrefab([
...createBasicMesh3D(mesh, material)])
.build()
}