question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toByteArray produces invalid 3dm file in some cases

See original GitHub issue

Here’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()

image

box_test.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fraguadacommented, May 19, 2021

Got around to testing the changes by @kovacsv and this bug is no longer present in js.

1reaction
fraguadacommented, Feb 17, 2021
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found