<script src="https://rawgit.com/mrdoob/three.js/dev/build/three.js"></script>
<script src="https://rawgit.com/mrdoob/three.js/dev/examples/js/controls/OrbitControls.js"></script>
<p>
When putting a child mesh inside of a parent mesh, the child mesh's world space is still intact. For example, to move a child up before parenting, you would use the axis-Z.
After parenting, even if the parent flipped, to move the child up, you'd continue to target the axis-Z.
</p>
JavaScript
var wallsPoint = [{
"X": 0,
"Y": 0
},
{
"X": 5,
"Y": -5
},
{
"X": 5,
"Y": 3
},
{
"X": 7,
"Y": 3
},
{
"X": 7,
"Y": 5
},
{
"X": 5,
"Y": 5
},
{
"X": 5,
"Y": 7
},
{
"X": 0,
"Y": 7
}
];
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(3.5, 10, 3.5);
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.target.set(3.5, 0, -3.5);
controls.update();
var grid = new THREE.GridHelper(20, 20, 0x44ff44);
grid.position.set(0, -0.01, 0);
scene.add(grid);
var wallPoints = wallsPoint.map(w => {
return new THREE.Vector3(w.X, 0, -w.Y)
});
var geom = new THREE.BufferGeometry().setFromPoints(wallPoints);
var points = new THREE.Points(geom, new THREE.PointsMaterial({
size: 1,
color: "green"
}));
var lines = new THREE.LineLoop(geom, new THREE.LineBasicMaterial({
color: "yellow"
}));
scene.add(points, lines);
var marker = new THREE.Mesh(new THREE.SphereBufferGeometry(0.25, 8, 2), new THREE.MeshBasicMaterial({
color: "aqua"
}));
marker.position.set(3.5, 3.5, 0);
scene.add(marker);
document.addEventListener("mousemove", onMouseMove, false);
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
var iPoint = new THREE.Vector3();
function onMouseMove(event) {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
raycaster.ray.intersectPlane(plane, marker.position);
marker.material.color.set(isInside(marker.position, wallPoints) ? "aqua"...
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.