Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.6

0.11.6 / src / fbx_nodes.luc

## FBX in the node graph (luce-fbx): the File node reading .fbx with its FBX
## rows (node_catalog.fbx_fields), and the Export node writing .fbx.
from luce_std import math
from luce_fbx.fbx import Fbx
from geometry_data import GeometryData
from usd_nodes import summary

## Whether `path` names an FBX file.
pub func is_fbx_path(path: str) -> bool:
    return path.trim().lower().ends_with(".fbx")

## A File node's FBX file at the options its FBX rows hold (value slots 1-7):
## 1 import (0 merge into one mesh, 1 keep hierarchy), 2 instancing,
## 3 convert to Y-up meters, 4 import normals, 5 set frame, 6 the frame
## (at the file's frame rate), 7 deform (blend shapes and skins).
pub func load_fbx(path: str, values: list[float]) -> GeometryData!:
    let frame = values[6] if values[5] != 0.0 else math.nan
    let geometry = Fbx.load(path, keep_hierarchy = values[1] == 1.0, instancing = values[2] != 0.0, convert_units = values[3] != 0.0, normals = values[4] != 0.0,
                            frame = frame, deform = values[7] != 0.0)
    let data = GeometryData(geometry = geometry)
    data.warning = summary(Fbx.warnings())
    return data

## The Export node's cook for a .fbx path: write `data` as binary FBX 7.4
## (meshes by path, instances, curves, materials; docs/MODELING.md) and
## pass it on, with what the writer left out as the warning.
pub func export_fbx(path: str, data: GeometryData) -> GeometryData!:
    Fbx.save(data.geometry, path)
    let warning = summary(Fbx.warnings())
    return data.passed(warning) if warning != "" else data