-
Notifications
You must be signed in to change notification settings - Fork 141
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
13 changed files
with
152 additions
and
568 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<link rel="stylesheet" href="../../../resources/styles.css"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | ||
<link rel="icon" type="image/x-icon" href="../../../resources/favicon.ico"> | ||
<title>Simple 2D Scene</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.full-screen { | ||
width: 100vw; | ||
height: 100vh; | ||
position: relative; | ||
overflow: hidden; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="full-screen" id="container"></div> | ||
<script type="module" src="./example.ts"></script> | ||
</body> | ||
|
||
</html> |
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,27 @@ | ||
import * as THREE from "three"; | ||
import * as OBC from "../.."; | ||
|
||
const container = document.getElementById("container")!; | ||
|
||
const components = new OBC.Components(); | ||
|
||
const worlds = components.get(OBC.Worlds); | ||
const world = new OBC.SimpleWorld< | ||
OBC.SimpleScene, | ||
OBC.SimpleCamera, | ||
OBC.SimpleRenderer | ||
>(components); | ||
|
||
world.scene = new OBC.SimpleScene(components); | ||
world.renderer = new OBC.SimpleRenderer(components, container); | ||
world.camera = new OBC.SimpleCamera(components); | ||
|
||
worlds.add(world); | ||
|
||
components.init(); | ||
|
||
const cube = new THREE.Mesh(new THREE.BoxGeometry()); | ||
world.scene.three.add(cube); | ||
|
||
const grids = components.get(OBC.Grids); | ||
grids.create(world); |
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,48 @@ | ||
import * as THREE from "three"; | ||
import { Component, Disposable, World, Event } from "../Types"; | ||
import { GridConfig, SimpleGrid } from "./src"; | ||
|
||
export class Grids extends Component implements Disposable { | ||
static readonly uuid = "d1e814d5-b81c-4452-87a2-f039375e0489" as const; | ||
|
||
list = new Map<string, SimpleGrid>(); | ||
|
||
onDisposed = new Event(); | ||
|
||
config: Required<GridConfig> = { | ||
color: new THREE.Color(0xbbbbbb), | ||
size1: 1, | ||
size2: 10, | ||
distance: 500, | ||
}; | ||
|
||
/** {@link Component.enabled} */ | ||
enabled = true; | ||
|
||
create(world: World) { | ||
if (this.list.has(world.uuid)) { | ||
throw new Error("This world already has a grid!"); | ||
} | ||
const grid = new SimpleGrid(this.components, world, this.config); | ||
this.list.set(world.uuid, grid); | ||
world.onDisposed.add(() => { | ||
this.delete(world); | ||
}); | ||
} | ||
|
||
delete(world: World) { | ||
const grid = this.list.get(world.uuid); | ||
if (grid) { | ||
grid.dispose(); | ||
} | ||
this.list.delete(world.uuid); | ||
} | ||
|
||
dispose() { | ||
for (const [_id, grid] of this.list) { | ||
grid.dispose(); | ||
} | ||
this.list.clear(); | ||
this.onDisposed.trigger(); | ||
} | ||
} |
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 @@ | ||
export * from "./simple-grid"; |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.