Blender Asset Exporter

Howdy guys.
I’m working on a blender->playcanvas exporter

So far I can export an asset.json file containing the mesh data parenting. A fair bit of the simple stuff
If possible I’d like some clarification on the file format:


Number 1
Each mesh has the parameter “base”:0
What makes it not be zero?

Number 2
There is an empty list ‘skins’:[]
What makes it not empty?

Number 3
Is there any data apart from verts, faces, normals, uvdata and instances in the asset.jsopn file?
I haven’t tried, but things like vertex color?

Tomorrow and I’ll have to figure out how to create materials etc…

I have one final question:
Is building an exporter to playcanvas OK with you guys?
I sure hope so.

Building an exporter is great, go for it!

I’m not the person to answer these questions… but, …

skins: [] contains skinned model data, so you’d need to export a model with a skeleton to see that. Take a look at the Playbot export in the platform starter kit.

I don’t believe we currently export vertex color. I’ll have to check though.

Here is a rough outline of the model format (fair warning, I don’t know much about this area, and the model format is liable to change)

{
    "model": {
        "version": 2,
        "nodes": [
            {
                "name": "...",
                "position": [],
                "rotation": [],
                "scale": []
            }
        ],
        "parents": [
        ],
        "skins": [
            {
                "invertedBindMatrices": [
                    [...]
                ],
                "boneNames": [
                    "..."
                ]
            }
        ],
        "vertices": [
            {
                "position": {
                    "type": "float32",
                    "components": 3,
                    "data": [...]
                },
                "normal": {
                    "type": "float32",
                    "components": 3,
                    "data": [...]
                },
                "blendIndices": {
                    "type": "uint8",
                    "components": 4,
                    "data": [...]
                },
                "blendWeight": {
                    "type": "float32",
                    "components": 4,
                    "data": [...]
                },
                "texCoord0": {
                    "type": "float32",
                    "components": 2,
                    "data": [...]
                },
            }
        ],
        "meshes": [
            {
                "aabb": {
                  "min": [],
                  "max": []
                },
                "vertices": 0,
                "skin": 0,
                "indices": [],
                "type": "triangles",
                "base": 0,
                "count": 1000
            },        
        ],
        "meshInstances": [
            {
                "node": 0,
                "mesh": 0
            },
        ]
    }
}

Thanks for the outline of the format. I have indeed missed all the animation data. Because it’s not in the game I’m working on, I didn’t even think about animations!
Something tells me the animation data will probably be the hardest to extract from blender (If for no other reason than my having little experience with blenders animation system), so I think I’ll do the material exporting and then come back to the animation stuff.

Also, just in the interests of clarity for anyone stumbling over this page. PlayCanvas already supports models exported from Blender. You can export from Blender as FBX, Collada or OBJ and import by dragging your model into PlayCanvas.

This user-generated exporter is (I presume) for use with the open-source engine, for users who do not wish to use the PlayCanvas cloud toolset.

1 Like

@sdfgeoff Did you get anywhere with this?
I really like the look of the engine but I don’t want to build something that relies on a 3rd party service… would love to be able to export from blender directly without the cloud tools.

@dave I read an old forum post that seemed to suggest their used to be some command line tools to do the model conversion before the cloud service was introduced, are they still available for download anywhere?

I got the Blender exporter to export all the model data, but couldn’t figure out how to access the UV data within blender, nor how the UV data was stored within playcanvas’ file format.

So I decided to change the scope to be a collada -> playcanvas exporter (because everything can export collada). Unfortunately, just a few days after starting this project I hit a period of rather heavy workload which hasn’t ended yet. As a result, it’s currently sitting there waiting for me to have some free time.
My new approach to this exporter is to use the python library pycollada, which makes accessing the .dae file trivial. From that I’m exporting multiple files:

  • modelname.lights.json
  • modelname.json
  • modelname.mapping.json
  • material1.json
  • material2.json
    etc.

Looking through where I got to, I only completed a single one: the lights (which isn’t a file supported by playcanvas - but I’m hoping to write some javascript to load it). Hopefully the workload will ease up in a week or two and I’ll get back to developing this.

If you want to inspect what I’ve got, ask, but I don’t think it’s very useful at this stage.

@sdfgeoff Sounds cool… I think a Collada converter would be even better because it will work with other tools not just Blender.
I was thinking a good thing to help might be to get a very simple scene with just a cube, export in an ASCII/JSON format and then convert with the PlayCanvas tools and compare the two. Then do a slightly more complex scene etc.

That’s exactly the method I’m using!

The scene I’m using has two cubes of different materials and a plane with a UV image on it.

1 Like

Finally got back to this.

We can now export models and some material properties from blender

2 Likes

Nice! I guess the animations are the hardest part :S

Fortunately for me, I don’t need it in my project. It shouldn’t be any harder than reverse engineering the model format, but I just don’t have the reason to do it.

At this stage I consider multiple UV maps (and restructuring the script to be more sensible) as a higher priority.

I’m working on this again as I have another project lined up in playcanvas.

I thought I’d revive this thread to ask if the format has changed in any significant way. A brief inspection doesn’t reveal anything significant, though I see there are a lot more material parameters than I recall.

Anyway, the exporter now supports multiple UV layers, and a couple more material parameters. I’m currently fighting blender’s method of storing split normals for faces so that you don’t have to do it manually before you export…

1 Like

Split normals and multiple UV layers now supported. Some fixes regarding transformations. Also supports exporting multiple model hierarchy’s from the same blend file (using blender’s parenting). Now exports vertex color data.

File size needs to be optimized (even vertices that could be shared are not).

No, the geometry file format hasn’t changed. The only thing, as you say, is that we’ve added some additional material properties in the material JSON.

Sharing verts if definitely worth doing. The PlayCanvas converter on the server does exactly that. I’m the poor soul that wrote that code originally.