[x3d-public] Specification review progress: PNG3, Tangent node, HAnim weekly progress
John Carlson
yottzumm at gmail.com
Wed Jul 9 20:00:41 PDT 2025
Looking the blender code, link in enclosure, it appears that the 'tangent'
is something in self.blender_mesh.loops, probably filled in other places in
the glTF export code...Hmm! But I've lost the track from there.
Apparently, I need to study the numpy python package some.
John
def __get_tangents(self):
"""Get an array of the tangent for each loop."""
self.tangents = np.empty(len(self.blender_mesh.loops) * 3,
dtype=np.float32)
self.blender_mesh.loops.foreach_get('tangent', self.tangents)
self.tangents = self.tangents.reshape(len(self.blender_mesh.loops),
3)
self.tangents = np.round(self.tangents, ROUNDING_DIGIT)
On Wed, Jul 9, 2025 at 11:40 AM John Carlson <yottzumm at gmail.com> wrote:
> From Don McCurdy @ Khronos Discord:
>
> Computed with `mesh.calc_tangents`:
>
> https://docs.blender.org/api/current/bpy.types.Mesh.html#bpy.types.Mesh.calc_tangents
> and then accessed here i think:
>
> https://github.com/KhronosGroup/glTF-Blender-IO/blob/ed5100ab6c40472b7c3254fddfe0dd0d76d60644/addons/io_scene_gltf2/blender/exp/primitive_extract.py#L1512-L1517
>
> Looks like this is export. I’m not sure about import.
>
> Anyone is welcome to have at it. I don’t have a Tangent 3D model yet.
>
> John
>
>
> On Wed, Jul 9, 2025 at 11:16 AM Michalis Kamburelis <
> michalis.kambi at gmail.com> wrote:
>
>> Indeed, taking a look at Blender -> glTF exporter should be helpful.
>> It can already generate the 4D tangent vectors in the same format we
>> now accept in X3D (with the W component indicating "handedness" in the
>> same way for X3D and glTF). Note that you need to select a proper
>> checkbox when exporting glTF to have tangents written to the file.
>>
>> From my side, Tangent development:
>>
>> - Announced right now on
>>
>> https://castle-engine.io/wp/2025/07/09/support-for-new-tangent-node-in-x3d-with-vectors-as-4d-better-aligned-with-gltf/
>>
>> - Castle Game Engine now follows the X3D Tangent spec, with MFVec4f
>> for vectors just like for glTF. (hooray, another win for standards --
>> glTF, X3D in X_ITE, X3D in Castle Game Engine are now all aligned.)
>>
>> - Our tools, like Castle Model Viewer, convert glTF to X3D, preserving
>> tangent information from glTF into X3D Tangent node. (e.g. convert
>> models with tangents generated by Blender or downloaded from Sketchfab
>> or obtained from Khronos tests)
>>
>> - In effect we have some sample X3D files using Tangent node :
>> https://github.com/castle-engine/demo-models/tree/master/gltf/tangents
>> . These were obtained by converting some glTFs from Sketchfab
>> (Creative Commons licenses) -> X3D using CGE, see README there for
>> details.
>>
>> - I also tested our implementation on Khronos testcase
>>
>> https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/NormalTangentMirrorTest
>>
>> Regards,
>> Michalis
>>
>>
>> niedz., 6 lip 2025 o 07:29 John Carlson <yottzumm at gmail.com> napisał(a):
>> >
>> > Now….
>> >
>> > How do we import/export a Tangent node in Blender? Can we create a
>> .blend file example for it so I can try exporting, then importing? What
>> are the Blender API data structures and methods?
>> >
>> > I will probably look at glTF examples and intuit.
>> >
>> > John
>> >
>> > On Sat, Jul 5, 2025 at 8:23 AM Michalis Kamburelis <
>> michalis.kambi at gmail.com> wrote:
>> >>
>> >> John,
>> >>
>> >> Thank you, it's cool, every precise question helps me to explain it
>> better :)
>> >>
>> >> To answer that:
>> >>
>> >> The tangent vectors (i.e., Tangent node contents) only change the way
>> >> "final normal vector at given surface point" (designated by N in the
>> >> lighting equations) is calculated. That's how they influence the
>> >> calculation done by lighting equations, and thus the final rendered
>> >> color. They do not interact with colors or geometry in any other way.
>> >>
>> >> And the way they change this N is that tangent vectors (together with
>> >> bitangent and per-face/per-vertex normals) define the "tangent space"
>> >> in which the bump mapping (which is the moment where we take
>> >> XxxMaterial.normalTexture into account) is calculated.
>> >>
>> >> There are some resources on the web explaining this, like:
>> >> - https://fabiensanglard.net/bumpMapping/
>> >> - Wikipedia: https://en.wikipedia.org/wiki/Bump_mapping ,
>> >> https://en.wikipedia.org/wiki/Normal_mapping
>> >> - hm, ok, and much more, searching for terms like "bump mappping" or
>> >> "normal mapping" or "bump mapping 3d opengl" yields a lot of results
>> >> :)
>> >>
>> >> ( One needs some disclaimer when reading them though:
>> >>
>> >> - There are various ways to define/deal with "handedness" of the
>> >> coordinate system. X3D spec and glTF spec match in how they handle it,
>> >> so the world 3D coordinate space is right-handed, and the "tangent
>> >> space" handedness is determined by the W component of 4D tangents.
>> >> Various articles on the web don't deal with this detail, or they deal
>> >> with it differently.
>> >>
>> >> - The terminology distinction "bump mapping" vs "normal mapping" is
>> >> honored/ignored differently in articles. (Admittedly, in my own
>> >> writing sometimes too :) ) To be precise, "bump mapping" is more
>> >> general idea, and "normal mapping" is a special case of it (when you
>> >> do it using normal maps), and "normal mapping in tangent space" is
>> >> even more special case of it. But...various resources simplify these
>> >> things, because in practice "normal mapping in tangent space" is the
>> >> most common way to do bump mapping in real-time 3D graphics (now).
>> >> )
>> >>
>> >> I hope any of this helps you and Don and anyone else to make sense of
>> >> it :) Feel free to incorporate any of this in spec prose.
>> >>
>> >> Regards,
>> >> Michalis
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20250709/f978973f/attachment.html>
More information about the x3d-public
mailing list