## Three.js: Adding and Removing Children of Rotated Objects

The trick is to make use of THREE.Object3D.attach(). You need to begin with all your 27 cubes as a child of the scene. Let pivot be an Object3D(). Let active be an array containing the 9 cubes you want to rotate. Now make the cubes a child of the pivot: pivot.rotation.set( 0, 0, 0 ); … Read more

## What’s the simple way to compute the diagonal length of a 3D mesh bounding box?

For simplicity let us consider a list of n 3D points (point cloud) as input (instead of mesh) which is enough for polygonal meshes. The “diagonal” of the mesh is just line between 2 most distant points in the mesh. That is easily computable with trivial O(n^2) brute force search (2 nested for loops remembering … Read more

## How to create custom 3d model in JavaFX 8?

nothing appeared in the scene Your sample mesh rendered OK for me. Perhaps you didn’t have your camera setup correctly or have your mesh scaled so that it was visible. Your sample mesh doesn’t do much, it is one triangle facing towards the camera and a second triangle facing away from the camera. And is … Read more

## Move camera to fit 3D scene

There are many possible camera positions + orientations where the bounding box would fit inside the view frustum. But any procedure would select one specific camera position and orientation. If you would consider bounding spheres, one solution could be to first change orientation to look at bounding sphere center then move back sufficiently (negative look … Read more

## How can matplotlib 2D patches be transformed to 3D with arbitrary normals?

Short answer Copy the code below into your project and use the method def pathpatch_2d_to_3d(pathpatch, z = 0, normal=”z”): “”” Transforms a 2D Patch to a 3D patch using the given normal vector. The patch is projected into they XY plane, rotated about the origin and finally translated by z. “”” to transform your 2D … Read more

## 3D Line-Plane Intersection

Here is a Python example which finds the intersection of a line and a plane. Where the plane can be either a point and a normal, or a 4d vector (normal form), In the examples below (code for both is provided). Also note that this function calculates a value representing where the point is on … Read more

## How do I reverse-project 2D points into 3D?

[*] Alright, I came here looking for an answer and didn’t find something simple and straightforward, so I went ahead and did the dumb but effective (and relatively simple) thing: Monte Carlo optimisation. Very simply put, the algorithm is as follows: Randomly perturb your projection matrix until it projects your known 3D coordinates to your … Read more

Categories 3d

## Converting 3D position to 2d screen position [r69!]

I’ve written for my project the following function; it receives an THREE.Object3D instance and a camera as a parameters and returns the position on the screen. function toScreenPosition(obj, camera) { var vector = new THREE.Vector3(); var widthHalf = 0.5*renderer.context.canvas.width; var heightHalf = 0.5*renderer.context.canvas.height; obj.updateMatrixWorld(); vector.setFromMatrixPosition(obj.matrixWorld); vector.project(camera); vector.x = ( vector.x * widthHalf ) + widthHalf; … Read more