Commit Graph

37 Commits

Author SHA1 Message Date
Pär Winzell 7995f7b341 Resolve _WIN32 isnan() fiasco completely. 2018-05-27 13:28:49 -07:00
Par Winzell f530af8bf4 Use std:: whenever possible. 2018-05-03 08:21:42 -07:00
Par Winzell 68983ad0d0 Fix skinning edge case.
A mesh with a single (skinning) deformer which had zero clusters would
erroneously register as skinned, leading GetRoodNode() to an assertion
failure. Fixed.
2018-04-08 17:54:42 -07:00
Par Winzell 9174fe2f50 Fixes and improvements to shininess -> roughness. 2018-03-29 05:49:40 -07:00
Par Winzell 3f1590a26b Don't be tricksy if we're already done.
The FBX SDK looks for our textures and often finds them. It helpfully
tells us exactly where they are. Let's not throw that information away
and demand that the textures only exist in precisely the folders we are
aware of.
2018-03-27 20:00:48 -07:00
Par Winzell ca12a38afe Always eliminate the 0.01 factor. 2018-03-27 14:54:36 -07:00
PLAINCONCEPTS\davila 4ec8c8e34d Change the way that unit conversion affects the scene. 2018-03-27 14:17:33 -07:00
Pär Winzell a984f7bf37
Drop the Gltf:: namespace prefix. (#77) 2018-02-25 17:19:19 -08:00
Par Winzell b95c50a72f Code to repair normals. 2018-02-18 14:42:30 -08:00
David Ávila a2d5c7d87b Fix duplicate name issues (#51)
Fix the naming issues. Now the nodes are identified by pNode->GetUniqueID(), instead of its name. All dictionaries and references to nodes are replaced by its id, instead of its name.
2017-12-06 10:43:18 -08:00
David Ávila Membrives 1a46ccf7ff Include meshScaling in normal transform 2017-12-03 20:47:41 +01:00
David Ávila Membrives 9c2e485cfc Apply the correct transform on normals (remove transform & scaling components) 2017-12-03 15:32:53 +01:00
Pär Winzell fdf7bb3336 Support for Stingray PBS material definitions (#47)
This adds the first FBX PBR import path. Materials that have been
exported via the Stingray PBS preset should be picked up as native
metallic/roughness, and exported essentially 1:1 to the glTF output.

In more detail, this commit:
- (Re)introduces the STB header libraries as a dependency. We currently
use it for reading and writing images. In time we may need a more
dedicated PNG compression library.
- Generalizes FbxMaterialAccess to return different subclasses of
  FbxMaterialInfo; currently FbxRoughMetMaterialInfo and
  FbxTraditionalMaterialInfo.
  - FbxTraditionalMaterialInfo is populated from the canonical
    FbxSurfaceMaterial classes.
  - FbxRoughMetMaterialInfo is currently populated through the Stingray
    PBS set of properties, further documented in the code.
- RawMaterial was in turn generalized to feature a pluggable,
  type-specific RawMatProps struct; current implementations are,
  unsurprisingly, RawTraditionalMatProps and RawMetRoughMatProps. These
  are basically just lists of per-surface constants, e.g. diffuseFactor or
  roughness.
- In the third phase, glTF generation, the bulk of the changes are
  concerned with creating packed textures of the type needed by e.g. the
  metallic-roughness struct, where one colour channel holds roughness and
  the other metallic. This is done with a somewhat pluggable "map source
  pixels to destination pixel" mechanism. More work will likely be needed
  here in the future to accomodate more demanding mappings.

There's also a lot of code to convert from one representation to
another. The most useful, but also the least well-supported conversion,
is from old workflow (diffuse, specular, shininess) to
metallic/roughness. Going from PBR spec/gloss to PBR met/rough is hard
enough, but we go one step sillier and treat shininess as if it were
glossiness, which it certainly isn't. More work is needed here! But it's
still a fun proof of concept of sorts, and perhaps for some people it's
useful to just get *something* into the PBR world.
2017-11-30 22:23:50 -08:00
Par Winzell e2e0d741a2 Style tweaks. 2017-11-28 01:22:43 -08:00
David Ávila fada9e45ee Modify FBX2glTF to allow that several nodes share the same mesh. (#46) 2017-11-28 01:16:01 -08:00
Par Winzell e73c2f46e2 Only use vertex alpha if color layer is present.
This was previously flagging far too many materials as transparent.
2017-11-14 13:47:34 -08:00
Par Winzell 412b98b9ab Cope with animation edge case, don't NPE. 2017-11-08 11:25:55 -08:00
Par Winzell 145f0d84a1 Minor normal/tangent cleanup. 2017-11-07 13:59:13 -08:00
Pär Winzell 3eeebf4599
Blendshape tangets & normals, cleanup. (#35)
Turns out Maya was always including normals in the FBX export, they were just a bit trickier to get to than originally surmised. We need to go through the proper element access formalities that takes mapping and reference modes into account.

Luckily we already have a helper class for this, so let's lean on that.
2017-11-07 13:32:54 -08:00
Pär Winzell 5786fc9f0b One more dynamic_cast to drop. 2017-11-06 23:14:35 -08:00
Par Winzell 4f8ddffdf7 Better calculation of glTF opacity.
At the glTF level, transparency is a scalar; we just throw away any
color information in FBX TransparentColor. We still need to calculate
our total opacity from it, however. This is the right formula, which
additionally matches the deprecated (but still populated, by the Maya
exporter) 'Opacity' property.
2017-11-06 14:48:16 -08:00
Pär Winzell 5eb3779ad8 Don't use dynamic_cast, it needs RTTI. 2017-11-06 00:17:39 -08:00
Pär Winzell 60f18ae635 Diffuse texture transparency takes priority.
If the diffuse texture is opaque, it doesn't matter if a couple of
vertexes are semi-transparent.
2017-11-05 23:09:59 -08:00
Pär Winzell 7ecc6e5743 Fix build on Windows.
No vectors of const objects. Got it. Makes sense.
2017-11-05 23:08:32 -08:00
Pär Winzell 9ae36088b4
Blend Shape / Morph Target Support (#33)
This adds blend shape / morph target functionality.

At the FBX level, a mesh can have a number of deformers associated with it. One such deformer type is the blend shape. A blend shape is a collection of channels, which do all the work. A channel can consist of a single target shape (the simple case) or multiple (a progressive morph). In the latter case, the artist has created in-between shapes, the assumption being that linear interpolation between a beginning shape and an end shape would be too crude. Each such target shape contains a complete set of new positions for each vertex of the deformed base mesh.

(It's also supposed to be optionally a complete set of normals and tangents, but I've yet to see that work right; they always come through as zeroes. This is something to investigate in the future.)

So the number of glTF morph targets in a mesh is the total number of FBX target shapes associated with channels associated with blend shape deformers associated with that mesh! Yikes.

The per-vertex data of each such target shape is added to a vector in RawVertex. A side effect of this is that vertices that participate in blend shapes must be made unique to the mesh in question, as opposed to general vertices which are shared across multiple surfaces.

Blend Shape based animations become identical glTF morph target animations..

Fixes #17.
2017-11-05 00:06:24 -07:00
Pär Winzell 5e0f05261c
Sort triangles with vertex transparency separately. (#32)
Lean on the excellent pre-existing support for creating multiple glTF
meshes from a single FBX mesh based on material type. All the triangles
with (at least one) non-opaque vertex get flagged as transparent
material. They will all go separately in their own mesh after the
CreateMaterialModels() gauntlet.

Fixes #25.
2017-11-04 20:10:28 -07:00
Par Winzell 14150269a0 Switch FbxDouble4 uses to FbxVector4, clean up. 2017-11-03 21:48:41 -07:00
Par Winzell 075dc4a8c3 Fix and improve inheritance warnings.
We were warnings against eInheritRSrs, which is actually the one type of
ineritance we're good with. It's eInheritRrSs we should freak out about.

That said, no need to do it for the root node -- at that point there is
no global transform to worry about.
2017-10-27 15:47:49 -07:00
Par Winzell db3f232fc9 Cope with geometry opting out of geometry.
Some FBX files have index arrays that contain -1 (indeed, that are
nothing but negative ones). Presumably the intention is to specify "no
material". In any case, let's not segfault.
2017-10-24 20:57:55 -07:00
Par Winzell 5580dcfa92 Whitespace tweaks in log output. 2017-10-23 18:59:32 -07:00
Pär Winzell 8cf7f446b7 Further improvemens to texture resolution. (#16)
* Further improvemens to texture resolution.

- Move towards std::string over char * and FbxString where convenient,
- Make a clear distinction between textures whose image files have been
  located and those who haven't; warn early in the latter case.
- Extend RawTexture so we always know logical name in FBX, original file
  name in FBX, and inferred location in local filesystem.
- In non-binary mode, simply output the inferred local file basename as
  the URI; this will be the correct relative path as long as the texture
  files are located next to the .gltf and .bin files.

Primary remaining urge for a follow-up PR:

- We should be copying texture image files into the .gltf output folder,
  but before that we should switch to an off-the-shelf cross-platform
  file manipulation library like https://github.com/cginternals/cppfs.
  When we make that transition, all this texture resolution code will
  undergo another refactoring.
2017-10-20 09:42:39 -07:00
Par Winzell bc803213fc Delete obsolete snippets. 2017-10-17 21:19:36 -07:00
Par Winzell bf28c29f50 Multiple fixes for transparency.
- alphaMode is only BLEND for transparent materials.
- We use RawMaterial.type to figure out what's transparent.
- FBX TransparencyFactor is not opacity, but 1.0-opacity.
- Treat vertex coloured materials as transparent
  - We should at least iterate over vertices here and see if any of them
    actually are transparent
- Sort triangles properly: transparent ones render last!
2017-10-17 21:14:52 -07:00
Par Winzell b44d3b19a8 Fix build across all platforms. 2017-10-17 17:56:21 -07:00
Par Winzell f2a057d783 Do a better job resolving texture files.
- Nix GetFileFolder(). It was not helping. Always search for textures
- near the FBX file.
- Use RawTexture::name for the texture name and ::fileName for the
  inferred local filename path.
2017-10-16 23:31:19 -07:00
Par Winzell e9067850e1 Break out material property & texture code.
Digging the property values and texture shadows thereof, associated with
a certain FbxSurfaceTexture, should clearly happen once per material,
not per polygon. Furthermore there is a pre-existing pattern of
Fbx-specific accessclasses in Fbx2Raw that we should follow.

Soon we'll be extracting more than Phong/Lambert properties here, and
then we'll need to do further refactoring.
2017-10-16 23:12:57 -07:00
Par Winzell 276a0dfb86 Initial commit. 2017-10-13 01:55:11 -07:00