cell update

This commit is contained in:
2026-01-06 20:30:30 -06:00
parent 8237dca8ea
commit 034fd8b96e
2 changed files with 24 additions and 26 deletions

23
gltf.cm
View File

@@ -2,10 +2,9 @@ var gltf = this
var native_decode = gltf.decode
var fd = use('fd')
var utf8 = use('utf8')
var blob = use('blob')
var http = use('http')
var text = use('internal/text')
var json = use('json')
var png = use('cell-image/png')
var jpg = use('cell-image/jpg')
@@ -109,7 +108,7 @@ function parse_glb(glb_blob) {
var json_to = (20 + json_len) * 8
var json_blob = glb_blob.read_blob(json_from, json_to)
stone(json_blob)
var json_obj = json.decode(utf8.decode(json_blob))
var json_obj = json.decode(text(json_blob))
var offset = 20 + json_len
if (offset + 8 > total_len) return { json: json_obj, bin: null }
@@ -128,7 +127,7 @@ function parse_glb(glb_blob) {
function make_glb_from_json_and_bin(doc, bin_blob) {
var json_text = json.encode(doc, null, 0)
var json_blob = utf8.encode(json_text)
var json_blob = new blob(json_text)
var json_bytes = json_blob.length / 8
var bin_bytes = bin_blob.length / 8
@@ -136,7 +135,7 @@ function make_glb_from_json_and_bin(doc, bin_blob) {
var json_pad = (4 - (json_bytes % 4)) % 4
var bin_pad = (4 - (bin_bytes % 4)) % 4
var json_pad_blob = utf8.encode(spaces(json_pad))
var json_pad_blob = new blob(spaces(json_pad))
var bin_pad_blob = zeros_blob(bin_pad)
var json_chunk_len = json_bytes + json_pad
@@ -196,7 +195,7 @@ gltf.decode = function(input, opts) {
var uri_loader = opts.uri_loader
if (uri_loader == null) uri_loader = load_uri_default
if (typeof input == 'string') {
if (is_text(input)) {
var path = input
if (ends_with(path, ".gltf")) {
var gltf_blob = fd.slurp(path)
@@ -298,7 +297,7 @@ function used_image_indices(asset) {
var textures = asset.textures || []
for (var k in used_tex) {
var ti = parseInt(k)
var ti = number(k)
var t = textures[ti]
if (!t) continue
if (t.image == null) continue
@@ -446,9 +445,9 @@ function premultiply_rgba(pixels_blob) {
var g = pixels_blob.read_fit((i + 1) * 8, 8)
var b = pixels_blob.read_fit((i + 2) * 8, 8)
var a = pixels_blob.read_fit((i + 3) * 8, 8)
var rr = Math.floor((r * a) / 255)
var gg = Math.floor((g * a) / 255)
var bb = Math.floor((b * a) / 255)
var rr = number.floor((r * a) / 255)
var gg = number.floor((g * a) / 255)
var bb = number.floor((b * a) / 255)
out.write_fit(rr, 8)
out.write_fit(gg, 8)
out.write_fit(bb, 8)
@@ -578,10 +577,10 @@ gltf.stats = function(asset) {
if (p.topology != "triangles") continue
if (p.indices != null) {
var acc = asset.accessors[p.indices]
if (acc) stats.triangles += Math.floor((acc.count || 0) / 3)
if (acc) stats.triangles += number.floor((acc.count || 0) / 3)
} else if (p.attributes && p.attributes.POSITION != null) {
var acc = asset.accessors[p.attributes.POSITION]
if (acc) stats.triangles += Math.floor((acc.count || 0) / 3)
if (acc) stats.triangles += number.floor((acc.count || 0) / 3)
}
}
}

View File

@@ -6,7 +6,7 @@ var fs = use('cellfs')
if (args.length < 1) {
log.console("Usage: cell run tests/readout.ce <model_file>")
log.console("Supported formats: .gltf, .glb, .obj, .fbx")
$_.stop()
$stop()
}
var filepath = args[0]
@@ -16,7 +16,7 @@ var ext = dot >= 0 ? filepath.slice(dot).toLowerCase() : ''
var data = fs.slurp(filepath)
if (!data) {
log.console(`Error: Could not read file: ${filepath}`)
$_.stop()
$stop()
}
var model = null
@@ -29,7 +29,7 @@ if (ext == '.gltf' || ext == '.glb') {
} else {
log.console(`Error: Unsupported file format: ${ext}`)
log.console("Supported formats: .gltf, .glb, .obj, .fbx")
$_.stop()
$stop()
}
def print_array = function(arr, indent) {
@@ -39,7 +39,7 @@ def print_array = function(arr, indent) {
}
for (var i = 0; i < arr.length; i++) {
var item = arr[i]
if (typeof item == 'object' && item != null) {
if (is_object(item)) {
log.console(`${indent}[${i}]:`)
print_object(item, indent + " ")
} else {
@@ -50,21 +50,20 @@ def print_array = function(arr, indent) {
def print_object = function(obj, indent) {
if (!indent) indent = ""
var keys = Object.keys(obj)
var keys = array(obj)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var val = obj[key]
if (val == null) {
log.console(`${indent}${key}: null`)
} else if (typeof val == 'object') {
if (val.constructor && val.constructor.name == 'Blob') {
log.console(`${indent}${key}: <Blob ${val.length} bytes>`)
} else if (Array.isArray(val)) {
} else if (val.constructor && val.constructor.name == 'Blob') {
log.console(`${indent}${key}: <Blob ${val.length} bytes>`)
} else if (is_array(val)) {
if (val.length == 0) {
log.console(`${indent}${key}: []`)
} else if (val.length <= 4 && typeof val[0] != 'object') {
} else if (val.length <= 4 && !is_object(val[0])) {
log.console(`${indent}${key}: [${val.join(', ')}]`)
} else if (typeof val[0] != 'object') {
} else if (!is_object(val[0])) {
log.console(`${indent}${key}: [${val.slice(0, 4).join(', ')}...] (${val.length} items)`)
} else {
log.console(`${indent}${key}: (${val.length} items)`)
@@ -107,7 +106,7 @@ for (var i = 0; i < model.meshes.length; i++) {
for (var j = 0; j < m.primitives.length; j++) {
var p = m.primitives[j]
log.console(` primitive[${j}]: topology: ${p.topology}, indices: ${p.indices}, material: ${p.material}`)
var ak = Object.keys(p.attributes)
var ak = array(p.attributes)
var parts = []
for (var k = 0; k < ak.length; k++) parts.push(ak[k] + ': ' + text(p.attributes[ak[k]]))
log.console(' attributes: {' + parts.join(', ') + '}')
@@ -176,6 +175,6 @@ log.console(` required: [${model.extensions.required}]`)
log.console(`\n=== End ===\n`)
log.console(json.encode(model))
log.console(model)
$_.stop()
$stop()