Skip to content

Commit

Permalink
merge webviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese committed Jul 24, 2023
1 parent 4979836 commit f2fda5e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
webviewer
node_modules
5 changes: 2 additions & 3 deletions .npmignore
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
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pureeval/voxel-geometry",
"version": "1.2.5",
"version": "1.2.6",
"type": "module",
"description": "voxel-geometry",
"devDependencies": {
Expand All @@ -13,10 +13,14 @@
"gulp-sourcemaps": "^3.0.0",
"gulp-typescript": "^6.0.0-alpha.1",
"source-map": "^0.7.4",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"express": "^4.18.2",
"three": "^0.126.1",
"ws": "^8.12.0"
},
"scripts": {
"lint": "eslint . --ext .ts"
"lint": "eslint . --ext .ts",
"webviewer": "tsc && node ./webviewer/server.js"
},
"main": "index.js",
"repository": {
Expand Down
106 changes: 106 additions & 0 deletions webviewer/public/index.html
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>
Binary file added webviewer/public/texture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2fda5e

Please sign in to comment.