What is binary reader/stream reader c# equivalent in javascript

Hi guys, we have custom binary format that we developed for use in Unity/C# I guess that it’s possible to read binary data and construct meshes from the file. Format is a bit complicated I just need a starting point

Thank you

That’d be JavaScript WebSockets. If you’re using a custom format, I’m going to assume you’re using a library like Protobuf or MessagePack to serialize the data? If so, just use one of the JavaScript libraries to deserialize it on the client side. For example, both messagepack and protobuf are available via a CDN which can be included in your PlayCanvas project’s external scripts.

we have custom binary format for models that can consist of many parts/meshes. So we are just looping through parts and writing vertex, tris and some other data. Just need to go through the file and based on the first 32 bytes as serves as a header to calculate how much bytes are vertices, tris, etc…

like BinaryReader in C#

Hi @mirkoni,

Take a look at the Mesh API, and also the vertex/index iterator classes if needed.

Here is the docs for the Mesh Class:

https://developer.playcanvas.com/api/pc.Mesh.html

And you can find several examples that leverage it below, here is a good one:

https://playcanvas.github.io/#/graphics/mesh-generation

Yes, would definitely use that to construct the mesh but I first need to extract data from file. This is more javascript question then playcanvas

I think I understand. There is a native JS api in the FileReader class that can be of help. It contains a binary/arraybuffer reader that can be of help:

You may also find data structures like Uint8Array - JavaScript | MDN useful?