-
Notifications
You must be signed in to change notification settings - Fork 1
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
5 changed files
with
117 additions
and
7 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
webviewer | ||
node_modules |
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,9 +1,8 @@ | ||
index.ts | ||
tsconfig.json | ||
src | ||
build | ||
src/*.ts | ||
!src/*.d.ts | ||
webviewer | ||
*.ts | ||
.prettierrc | ||
.eslintrc | ||
.eslintignore |
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<title>VoxelGeometry Viewer</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"three": "/node_modules/three/build/three.module.js", | ||
"three/addons/": "/node_modules/three/examples/jsm/" | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
import * as THREE from "three"; | ||
import { OrbitControls } from "three/addons/controls/OrbitControls.js"; | ||
|
||
const createScene = () => { | ||
let scene = new THREE.Scene(); | ||
scene.background = new THREE.Color(0xbfd1e5); | ||
return scene; | ||
}; | ||
|
||
let scene = createScene(); | ||
|
||
const createCamera = () => { | ||
return new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | ||
}; | ||
|
||
const camera = createCamera(); | ||
|
||
const createRenderer = () => { | ||
const renderer = new THREE.WebGLRenderer({ | ||
antialias: true, | ||
}); | ||
renderer.setPixelRatio(window.devicePixelRatio); | ||
renderer.setSize(window.innerWidth, window.innerHeight); | ||
document.body.appendChild(renderer.domElement); | ||
return renderer; | ||
}; | ||
|
||
const renderer = createRenderer(); | ||
|
||
const createMaterial = () => { | ||
const texture = new THREE.TextureLoader().load("./texture.png"); | ||
const material = new THREE.MeshBasicMaterial({ | ||
map: texture, | ||
side: THREE.DoubleSide, | ||
}); | ||
material.transparent = true; | ||
texture.magFilter = THREE.NearestFilter; | ||
return material; | ||
}; | ||
|
||
const material = createMaterial(); | ||
|
||
const geometry = new THREE.BoxGeometry(1, 1, 1); | ||
|
||
const createBlock = (x, y, z) => { | ||
const cube = new THREE.Mesh(geometry, material); | ||
scene.add(cube); | ||
cube.position.x = x; | ||
cube.position.y = y; | ||
cube.position.z = z; | ||
}; | ||
|
||
const clear = () => { | ||
scene = createScene(); | ||
}; | ||
|
||
camera.position.z = 5; | ||
|
||
const controls = new OrbitControls(camera, renderer.domElement); | ||
controls.target.set(1, 1, 1); | ||
controls.update(); | ||
|
||
(function animate() { | ||
requestAnimationFrame(animate); | ||
renderer.render(scene, camera); | ||
})(); | ||
|
||
const ws = new WebSocket("ws://127.0.0.1:2333"); | ||
|
||
ws.onmessage = function (msg) { | ||
const op = JSON.parse(msg.data); | ||
if (op["op"] == "clear") { | ||
clear(); | ||
} else { | ||
for (let x of op["raw"]) { | ||
createBlock(x[0], x[1], x[2]); | ||
} | ||
} | ||
}; | ||
</script> | ||
</body> | ||
|
||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.