toByteArray produces invalid 3dm file in some cases
See original GitHub issueHere’s a simple node.js script that produces an invalid .3dm file.
The script solves a simple Grasshopper definition on Compute (see below) that produces a very simple mesh box and then adds that mesh to a doc and writes it to “box_test.3dm”.
Uncomment the line to also add the sphere to the doc. In this case the .3dm file will be valid and the mesh box will be present and valid.
const rhino3dm = require('rhino3dm')
const compute = require('compute-rhino3d')
const fs = require('fs')
compute.url = 'http://localhost:8081/'
const name = 'box_test.gh'
const buffer = fs.readFileSync(name)
const definition = new Uint8Array(buffer)
async function doStuff() {
const rhino = await rhino3dm()
let res = await compute.Grasshopper.evaluateDefinition(definition, [])
const json = JSON.parse(res.values[0].InnerTree['{ 0; }'][0].data)
const mesh = rhino.CommonObject.decode(json)
const doc = new rhino.File3dm()
doc.objects().add(mesh, null)
const sphere = new rhino.Sphere([0,0,0], 12)
// add this sphere and the 3dm file will be valid!
//doc.objects().addSphere(sphere, null)
console.log('saved')
fs.writeFileSync('box_test.3dm', doc.toByteArray())
}
doStuff()
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Rhino3dm - Threejs geometry import failing - McNeel Forum
I'm using rhino3dm for that however the file I receive is corrupted. ... to this issue: toByteArray produces invalid 3dm file in some...
Read more >Rhino3dm file.3dm not an m_archive when adding 6 or more ...
I'm trying to create a .3dm file from a set of vertices and faces and ran into a problem where the file gave...
Read more >Invalid argument when passing ByteArray to javascript ...
I am using Rhino to evaluate some javascript, where I simply pass a ByteArray from kotlin to a function in Javascript.
Read more >Untitled
Failed to write 3dm file object table WebNov 10, 2018 · (First the ... Rhino - rhino3dm Libraries toByteArray produces invalid 3dm file...
Read more >ByteArrayOutputStream (Java Platform SE 8 )
This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got around to testing the changes by @kovacsv and this bug is no longer present in js.
@pearswj @sbaer here is another case of this issue popping up: https://discourse.mcneel.com/t/rhino3dm-threejs-geometry-import-failing/118635/6