JSFiddle - React, Tailwind, and code Playground
by realhunts
HTML
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<textarea id="map" width="400" height="700" style="width:500px;height:300px;font-family: monospace;">
###wwwwww##wwwwww########www#####
#...................#...........#
#...................#............
w...................#............
w...................#............
w............##...######## .....#
w............#...........###...##
w............#..................#
w............#..................#
#............#..................w
#............#..................w
##############..................w
#............#..................w
w ...........#..................#
w...............................#
w........................########
w............#..................#
#............#..................w
##############..................w
#............#..................w
#............#..................w
w...............................#
w...............................w
w...............................w
w............#..................w
#............#..................w
#............#..................#
###############...#####...#######
#..................#............#
#..................#............#
w..................#............w
w..................#............w
w..................#............w
w..................#............w
#..................#............#
#..................#............#
###wwwwww##wwwwww####wwww##wwww##
</textarea>
<script>
function House(map) {
var me = this;
var WALL_HEIGHT = 10;
var walls = [];
var floorCeil = [];
var roof = [];
var addPlane =...
CSS
textarea{
display: none
}
JavaScript
// a basic three.js scene
var container, renderer, scene, camera, controls;
init();
animate();
function init() {
// renderer
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xccccff);
container = document.createElement('div');
document.body.appendChild(container);
container.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 200, 800);
camera.lookAt(scene.position);
// (camera) controls
// mouse controls: left button to rotate,
// mouse wheel to zoom, right button to pan
controls = new THREE.OrbitControls(camera, renderer.domElement);
// light
var light = new THREE.PointLight(0xffffff);
light.position.set(100, 250, 250);
scene.add(light);
// mesh
var house = new House(document.getElementById('map').value);
var h = house.addToScene(scene, 0, 0, 0, 4, true)
h.scale.set(5, 5,5)
console.log(h)
h.rotation.x = -Math.PI/2
var planeGeometry = new THREE.PlaneGeometry(500, 500, 10, 10);
var planeMaterial = new THREE.MeshLambertMaterial({
color: 0x888888,
side: THREE.DoubleSide
});
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.rotation.x = -Math.PI / 2;
scene.add(plane);
// events
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize(event) {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}