Three.js: Trouble with dynamic geometry and merging - three.js

I want to display a lot of cubes. Their position is calculated during runtime, one more per frame. Just doing scene.add(cube) each time works but is too slow. So I want to merge their geometries each time. But when I try to add the merged geometry to the scene, it still shows the old version! I tried all kinds of .updateMatrix() and .verticesNeedUpdate=true things.
Interestingly the problem only comes up if I try to change things I have already added to the scene. It does work if I just do my merging in the background and add the result to the scene at some point! But After it has been added, merging it and adding the result still displays the old version. I've tried removing the Object from the scene first, but that doesn't change anything.

Finally came across the right command: group.geometry.groupsNeedUpdate = true;. Still can't find any good documentation on it, but it works

Related

Smooth animation of three shapes in SciLab

This answer provides a nice way to make smooth animations in SciLab. I now have to write a simulation of a body attached to two strings (and therefore its movement regarding some additional forces).
The code in the link works well to render movement of a single point and, unfortunately, I didn't manage to make an animation of a point + two lines using this method. If someone is curious, I tried this code to do it:
frametime=(tk-t0)/Nt//defining the waitnig time
plot(Y(1,1),Y(2,1),"o")//plotting the point
plot([0;Y(1,1)],[0;Y(2,1)],style=1)
plot([D;Y(1,1)],[0;Y(2,1)],style=1)//plotting the two initial lines
h1_compound = gce();
h_point=h1_compound.children
h_point.mark_size = 20;
h_point.mark_background = 2;
h_line1=h_compound.children
h_line2=h_compound.children
//h_axes = gca();
//h_axes.data_bounds = [0,-1;10,1];
realtimeinit(frametime);
for i=1:Nt//my vectors have Nt points
realtime(i);//wait "frametime" seconds before drawing the new position
h_point.data=[Y(1,i),Y(2,i)];
h_line1.data=[[0;Y(1,i)],[0;Y(2,i)]]
h_line2.data=[[D;Y(1,i)],[0;Y(2,i)]]
end
The question is: is there any way to make an animation of three shapes without making axes blink (as it is with the window refreshment) or other wierd stuff?
Since you didn't create a MCVE I can't reproduce your exact problem. But you may try to add drawlater(); before, and drawnow(); after your data modification to see if it does help with blinking or not.
Or you may get much better looking result by saving your plots in every round with xs2gif and assemble the animation with another gifmaker progam (there are free online sites to do this, however with some limitations). If you need to present your result, you should do this step anyway.

Inconsistent transparency, looking like render order issue

I am using r82.
I have a mesh with multiple materials. I can change their opacity just fine, but how they are rendered is what I would call "splotchy". I have been using ThreeJs for a while, and EDIT: was able to get the transparency working in a past version (r67) with the same model in a significantly more consistent way. So I was wondering if there is something that now I need to set that I didn't need to set before or if I am just overlooking something. Upon revisiting my older code and testing it again, I found that the same transparency issues were present. It was simply a matter of there not being as obvious "splotches" (and not testing enough, I'm sure). Here is a screenshot.
Here are a few more pictures I took that highlight the issue a bit better. I have the outside wall in a light grey and the floors a dark grey in the model and can toggle the outside walls to be visible or not. In these pictures I have one face of the outside wall purple and a face of the floor in the room on the other side of the wall green.
Based on the angle of the camera, it makes part of the green floor face invisible even though there is only one face between the camera and it.
The materials are all double sided already and there is no sign of this until the transparency is on. I found a similar question that suggested changing the mesh.setFaceCulling (or something similar) but that seemed to be from an older version and wasn't in r82.
Thanks for any help in advance!
EDIT:
I started looking into the old version of threeJS and the current version's source code to see what is done differently regarding transparency. I found transparentObjects, which is an array of the objects (I believe faces) that are going to be rendered and are in sorted based on "reversePainterSortStable". There is another list of objects (I believe for the materials objects, maybe?) called opaqueObjects that uses "painterSortStable". So to see if changing the sort order would change the outcome of how things are looking when transparent I changed it so that transparentObjects got sorted by "painterSortStable" and it did change how things showed up significantly (granted it didn't fix my problem since it just removed some problem spots and created new ones).
So the short version, it looks like it is an issue with the renderOrder of the faces.
That being said, I tried finding how the r67 version of the code handled the "renderOrder" of the faces since it wasn't something that (to my knowledge) could be set in that version and just did it automatically. But I have had no such luck tracking down how it was done as of yet.
So I see two possibilities. 1) find out how the past version correctly did transparency (at least for my purposes) and change the logic in the current version to use that. Or 2) find how to properly set the renderOrder of the faces based on the camera position in the scene. Will look into the second option first, but figured it would be good to document this for others looking to help answer or that have a similar problem.
EDIT 2:
So digging through the source code for threeJs and noticed something about the transparentObjects array I mentioned in the previous edit. The first, that I cannot for the life of me figure out how it gets populated since it doesn't seem like it is added to anywhere in the code. The second is that I think it is being populated with duplicates of the entire building object/mesh (see screenshot below).
The z indexes all seem to be the same. as well as the ids and the objects are all of type "mesh" (of the ones I looked through, granted, since there are a few thousand). So I was going to figure out why its adding what is being added to the array, but that is when I stumbled across the issue of not finding where in the code that the transparentObjects array actually get populated.
EDIT 3:
WestLangley, I tried setting the depth test for the outer wall material to false and got this. Like I said in my response comment, even if it did work it wouldn't fix the issues experienced with the camera inside the building, but wanted to follow up none the less (see snapshot below).

Problems importing unreal mesh collisions

I have an Unreal Engine 4 project. I have two sets of the same map, one unmerged and the other merged. THe merged map has the textures baked in. When I try to add a collision mesh in the baked level model everything works fine. When I try to add a collision mesh to the level broken down into several meshes, there isn't any option to add collision - in fact, half of the menu options aren't even there. I tried posting on the unreal forums without luck. I was hoping someone here might be able to help. Thanks - Ted
When you select an object in UE4 it shows properties of that object. When you select several objects, it shows only the properties that the selected objects have in common. So my guess is that you trying to set up a collision for several objects of different type. Try setting it one by one.

Three.js - Under what conditions are THREE.Lines frustum-culled?

I'm drawing a handful of lines (THREE.Line). Under some conditions, the line suddenly disappears from the screen. This happens frequently when one endpoint is far outside the camera's field of view, but the other one is definitely within the field of view. This also happens when the line crosses the camera's field of view, but both endpoints are far outside it.
I can temporarily fix it by setting frustumCulled to false for each line, but this isn't optimal since I might have thousands of lines in the scene.
Is this working as expected?
BTW, I'm using r68. I haven't had time to refactor my app to work with r69. I'm using the WebGLRenderer.
I needed avoiding lines to dissapear too.
Following Justin idea of frustumCulled I had to do
line.frustumCulled = false;
I thought it was
line.geometry.frustumCulled = false;
but I was wrong, you've to apply it on the line not on its geometry.
This works for me on version 0.70

Model with bones animation (blender export) animating incorrectly in three.js

I am currently working on skeletal animation tests in three.js. I have a simple model which animates just fine in blender. Basically it consists of three stacked, bending cubes.
When I export the blender file to the three.js using the blender export plugin with Blender V2.64, the animation in the webGl context appears different as if the skinweighting is wrong.
WebGL-Demo:
http://rainbowrangers.de/threejs/animation_test01/
Blender-File:
http://rainbowrangers.de/threejs/animation_test01/model/animation_test01.blend
What do I have to do to get the correct result in three.js?
I am the person you quoted from the github discussion. I have recently been experimenting with this pipeline, ( ie Blender bone animations into threejs,) and have found that it is very very difficulty to find a reliable process that will work every time.
On my blog, I have compiled a list of 'tips' that allowed me to achieve success on some occasions:
http://dev.mothteeth.com/2012/10/threejs-blender-exporting-skeletal-animations/
To summarise, the most important things I found were:
Delete the Armature Modifier before exporting, or the animation will be all messed up.
Check that your Vertex Groups are properly assigned to the bones. ( In Blender, you can use automatic bone weights. )
Key all bones in the first and last frames of your animation. ( As you discovered, if you only have keys for the bones you have changed, ThreeJS won't infer anything about the other ones, and things will be broken. )
Even following these guidelines, I can't get things to work consistently, and have been considering using morph targets until the library matures a bit more. The file sizes for morph targets are much larger but they seem to be a more reliable option at this point, in my experience.
After a lot of digging I finally found the answer in one of the three.js github discussions:
"Insert a full keyframe for all of the bones at the beginning and end of the animation. I found that without the first keyframe the animation would be subtly distorted, and without the one at the end I would lose parts of the animation toward the end."
Source: https://github.com/mrdoob/three.js/issues/2106
That was exactly what happened to our render. We only hat keyframes set for the bones that were changing and not for the static ones.
I've also found that to get the exported model working right the export should be done at frame 0 in Blender.
Another thing that solved a problem I've encountered was not to scale model after exporting it. This means that the model can't be scaled in the JSON file and probably in the code directly.
Using three.js r56

Resources