-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ callback ([DWM](https://github.com/deno-windowing/dwm) handles both). | |
|
||
```ts | ||
// GLES2 3.2 API | ||
import * as gl from "https://deno.land/x/[email protected].0/api/gles23.2.ts"; | ||
import * as gl from "https://deno.land/x/[email protected].1/api/gles23.2.ts"; | ||
|
||
// Initialize function pointers | ||
gl.load(yourGetProcAddress); | ||
|
@@ -45,6 +45,11 @@ along with `--allow-ffi`. | |
deno run --unstable --allow-ffi <file> | ||
``` | ||
|
||
Extensions: | ||
|
||
- [Babylon](https://www.babylonjs.com/) (Use | ||
`ext/babylon.ts` for an easy to use wrapper) | ||
|
||
## Maintainers | ||
|
||
- Dj ([@DjDeveloperr](https://github.com/DjDeveloperr)) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { init, World } from "../ext/babylon.ts"; | ||
|
||
class Game extends World { | ||
constructor() { | ||
super({ | ||
title: "Babylon.js", | ||
width: 800, | ||
height: 600, | ||
}, { | ||
preserveDrawingBuffer: true, | ||
stencil: true, | ||
// deno-lint-ignore no-explicit-any | ||
} as any, true); | ||
} | ||
|
||
createScene() { | ||
const scene = new BABYLON.Scene(this.engine); | ||
|
||
// This creates and positions a free camera (non-mesh) | ||
const camera = new BABYLON.FreeCamera( | ||
"camera1", | ||
new BABYLON.Vector3(0, 5, -10), | ||
scene, | ||
); | ||
|
||
// This targets the camera to scene origin | ||
camera.setTarget(BABYLON.Vector3.Zero()); | ||
|
||
// This attaches the camera to the canvas | ||
camera.attachControl(window, true); | ||
|
||
// This creates a light, aiming 0,1,0 - to the sky (non-mesh) | ||
const light = new BABYLON.HemisphericLight( | ||
"light", | ||
new BABYLON.Vector3(0, 1, 0), | ||
scene, | ||
); | ||
|
||
// Default intensity is 1. Let's dim the light a small amount | ||
light.intensity = 0.7; | ||
|
||
// Our built-in 'sphere' shape. | ||
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { | ||
diameter: 2, | ||
segments: 32, | ||
}, scene); | ||
|
||
// Move the sphere upward 1/2 its height | ||
sphere.position.y = 1; | ||
|
||
// Our built-in 'ground' shape. | ||
const _ground = BABYLON.MeshBuilder.CreateGround("ground", { | ||
width: 6, | ||
height: 6, | ||
}, scene); | ||
|
||
return scene; | ||
} | ||
} | ||
|
||
init(new Game()); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { init, World } from "../ext/babylon.ts"; | ||
|
||
class Game extends World { | ||
constructor() { | ||
super({ | ||
title: "Babylon.js", | ||
width: 800, | ||
height: 600, | ||
}, { | ||
preserveDrawingBuffer: true, | ||
stencil: true, | ||
// deno-lint-ignore no-explicit-any | ||
} as any, true); | ||
} | ||
|
||
createScene() { | ||
const scene = new BABYLON.Scene(this.engine); | ||
|
||
const camera = new BABYLON.ArcRotateCamera( | ||
"camera", | ||
-Math.PI / 2, | ||
Math.PI / 2.5, | ||
15, | ||
new BABYLON.Vector3(0, 0, 0), | ||
); | ||
camera.attachControl(this.canvas, true); | ||
const _light = new BABYLON.HemisphericLight( | ||
"light", | ||
new BABYLON.Vector3(1, 1, 0), | ||
scene, | ||
); | ||
|
||
BABYLON.SceneLoader.ImportMeshAsync( | ||
["ground", "semi_house"], | ||
"https://assets.babylonjs.com/meshes/", | ||
"both_houses_scene.babylon", | ||
); | ||
|
||
return scene; | ||
} | ||
} | ||
|
||
init(new Game()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//@deno-types="npm:babylonjs" | ||
import "https://deno.land/x/[email protected]/mod.ts"; | ||
import { WebGLCanvas } from "../src/webgl/mod.ts"; | ||
import "https://preview.babylonjs.com/ammo.js"; | ||
|
@@ -10,42 +11,45 @@ import "https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proced | |
import "https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"; | ||
import "https://preview.babylonjs.com/loaders/babylonjs.loaders.js"; | ||
import "https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"; | ||
import { CreateWindowOptions } from "../src/webgl/deps.ts"; | ||
|
||
BABYLON.SceneLoader.ShowLoadingScreen = false; | ||
|
||
export const canvas = new WebGLCanvas({ | ||
title: "Babylon.js", | ||
width: 800, | ||
height: 600, | ||
// maximized: true, | ||
}); | ||
|
||
export const engine = new BABYLON.Engine(canvas, true, { | ||
preserveDrawingBuffer: true, | ||
stencil: true, | ||
}); | ||
export abstract class World { | ||
canvas: WebGLCanvas; | ||
engine: BABYLON.Engine; | ||
constructor( | ||
settings: CreateWindowOptions = {}, | ||
engineSettings: BABYLON.EngineOptions = {}, | ||
antialias = true, | ||
) { | ||
this.canvas = new WebGLCanvas(settings); | ||
this.engine = new BABYLON.Engine(this.canvas, antialias, engineSettings); | ||
addEventListener("resize", () => { | ||
this.engine.resize(); | ||
}); | ||
|
||
addEventListener("resize", () => { | ||
engine.resize(); | ||
}); | ||
addEventListener("close", () => { | ||
this.engine.stopRenderLoop(); | ||
}); | ||
} | ||
|
||
addEventListener("close", () => { | ||
engine.stopRenderLoop(); | ||
}); | ||
abstract createScene(): BABYLON.Scene; | ||
} | ||
|
||
export function runScene(createScene) { | ||
export function init<T extends World>(app: T) { | ||
const world = app; | ||
try { | ||
const scene = createScene(); | ||
|
||
engine.runRenderLoop(() => { | ||
const scene = world.createScene(); | ||
world.engine.runRenderLoop(() => { | ||
try { | ||
scene.render(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}); | ||
|
||
return canvas.run(); | ||
return world.canvas.run(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|