JSFiddle - React, Tailwind, and code Playground
by realhunts
HTML
<script src="http://threejs.org/build/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://threejs.org/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://threejs.org/examples/js/utils/BufferGeometryUtils.js"></script>
<script src="https://stemkoski.github.io/Three.js/js/Stats.js"></script>
JavaScript
// a basic three.js scene
var container, renderer, scene, camera, controls;
var stats;
init();
animate();
function init() {
// renderer
renderer = new THREE.WebGLRenderer({
antialias: false,
precision: 'lowp'
});
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, 1000000);
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, 5);
light.position.set(100, 250, 250);
scene.add(light);
// STATS
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
// trees
function addTrees() {
var geom = [];
var glTFLoader = new THREE.GLTFLoader();
glTFLoader.load( 'https://cdn.glitch.com/27780c96-8860-401c-a4e0-26a8674900ba%2Fscene%20(42).glb?1550946761701', ( gltf ) => {
const tree = gltf.scene.children[ 1 ];
tree.geometry.rotateX(Math.PI/2)
console.log(tree)
for ( let i = 0; i< 150 ; i ++ ) {
const scale = 2 + ( Math.random() * 1.5 );
const mesh = tree.clone();
mesh.geometry.translate(( Math.random() * .2 ), -.1, ( Math.random() * .1 ));
//mesh.geometry.rotateX(Math.PI/2);
//mesh.geometry.rotateX(Math.PI/2);
//mesh.position.y = -100;
// mesh.position.z = ( Math.random() * 3000 ) - 3000;
// keep the way through the forest free of...