Skip to content

Instantly share code, notes, and snippets.

@MizunagiKB
Created January 10, 2021 08:59
Show Gist options
  • Save MizunagiKB/ab5d6d75b101d1bf00150c977faac660 to your computer and use it in GitHub Desktop.
Save MizunagiKB/ab5d6d75b101d1bf00150c977faac660 to your computer and use it in GitHub Desktop.
three.js sample
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r124/three.js"
integrity="sha512-tmdOKTY7I6MOUcCL/9fa4s+BnBCgEuifJImOX46m36+rxVMcgHEPGLVoCXHR6ZvjcKGoVixEiBKE4LcYLnv0Cw=="
crossorigin="anonymous"></script>
<script>
const data = ""
+ "(-27.550, -70.624, 51.7)\n"
+ "(10.0, 10.0, 0.0)\n"
+ "(100.0, -50.0, 100.0)\n";
function parse_data(scene, raw_data) {
let lines = raw_data.split(/\r?\n/)
for (let n = 0; n < lines.length; n++) {
let v = lines[n].replace("(", "[").replace(")", "]").trim()
if (v.length > 0) {
try {
const pos = JSON.parse(v)
const cgeometry = new THREE.CircleGeometry(10, 6);
const cmaterial = new THREE.MeshBasicMaterial({ color: 0xFFFFFF });
const circle = new THREE.Mesh(cgeometry, cmaterial);
circle.position.set(pos[0], pos[1], pos[2])
scene.add(circle);
} catch (e) {
console.log("parse error >>>", v);
}
}
}
}
function main() {
const renderer = new THREE.WebGLRenderer();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const scene = new THREE.Scene();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.z = 200;
parse_data(scene, data);
renderer.render(scene, camera);
}
window.onload = function () { main(); }
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment