body {
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
/* THREE.Object3D.DefaultUp.set(0,0,1); */
// three.js info box follows shape
var renderer, scene, camera, controls;
var angle = 0;
var arrow;
var rayCaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var axis = new THREE.Vector3();
// material
var material = new THREE.MeshPhongMaterial({
color: 0x0000ff,
shading: THREE.FlatShading
});
init();
animate();
function init() {
// info
var info = document.createElement('div');
info.style.position = 'absolute';
info.style.top = '30px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.style.color = '#fff';
info.style.fontWeight = 'bold';
info.style.backgroundColor = 'transparent';
info.style.zIndex = '1';
info.style.fontFamily = 'Monospace';
info.innerHTML = "three.js - set arrow direction from intersect face normal";
document.body.appendChild(info);
// renderer
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
var geometry = new THREE.BoxBufferGeometry(0.8, 0.2, 0.1);
var material = new THREE.MeshBasicMaterial({
color: 0xffff00
});
var cubeA = new THREE.Mesh(geometry, material);
cubeA.position.set(0, 0, 0);
var cubeB = new THREE.Mesh(new THREE.BoxBufferGeometry(0.11, 0.23, 0.2), material);
cubeB.position.set(0.45, 0, 0);
//create a group and add the two cubes
//These cubes can now be rotated / scaled etc as a group
var group = new THREE.Group();
group.add(cubeA);
group.add(cubeB);
scene.add(group);
//
var geometry = new THREE.BoxBufferGeometry(0.8, 0.2, 0.1);
var material = new THREE.MeshBasicMaterial({
color: 0xff0000
});
var cubeA2 = new THREE.Mesh(geometry, material);
cubeA2.position.set(0, 0, 0);
var cubeB2 = new THREE.Mesh(new THREE.BoxBufferGeometry(0.11, 0.1, 0.7), material);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.