Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColladaLoader doesn't set doubleSided #2280

Closed
jterrace opened this issue Aug 3, 2012 · 14 comments
Closed

ColladaLoader doesn't set doubleSided #2280

jterrace opened this issue Aug 3, 2012 · 14 comments

Comments

@jterrace
Copy link
Contributor

jterrace commented Aug 3, 2012

Many exporters put a double-sided flag in an effect's <extra> area to indicate that back faces should be rendered. As an example from Google SketchUp:

<effect id="material_3_4_0-effect" name="material_3_4_0-effect">
   <profile_COMMON>
      ...
      <extra>
         <technique profile="GOOGLEEARTH">
            <double_sided>1</double_sided>
         </technique>
      </extra>
   </profile_COMMON>
</effect>

It should be checked for .//extra//double_sided in an effect because different exporters put it under different techniques, but it's always called "double_sided".

It can also be put on a geometry, not on a material. I'm not sure if three.js supports setting doubleSided on a geometry instead of a material? Anyway, here's an example of that:

<geometry id="Cube_001-mesh" name="Cube.001">
    <mesh>
        ...
    </mesh>
    <extra>
        <technique profile="MAYA">
            <double_sided>1</double_sided>
        </technique>
    </extra>
</geometry>

If there's no way to set it on a geometry, a workaround could be to make a copy of the material and set the doubleSided flag for geometries that specify it.

@alteredq
Copy link
Contributor

alteredq commented Aug 3, 2012

We have doubleSided as object property though I'm getting more and more convinced this is wrong and it should be actually a material property.

Common trouble with doubleSided being an object property is when you have models that have parts done as single sheets of triangles - pieces of fabric flapping around or hairs or nozzle effects.

With doubleSided being material property, only these parts could be like this instead of the whole model being forced to be double sided (doubleSided rendering is more expensive, so less of it the better).

Downside would be a bit more GL state setting for multimaterial objects, though this is unlikely to have a big effect on performance (we change GL state only when needed).

@jterrace
Copy link
Contributor Author

jterrace commented Aug 3, 2012

Oh, I guess I had it backwards then - I thought doubleSided was a property of MeshBasicMaterial, etc. In that case, if it's found in <geometry>, it can just be set. If it's found in the material, it could just be checked and copied when applying the material to the mesh in the loader.

@alteredq
Copy link
Contributor

alteredq commented Aug 3, 2012

Currently it's in Object3D not in Geometry.

@jterrace
Copy link
Contributor Author

jterrace commented Aug 3, 2012

Yeah, sorry, I meant geometry in collada terms. Anyway, I will submit a patch for this if I get some free time.

@mrdoob
Copy link
Owner

mrdoob commented Aug 3, 2012

We have doubleSided as object property though I'm getting more and more convinced this is wrong and it should be actually a material property.

Yeah, I've been thinking about that too. We should move it to material.

Yeah, sorry, I meant geometry in collada terms. Anyway, I will submit a patch for this if I get some free time.

That'd be great!

@alteredq
Copy link
Contributor

alteredq commented Aug 3, 2012

Yeah, I've been thinking about that too. We should move it to material.

Ok, I'll try to do WebGL part.

@alteredq
Copy link
Contributor

alteredq commented Aug 3, 2012

Ok, WebGL part done:

alteredq@b838b38

I realized picking may be now tricker though, it would need to be aware of materials :S

BTW I also started this wiki page about diffs between lib versions relevant for migration, something we already spoke about:

https://github.com/mrdoob/three.js/wiki/Migration

The idea is that we just put a note there when we do some API breaking changes, at the moment we do the breakage.

@mrdoob
Copy link
Owner

mrdoob commented Aug 3, 2012

I realized picking may be now tricker though, it would need to be aware of materials :S

Ah... true. Oh well...

BTW I also started this wiki page about diffs between lib versions relevant for migration, something we already spoke about:

https://github.com/mrdoob/three.js/wiki/Migration

The idea is that we just put a note there when we do some API breaking changes, at the moment we do the breakage.

Great! I'll be filling it up too.

@mrdoob
Copy link
Owner

mrdoob commented Aug 3, 2012

Cool, also done changing it on Projector. 0360459

@jterrace
Copy link
Contributor Author

jterrace commented Aug 3, 2012

Instead of patching ColladaLoader to work with the current Object3D-based doubleSided, should I just wait and make the patch off the new Material-based doubleSided?

@mrdoob
Copy link
Owner

mrdoob commented Aug 3, 2012

Uhm, we have just changed it. They now sit in the material.

jterrace added a commit to jterrace/three.js that referenced this issue Aug 4, 2012
…tra>, applying it to the Material. This is half of Issue mrdoob#2280.
@jterrace
Copy link
Contributor Author

jterrace commented Aug 4, 2012

The above commit (3fd4f8e) adds doubleSided to the material if found. I'm not sure the best way to support double_sided on <geometry> instead. I guess when creating a THREE.Mesh, it would have to make a copy of the Material, setting the flag. It should probably cache the copies it makes so that if multiple geometries use the same material, it won't create more than 1 copy. Kind of messy, but is there an easier way?

@alteredq
Copy link
Contributor

alteredq commented Aug 5, 2012

Kind of messy, but is there an easier way?

Not really, as sidedness is now a material property, if two different objects share the same material but have different sidedness, they'll need to have two different materials (though even before internally there would have been two shader programs thanks to double sided lighting).

@jterrace
Copy link
Contributor Author

jterrace commented Aug 7, 2012

Now that clone on Material objects works, I took a stab at supporting the double_sided flag inside of <geometry>. 35839b8 should do it. I tested with a couple of test files and it looks to be working well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants