2

I made a model of a building with 3DS Max where each room is a modified cube, I used OBJMTLLoader to load the OBJ file with his own MTL. The problem is that I need to emphasize certain rooms according to the user requirements.

I use dat.gui to display a menu where the user can check/uncheck rooms to remark them (I think I will change the room size or marterial in order to emphasize it).

this is the code of my loader

var loader = new THREE.OBJMTLLoader();
        loader.load( 'models/ed.obj', 'models/textures/ed.mtl', 

        //onLoad()
        function ( object ){
            contenido = object;
            contenido.position.set(0,0,0);
            contenido.position.y = -80;
            contenido.name = 'edificio';

            scene.add(contenido);

            return contenido;
        } //and other onLoad, and onError stuff

I can play with the whole model, I have a transparency function that adjust transparency to a dat.gui bar (the one called opciones.Opacidad)

contenido.traverse( function( object ) {

                    if( object.material ) {

                        object.material.opacity = opciones.Opacidad;
                        object.material.transparent = true;
                    }

And it works correctly, but the probblem come when I try to access internal cubes of the geometry to remark them in wireframe (for example) I use:

contenido.getObjectByName("RoomNameIn3DSMax").material.wireframe=true;

In order to find and show it in wireframe, because the OBJ file names every module with its 3DS Max name. But it does not work, It looks like the item is found because I don't get any error, but it does not appear in wireframe, also when I use another room names, sometimes the program show in wireframe lots of things that can include the requested one or not, another ones it finds "undefined" I think it has something to be with the Groups created by the OBJMTLLoader.

I've also tried

        contenido.traverse( function ( child ) {
            if ( child.name == "NameInOBJor3DSMax" ) {
                child.material.wireframe = true;
            }
        })

But the result is the same.

So my question is, How can I access internal modules of my model loaded with OBJMTLLoader? As you can see I tried to use the "Object3D" methods to access the internal cubes of the whole model, am I doing it correctly? I can provide all the code and files if needed, you can see an approach of my problem here:

3DBuilding link You can also see all code there ;)

Thank you for your attention, I hope someone can help me.

EDIT: When I do:

 scene.getObjectByName("nameOfModule").material.color.set(0xff0000); 

To remark it on red or just: .material.wireframe=true; it shows remarked a lot of things that are not realted. It does the same when I use scene.getObjectById(ObjectId, true); But it does not show the name of the object in the DOM Tree.

I am trying to use another exporting tools to see if the problem is just the OBJ Exporter. It is something really annoying.

Here are some screens of the problem.

What I try to remark: What I try to tint

as you can see, it's only a edited box

what is remarked: What is tinted

If we go to the OBJ file we can see something like this:

#
  # object SDHAE001
#

v  106.4733 84.7697 -94.9228
... (more vertices)
v  106.3747 76.8453 -96.3784
# 16 vertices

vn 0.0000 1.0000 -0.0000
...(more normals)
vn -0.9991 0.0046 0.0425
# 14 vertex normals

#and here the group of faces fot that object ( Using triangles )
g SDHAE001
usemtl wire_115115115
f 10663//5549 10664//5549 10665//5549 
...(more triangle faces)
f 10676//5559 10663//5561 10678//5562 
# 22 faces

As you can see, 3DS Max is creating Groups of polygons for my geometry, and as far as I know, OBJMTL ignores "g" groups, so when I try to remark something, it remarks A LOT of things... Trying with other exporters... Parsing manually the OBJ file would be so annoying...

EDITED AGAIN

I've been exploring the options, and OBJ is generated ok by 3DS MAX, BUT when I explore de DOM Tree, I can see the THREE.Mesh as an array where only some of the the pair indexes have the expected object with his own name, and odd indexes have some sort of geometry I can't control without any name assigned, and for some strange reason, there are some groups of "vertices" created in geometry instance with no sense, I upload some screens and the OBJ/MTL files to make my problem clearer:

Look at this, I will try to remark now a module called "Conserjeria". and this is the module located in the DOM Tree:

Mesh located

Bigger image

Here, on the first column we can see, first problem, my OBJ (all the geometry) file only has about 298 Objects, so why are there 1056 Mesh Objects? It is not very relevant because most of them are with empty names.

Second problem, on the second column you can see geometry property for "Conserjeria" room, I think here is where the problem is generated... On the third column, I show you that strange "vertices" array for my "Conserjeria" object. I say strange, because it is composed by 6272 indexes... NOTHING in my OBJ file has 6272 vertices... You can see the OBJ here, and you can find Conserjeria if you want to see its structure (52v, 11vn, 80f). Might this be the reason why when I try to remark only certain objects it remarks a lot of them?

I've also tried with a simplified model of 3 boxes, 2 of them are correctly remarked, but the first one is not, have a look (use the checkboxes to remark them) I can't imagina why is this happening. (there are also 7 THREE.MESH index in the array when there are only 3 cubes in the scene...)

TestingCubes

Any help to remark only my rooms? I can share everything I have if needed(Code, OBJ, MTL, 3ds...)

Thank you to everyone who is trying to help me.

soiber
  • 172
  • 3
  • 14
  • I added information about my concrete problem, and "g" parsing is wrong in OBJMTLLoader (As so in OBJLoader). I also added the "vertices" problem for the Geometry of the Mesh. I hope someone can help me now... @AVGP – soiber Oct 16 '15 at 12:00
  • that is a seriously nice documented question! – FutureCake Sep 05 '16 at 15:22
  • Thank you, at least the problem was corrected by creating a new specific material for every module. Three,js parses the MTL and takes the objects with the same material as the same object, assigning them the same UUID identifier, no matter what the OBJ file says (OBJLoader returns a single Mesh losing reference to its children). – soiber Oct 02 '16 at 15:47

1 Answers1

1

Looks like you got a problem with the mesh names.

When I execute the following script, it's working just fine:

scene.children[2].traverse(function(c) {
  if(c.material && c.name.indexOf("INVESTIGACION_1_") >= 0) {
    c.material.color.set(0xff0000) 
  }
})

That tints part of the model red, as expected.

geekonaut
  • 5,714
  • 2
  • 28
  • 30
  • Thank you for your time. I tried your script, but the result is similar to the one I was having, it tints a lot of things more than the cube related to that name.. I will try to explain myself better with some images, look, this one is my "INVESTIGACION_1_" room: [link](http://imgur.com/0aRFlFk.png) As you can see, that one is the only cube to tint, but it tints all this [link](http://imgur.com/Dtsmn8u.png) And here, I can show you the name of one of that rooms tint, to prove that it is not called the same: [link](http://imgur.com/sH4EBIL.png) I REALLY appreciate your help. – soiber Sep 26 '15 at 15:40
  • hmm, that makes me wonder if the OBJ exporter from Blender is messing up the different groups – geekonaut Sep 27 '15 at 14:33
  • Thank you for your response, I use 3DS Max, I will try to improve my geometry and try another exporting options, I really, really appreciate your help, but if someone else can give me a solution I would be really pleased. So... I am not doing anything strange right? I am using the correct way to access my inner objects right? Once again, thank you very much for your time, this is an important project for me (my college Final Project) And I did not have any idea of Three.Js when I started using it, but it is really clear, so that I thought I was not accessing my inner objects in the right way. – soiber Sep 27 '15 at 15:30
  • It looks like there were some problems with Three during the parsing of OBJs from 3DS max, OBJMTLLoader is now deprecated. – soiber Feb 22 '16 at 20:50