I have multiple scene like => How to change the zOrder of object with Threejs?.
I want to select now an element with a Raycast, but I get one raycast for each scene, how can I handle all taken elements from all scenes at ones.
You can try to add all objects of both scenes into a separate array. In the next step, you use this array in order to call Raycaster.intersectObjects() like this:
raycaster.intersectObjects( objects );
Related
I'm trying to get access to inner THREE components to be able to change camera positions, add items to the scene, etc. How can I get access to these internal mechanics of THREE from this module? web-ifc-viewer: https://github.com/IFCjs/web-ifc-viewer
You can use ifcViewer.context to get the scene objects from Three.js.
Some other useful properties/ methods
ifcViewer.context.getScene()
ifcViewer.context.items
Hope this is what you're looking for.
Before changing your camera position, you need to disable cameraControls
viewer.context.ifcCamera.cameraControls.enabled = false;
I'm able to load in a model using assimp with:
SceneNode _sceneModel = new Importer().Load(path).Root;
This seems to load in the geometry into its separate meshes - for instance if in Maya you built a room with Wall_1, Wall_2, Wall_3, etc. the SceneNode is some kind of data structure with all the meshes.
The separate meshes can then be put into an array
geometry = _sceneModel.Traverse().Where(x => (x is MeshNode)).Select(m => ((MeshNode)m).Geometry).ToArray();
But ultimately I just want to bind the entire single piece of geometry (eg a house) in xml to
<MeshGeometryModel3D>
but can't figure out how to do it. I can bind a single piece of geometry eg. from the geometry array I can bind geometry[1] which might represent a wall but can't workout how to bind the whole thing.
Thanks
MeshGeometryModel3D is a wpf wrapper for Mesh Node (which is a scene node). If you only want to display your loaded model, you can add the root scene node into a GroupNodeModel3D.
You can find example here
https://github.com/helix-toolkit/helix-toolkit/blob/2254fce0870a165352ccb888e2f3e17398751724/Source/Examples/WPF.SharpDX/FileLoadDemo/MainViewModel.cs#L128
I created 1000 hidden objects with BoxGeometry geometry using THREE.JS. I set object.visible = false to hide each object, however this causes the raycasting/interaction to not work.
I expect that hiding the objects will give me a performance boost.
I can hide the box objects by setting material.visible = false on each object, however the performance of my app is still terrible.
How can I achieve the required raycasting interaction with hidden objects in the performance friendly way?
One way to achieve what you require would be to not add your Box objects to your scene which would ensure that they are not rendered, and pass those directly to a THREE.Raycaster to determine if intersection between any of those boxes has occurred.
You could for instance crate a THREE.Raycaster object from your ray primitive, and then pass an array of your Box objects to the .intersectObjects() method to determine ray intersection.
In code, that would look something like this:
// ray is your intersection primitive
const raycaster = new THREE.Raycaster(ray.origin, ray.direction);
// boxObjects is an array of THREE.Object3D's representing your 1000 boxes
const intersectionResult = raycaster.intersectObjects(boxObjects)
Currently, I am trying to dive deeper into grouped objects or better hierachic ordered objects. However I got a strange issue with the position and the visibility of a object3D and childs of those.
So i have a set of objects, a light source with is the main object so far, and a few spheres for example, which are childs of the the main object.
The problem is, that child objects, which are positioned behind another object ( siblings ) ( from the camera view ) are visible. And all childs objects appear infront of the main object while those actually positioned behind the main object.
Sadly i can't reproduce this in a codePen so i had to take some pictures of the scene, many apologies for that.
In the pictures, the camera rotates clockwise around the light source (main object to the left).
So basically what I am doing is:
mObj = new THREE.Object3D();
mObj.add(new THREE.Mesh(someGeometry, someMaterial);
cObj = new THREE.Object3D();
cObj.add(new THREE.Mesh(someGeometry, someMaterial);
mObj.add(cObj);
scene.add(mObj);
Is that related to the object hierachic order or something else?
The second more negligible issue is, that on one of my pc's, those parts of objects which are dark (because of no lighting), generate those strange black/grey faces, which i cant explain. Maybe Graphicscard/driver or something?
What's the distance between these objects? It could be a floating point rounding issue. I've run into it myself.
If it's so, and you're getting flickering models, you'll need to keep your camera and the active model at the origin, and move the universe around you to keep precision in the important places (near the player).
I want to have two overlapping objects in a scene but I want to define which object should be drawn first. I have a sample of the code here: http://jsfiddle.net/sg02e5sm/1/
I'm using renderOrder = 1 for the second object to make it appear always on top of the first object (as long as they have the same Z value), but it's not working.
renderOrder does not make something appear "on top". It controls the order in which objects are rendered.
If you want your 2nd plane to be "on top", you can add
mesh.material.depthTest = false;
for the 2nd plane.
Alternatively, you can implement two render passes, as described in this SO answer.
three.js r.142