model/ase: 3ds Max ASCII Scene Export read + write (geometry, Multi/Sub-Object materials, texture channels, colours, normals, NODE_TM hierarchy, helpers, cameras, lights; checked against assimp)
This commit is contained in:
1 parent
01c044805f
commit
0b6773db8b
12 files changed
+1814
-1
No files matched your search
@@ -0,0 +1,29 @@
|
||||
-- tools/fixtures/_ase_encode: run by tools/fixtures/ase.py (luau CLI, repo root): decodes every ASE case and writes it
|
||||
-- back with our ASE writer, printing "<file>\t<hex>" lines for assimp to read. Files: case_<i>.ase.
|
||||
local Ase = require("@rosetta/model/ase")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Cases = require("@tests/gen/ase_cases")
|
||||
|
||||
local HEX = {}
|
||||
for i = 0, 255 do
|
||||
HEX[i] = string.format("%02x", i)
|
||||
end
|
||||
local function hex(b: buffer): string
|
||||
local out = table.create(buffer.len(b))
|
||||
for i = 0, buffer.len(b) - 1 do
|
||||
out[i + 1] = HEX[buffer.readu8(b, i)]
|
||||
end
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
for i, c in Cases do
|
||||
local scene = Ase.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
if scene then
|
||||
local out, err = Ase.encode(scene)
|
||||
if out then
|
||||
print(string.format("case_%d.ase", i) .. "\t" .. hex(out))
|
||||
else
|
||||
print("encode failed " .. c.name .. ": " .. tostring(err))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,249 @@
|
||||
# ASE fixtures (tools/fixtures.py): assimp's ASE test models (test/models/ASE and test/models-nonbsd/ASE, read from the
|
||||
# nixpkgs assimp source, never committed) plus a hand-written file (Multi/Sub-Object material, a bitmap map with UVW
|
||||
# tiling, a second mapping channel, vertex colours, explicit normals, a helper parent, a camera, a light), with
|
||||
# reference values from assimp (`assimp info -r`: meshes, faces, vertices, cameras, lights; world bounds from its
|
||||
# PreTransformVertices export). Then our encoder's output (tools/fixtures/_ase_encode.luau) read back by assimp.
|
||||
# tests/gen/ase_cases.luau { name, data, assimp }
|
||||
# tests/gen/ase_xcheck.luau { name, case, assimp }
|
||||
import importlib.util, os
|
||||
|
||||
INPUTS = ["src/Rosetta/model/ase", "tools/fixtures/_model_ref.py", "tools/fixtures/fbx.py", "tools/fixtures/_ase_encode.luau"]
|
||||
|
||||
HAND = """*3DSMAX_ASCIIEXPORT\t200
|
||||
*COMMENT "hand-written for rosetta"
|
||||
*SCENE {
|
||||
\t*SCENE_FILENAME "hand.max"
|
||||
\t*SCENE_FIRSTFRAME 0
|
||||
\t*SCENE_LASTFRAME 50
|
||||
\t*SCENE_FRAMESPEED 25
|
||||
\t*SCENE_TICKSPERFRAME 192
|
||||
\t*SCENE_BACKGROUND_STATIC 0.1000\t0.2000\t0.3000
|
||||
\t*SCENE_AMBIENT_STATIC 0.0000\t0.0000\t0.0000
|
||||
}
|
||||
*MATERIAL_LIST {
|
||||
\t*MATERIAL_COUNT 1
|
||||
\t*MATERIAL 0 {
|
||||
\t\t*MATERIAL_NAME "Multi"
|
||||
\t\t*MATERIAL_CLASS "Multi/Sub-Object"
|
||||
\t\t*NUMSUBMTLS 2
|
||||
\t\t*SUBMATERIAL 0 {
|
||||
\t\t\t*MATERIAL_NAME "Brick"
|
||||
\t\t\t*MATERIAL_CLASS "Standard"
|
||||
\t\t\t*MATERIAL_AMBIENT 0.1000\t0.1000\t0.1000
|
||||
\t\t\t*MATERIAL_DIFFUSE 0.8000\t0.4000\t0.2000
|
||||
\t\t\t*MATERIAL_SPECULAR 0.9000\t0.9000\t0.9000
|
||||
\t\t\t*MATERIAL_SHINE 0.2500
|
||||
\t\t\t*MATERIAL_SHINESTRENGTH 0.5000
|
||||
\t\t\t*MATERIAL_TRANSPARENCY 0.0000
|
||||
\t\t\t*MATERIAL_SELFILLUM 0.0000
|
||||
\t\t\t*MAP_DIFFUSE {
|
||||
\t\t\t\t*MAP_NAME "BrickMap"
|
||||
\t\t\t\t*MAP_CLASS "Bitmap"
|
||||
\t\t\t\t*MAP_SUBNO 1
|
||||
\t\t\t\t*MAP_AMOUNT 1.0000
|
||||
\t\t\t\t*BITMAP "textures\\brick.png"
|
||||
\t\t\t\t*MAP_TYPE Screen
|
||||
\t\t\t\t*UVW_U_OFFSET 0.0000
|
||||
\t\t\t\t*UVW_V_OFFSET 0.0000
|
||||
\t\t\t\t*UVW_U_TILING 2.0000
|
||||
\t\t\t\t*UVW_V_TILING 3.0000
|
||||
\t\t\t\t*UVW_ANGLE 0.0000
|
||||
\t\t\t}
|
||||
\t\t}
|
||||
\t\t*SUBMATERIAL 1 {
|
||||
\t\t\t*MATERIAL_NAME "Glass"
|
||||
\t\t\t*MATERIAL_CLASS "Standard"
|
||||
\t\t\t*MATERIAL_AMBIENT 0.0000\t0.0000\t0.0000
|
||||
\t\t\t*MATERIAL_DIFFUSE 0.2000\t0.6000\t0.9000
|
||||
\t\t\t*MATERIAL_SPECULAR 1.0000\t1.0000\t1.0000
|
||||
\t\t\t*MATERIAL_SHINE 0.9000
|
||||
\t\t\t*MATERIAL_TRANSPARENCY 0.5000
|
||||
\t\t\t*MATERIAL_TWOSIDED
|
||||
\t\t}
|
||||
\t}
|
||||
}
|
||||
*HELPEROBJECT {
|
||||
\t*NODE_NAME "Pivot"
|
||||
\t*HELPER_CLASS "Dummy"
|
||||
\t*NODE_TM {
|
||||
\t\t*NODE_NAME "Pivot"
|
||||
\t\t*TM_ROW0 1.0000\t0.0000\t0.0000
|
||||
\t\t*TM_ROW1 0.0000\t1.0000\t0.0000
|
||||
\t\t*TM_ROW2 0.0000\t0.0000\t1.0000
|
||||
\t\t*TM_ROW3 10.0000\t0.0000\t0.0000
|
||||
\t}
|
||||
}
|
||||
*GEOMOBJECT {
|
||||
\t*NODE_NAME "Quad"
|
||||
\t*NODE_PARENT "Pivot"
|
||||
\t*NODE_TM {
|
||||
\t\t*NODE_NAME "Quad"
|
||||
\t\t*TM_ROW0 0.0000\t1.0000\t0.0000
|
||||
\t\t*TM_ROW1 -1.0000\t0.0000\t0.0000
|
||||
\t\t*TM_ROW2 0.0000\t0.0000\t1.0000
|
||||
\t\t*TM_ROW3 10.0000\t5.0000\t0.0000
|
||||
\t}
|
||||
\t*MESH {
|
||||
\t\t*TIMEVALUE 0
|
||||
\t\t*MESH_NUMVERTEX 4
|
||||
\t\t*MESH_NUMFACES 2
|
||||
\t\t*MESH_VERTEX_LIST {
|
||||
\t\t\t*MESH_VERTEX 0\t10.0000\t5.0000\t0.0000
|
||||
\t\t\t*MESH_VERTEX 1\t10.0000\t7.0000\t0.0000
|
||||
\t\t\t*MESH_VERTEX 2\t8.0000\t7.0000\t0.0000
|
||||
\t\t\t*MESH_VERTEX 3\t8.0000\t5.0000\t0.0000
|
||||
\t\t}
|
||||
\t\t*MESH_FACE_LIST {
|
||||
\t\t\t*MESH_FACE 0: A: 0 B: 1 C: 2 AB: 1 BC: 1 CA: 0\t*MESH_SMOOTHING 1\t*MESH_MTLID 0
|
||||
\t\t\t*MESH_FACE 1: A: 0 B: 2 C: 3 AB: 1 BC: 1 CA: 0\t*MESH_SMOOTHING \t*MESH_MTLID 1
|
||||
\t\t}
|
||||
\t\t*MESH_NUMTVERTEX 4
|
||||
\t\t*MESH_TVERTLIST {
|
||||
\t\t\t*MESH_TVERT 0\t0.0000\t0.0000\t0.0000
|
||||
\t\t\t*MESH_TVERT 1\t1.0000\t0.0000\t0.0000
|
||||
\t\t\t*MESH_TVERT 2\t1.0000\t1.0000\t0.0000
|
||||
\t\t\t*MESH_TVERT 3\t0.0000\t1.0000\t0.0000
|
||||
\t\t}
|
||||
\t\t*MESH_NUMTVFACES 2
|
||||
\t\t*MESH_TFACELIST {
|
||||
\t\t\t*MESH_TFACE 0\t0\t1\t2
|
||||
\t\t\t*MESH_TFACE 1\t0\t2\t3
|
||||
\t\t}
|
||||
\t\t*MESH_MAPPINGCHANNEL 2 {
|
||||
\t\t\t*MESH_NUMTVERTEX 1
|
||||
\t\t\t*MESH_TVERTLIST {
|
||||
\t\t\t\t*MESH_TVERT 0\t0.2500\t0.7500\t0.0000
|
||||
\t\t\t}
|
||||
\t\t\t*MESH_NUMTVFACES 2
|
||||
\t\t\t*MESH_TFACELIST {
|
||||
\t\t\t\t*MESH_TFACE 0\t0\t0\t0
|
||||
\t\t\t\t*MESH_TFACE 1\t0\t0\t0
|
||||
\t\t\t}
|
||||
\t\t}
|
||||
\t\t*MESH_NUMCVERTEX 2
|
||||
\t\t*MESH_CVERTLIST {
|
||||
\t\t\t*MESH_VERTCOL 0\t1.0000\t0.0000\t0.0000
|
||||
\t\t\t*MESH_VERTCOL 1\t0.0000\t1.0000\t0.0000
|
||||
\t\t}
|
||||
\t\t*MESH_NUMCVFACES 2
|
||||
\t\t*MESH_CFACELIST {
|
||||
\t\t\t*MESH_CFACE 0\t0\t1\t0
|
||||
\t\t\t*MESH_CFACE 1\t1\t1\t1
|
||||
\t\t}
|
||||
\t\t*MESH_NORMALS {
|
||||
\t\t\t*MESH_FACENORMAL 0\t0.0000\t0.0000\t1.0000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 0\t0.0000\t0.0000\t1.0000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 1\t0.0000\t0.0000\t1.0000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 2\t0.0000\t0.6000\t0.8000
|
||||
\t\t\t*MESH_FACENORMAL 1\t0.0000\t0.0000\t1.0000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 0\t0.0000\t0.0000\t1.0000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 2\t0.0000\t0.6000\t0.8000
|
||||
\t\t\t\t*MESH_VERTEXNORMAL 3\t0.0000\t0.0000\t1.0000
|
||||
\t\t}
|
||||
\t}
|
||||
\t*PROP_MOTIONBLUR 0
|
||||
\t*PROP_CASTSHADOW 1
|
||||
\t*PROP_RECVSHADOW 1
|
||||
\t*MATERIAL_REF 0
|
||||
}
|
||||
*CAMERAOBJECT {
|
||||
\t*NODE_NAME "Cam"
|
||||
\t*CAMERA_TYPE Free
|
||||
\t*NODE_TM {
|
||||
\t\t*NODE_NAME "Cam"
|
||||
\t\t*TM_ROW0 1.0000\t0.0000\t0.0000
|
||||
\t\t*TM_ROW1 0.0000\t0.0000\t1.0000
|
||||
\t\t*TM_ROW2 0.0000\t-1.0000\t0.0000
|
||||
\t\t*TM_ROW3 0.0000\t-50.0000\t10.0000
|
||||
\t}
|
||||
\t*CAMERA_SETTINGS {
|
||||
\t\t*TIMEVALUE 0
|
||||
\t\t*CAMERA_NEAR 1.0000
|
||||
\t\t*CAMERA_FAR 500.0000
|
||||
\t\t*CAMERA_FOV 0.7854
|
||||
\t\t*CAMERA_TDIST 50.0000
|
||||
\t}
|
||||
}
|
||||
*LIGHTOBJECT {
|
||||
\t*NODE_NAME "Spot"
|
||||
\t*LIGHT_TYPE Target
|
||||
\t*NODE_TM {
|
||||
\t\t*NODE_NAME "Spot"
|
||||
\t\t*TM_ROW0 1.0000\t0.0000\t0.0000
|
||||
\t\t*TM_ROW1 0.0000\t1.0000\t0.0000
|
||||
\t\t*TM_ROW2 0.0000\t0.0000\t1.0000
|
||||
\t\t*TM_ROW3 0.0000\t0.0000\t100.0000
|
||||
\t}
|
||||
\t*NODE_TM {
|
||||
\t\t*NODE_NAME "Spot.Target"
|
||||
\t\t*TM_ROW0 1.0000\t0.0000\t0.0000
|
||||
\t\t*TM_ROW1 0.0000\t1.0000\t0.0000
|
||||
\t\t*TM_ROW2 0.0000\t0.0000\t1.0000
|
||||
\t\t*TM_ROW3 0.0000\t0.0000\t0.0000
|
||||
\t}
|
||||
\t*LIGHT_SHADOWS Off
|
||||
\t*LIGHT_SETTINGS {
|
||||
\t\t*TIMEVALUE 0
|
||||
\t\t*LIGHT_COLOR 1.0000\t0.9000\t0.8000
|
||||
\t\t*LIGHT_INTENS 2.0000
|
||||
\t\t*LIGHT_HOTSPOT 30.0000
|
||||
\t\t*LIGHT_FALLOFF 60.0000
|
||||
\t}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def load(ctx, name):
|
||||
spec = importlib.util.spec_from_file_location("_" + name.replace(".", "_"), os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def reference(ctx, M, X, paths, tmp):
|
||||
out = []
|
||||
for p, a in zip(paths, M.assimp_info(ctx, paths, raw=True)):
|
||||
a.update(X.assimp_extra(ctx, p))
|
||||
for k in ("min", "max", "perMesh"):
|
||||
a.pop(k, None)
|
||||
if not a.get("failed"):
|
||||
a.update(X.ptv_bounds(ctx, p, tmp))
|
||||
out.append(a)
|
||||
return out
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
M = load(ctx, "_model_ref")
|
||||
X = load(ctx, "fbx")
|
||||
tmp = M.tempdir()
|
||||
src = X.assimp_src(ctx)
|
||||
cases = []
|
||||
for sub in ("models", "models-nonbsd"):
|
||||
d = os.path.join(src, "test", sub, "ASE")
|
||||
for root, _, files in sorted(os.walk(d)):
|
||||
for f in sorted(files):
|
||||
if f.lower().endswith((".ase", ".ask")) or f == "TestFormatDetection":
|
||||
p = os.path.join(root, f)
|
||||
cases.append({"name": "assimp/%s/%s" % (sub, os.path.relpath(p, d)), "path": p})
|
||||
hand = os.path.join(tmp, "hand.ase")
|
||||
with open(hand, "w") as fh:
|
||||
fh.write(HAND)
|
||||
cases.append({"name": "hand.ase", "path": hand})
|
||||
for c, a in zip(cases, reference(ctx, M, X, [c["path"] for c in cases], tmp)):
|
||||
c["assimp"] = a
|
||||
c["data"] = open(c["path"], "rb").read()
|
||||
del c["path"]
|
||||
ctx.emit("ase_cases", cases)
|
||||
|
||||
ours = M.luau_encode(ctx, "tools/fixtures/_ase_encode.luau")
|
||||
names = sorted((n for n in ours if n.endswith(".ase")), key=lambda n: int(n[5:-4]))
|
||||
paths = []
|
||||
for n in names:
|
||||
p = os.path.join(tmp, n)
|
||||
with open(p, "wb") as f:
|
||||
f.write(ours[n])
|
||||
paths.append(p)
|
||||
xs = []
|
||||
for n, a in zip(names, reference(ctx, M, X, paths, tmp)):
|
||||
xs.append({"name": n, "case": int(n[5:-4]), "assimp": a})
|
||||
ctx.emit("ase_xcheck", xs)
|
||||
@@ -0,0 +1,20 @@
|
||||
# Docs inputs for the engine / level-editor sections of the scene, tile map, archive and data pages (tools/fixtures.py,
|
||||
# tools/docs_check.py): the hand-written ASE of tools/fixtures/ase.py.
|
||||
# tests/gen/docs_engines.luau { files = { [name] = bytes }, vars = { aseText = "hand.ase", ... } }
|
||||
import importlib.util, os
|
||||
|
||||
INPUTS = ["tools/docs_check.py", "tools/fixtures/ase.py"]
|
||||
|
||||
|
||||
def mod(ctx, name):
|
||||
spec = importlib.util.spec_from_file_location("fx_" + name, os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
check = mod(ctx, "../docs_check")
|
||||
files = {"hand.ase": mod(ctx, "ase").HAND.encode()}
|
||||
vars = {"aseText": "hand.ase"}
|
||||
check.emit_inputs(ctx, files, vars)
|
||||
Reference in new issue
Block a user