Commit Graph

236 Commits

Author SHA1 Message Date
Pär Winzell 3f796dd90f
Use a tiny PNG for a fallback texture image, not a GIF (#74) 2018-02-23 19:39:08 -08:00
Pär Winzell f1982e6ca3 Bump NPM version. 2018-02-19 20:59:44 -08:00
Par Winzell da5d606c93 Documentation tweaks. 2018-02-19 20:15:01 -08:00
Par Winzell 608c6f1797 Add support for 32-bit indices.
This was way overdue. Breaking up large meshes into many 65535-vertex
primitives can save a few bytes, but it's really a lot of complication
for minor benefit.

With this change the user can force short or long indices, and the
default is to use shorts for smaller meshes and longs for longer.
2018-02-19 13:58:09 -08:00
Par Winzell 0deaf186a8 Some basic .gitignore stuff. 2018-02-19 09:32:25 -08:00
Par Winzell 7c0715c4ad Clean house in material extensions.
- KHR_materials_common never had a real life in the glTF 2.0 world. One
day we may see a new extension for Phong/Blinn/Lambert.
- PBR_specular_glossiness is a poor fit for PBS StingRay (the only real
source of PBR we have) and has no advantage over PBR_metallic_roughness.
- The conversion we were doing for traditional materials to PBR made no
sense. Revert to a very simple formula: diffuse -> baseColor, simple
reasonable constants for metallic & roughness.
2018-02-19 08:57:19 -08:00
Par Winzell 67bb9372d7 Optionally compute normals from geometry.
The user can now ask for normals to be computed NEVER (can easily cause
broken glTF if the source isn't perfect), MISSING (when the mesh simply
lacks normals), BROKEN (only emptuy normals are replaced), or
ALWAYS (perhaps if the normals in the source are junk).
2018-02-18 22:19:24 -08:00
Par Winzell b95c50a72f Code to repair normals. 2018-02-18 14:42:30 -08:00
Par Winzell 20b1bd7051 Semi-randomly tweak Phong->PBR conversion.
I stole expressions from Gary Hsu's PBR conversion routines here:

3606e79717/extensions/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows/js/three.pbrUtilities.js

which is experimental enough as it is, but I had gone further into the
domain of madness and uses this with *old* diffuse/specular values, not
PBR specular/glossness.

As a result a lot of old content was coming up with 100% metal values
quite often, which in turn means completely ignoring diffuse when
assembling a new base colour...

I should rip out this whole conversion. But not just now...
2018-02-04 14:42:57 -08:00
Par Winzell 54c3b04fce Cope with degenerate node T/R/S.
It's technically valid for e.g. scale to have a zero dimension, which in
turn wreaks havoc on the rotation quaternion we get from the FBX SDK.

The simplest solution is to just leave any T/R/S vector out of the glTF
if it has any NaN component.
2018-02-02 11:12:06 -08:00
Par Winzell a3989249f3 Consistent naming of unlit extension use. 2018-02-02 07:08:00 -08:00
Par Winzell 8ab9459d6a Don't override encoder's best guess. 2018-02-02 06:58:47 -08:00
Par Winzell cbd2e3f00d Use newer Draco. 2018-02-02 06:58:17 -08:00
Robert Long 74479426a7 KHR_materials_unlit (#61)
KHR_materials_unlit support.
2018-02-02 06:57:36 -08:00
Par Winzell 41f8a5ef03 Improvements in texture merging.
Be more flexible about reading various input formats (most especially
varying numbers of channels), and stop outputting RGBA PNGs for textures
that don't need it.

I'm not sure JPG generation ever worked right. But now it does.
2017-12-22 16:02:48 -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
Pär Winzell 13367dfc66
Merge pull request #50 from msfeldstein/master
Pass camera reference through propertly as index uints, not as (glTF 1.0 era) name strings.
2017-12-04 22:18:49 -08:00
Mike Feldstein 9d1096f3ff Properly pass camera data through 2017-12-04 14:35:57 -08:00
Pär Winzell cc0a6e5b89
Merge pull request #48 from davilovick/fix_normal_issues 2017-12-03 11:58:09 -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 a9c4fb1bd0 Fix for Windows. (And generally a good idea.) 2017-11-30 23:15:13 -08:00
Par Winzell 21305baa93 NPM-publish of patch release 0.9.3. 2017-11-30 23:02:22 -08: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
Pär Winzell f61814f7c9
Pin Draco at 1.2.0, for now
As @robertlong discovered, there are compilation errors in newer Draco patch releases under Win/VS 2017.
2017-11-21 19:10:45 -08:00
Par Winzell 423458a841 Construct JSON with explicit key order.
We are at liberty to order our JSON any way we like (by spec) and we can
improve readability a lot by doing so. By default, this JSON library
uses an unordered map for objects, but it's relatively easy to switch in
a FiFo map that keeps track of the insertion order.
2017-11-17 11:37:19 -08:00
Par Winzell c70ded31d5 Explicit versions of dependencies.
As we approach 1.0.0 we can't just download whatever someone's slammed
into the master branch of our various open source dependencies.
2017-11-16 18:19:52 -08:00
Par Winzell bcbfdae6be Drop misleading warning.
It's perfectly fine for materials to have neither diffuse texture nor
vertex colours. This dates back to a time when the tool had more limited
use cases.

To compensate: https://github.com/facebookincubator/FBX2glTF/issues/43
2017-11-16 14:10:30 -08:00
Pär Winzell 5eb36702b5
Make blend shape normals/tangents opt-in. (#40)
The FBX SDK absolutely claims that there is a normal layer to each
FbxShape, with non-trivial data, even when the corresponding FBX file,
upon visual inspection, explicitly contains nothing but zeroes. The only
conclusion I can draw is that the SDK is computing normals from
geometry, without being asked to, which seems kind of sketchy.

These computed normals are often not at all what the artist wanted, they
take up a lot of space -- often pointlessly, since if they're computed,
we could just as well compute them on the client -- and at least in the
case of three.js their inclusion uses up many of the precious 8 morph
target slots in the shader.

So, they are now opt-in, at least until we can solve the mystery of just
what goes on under the hood in the SDK.
2017-11-14 14:36:44 -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
Pär Winzell 7f8746f56e
Minor README tweaks. 2017-11-09 20:15:00 -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
Par Winzell 3b7872f4f1 NPM-publish of patch release 0.9.2. 2017-11-06 13:26:12 -08:00
Par Winzell d2a20ee5cb Fixes for Linux/GCC.
Between Linux, Darwin and Windows keeping me honest, I am slowly learning C++.
2017-11-06 12:20:15 -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 0fcd00cb5b Get rid of some pointless copying. 2017-10-31 20:18:14 -07:00
Pär Winzell 21138b6eff
Merge pull request #30 from facebookincubator/check-for-exe
Use .exe suffix on Windows.
2017-10-31 11:49:10 -07:00
Michael Bayne 7f9aa3318a Use .exe suffix on Windows. 2017-10-31 11:33:32 -07:00
Par Winzell 58518f5e00 Tiny log string fix. 2017-10-29 00:34:20 -07:00