14
$\begingroup$

I wish to use Blender to model a level for a 3D game. The level is a set of Meshes. I have to set special (additional) properties per face (triangle). These properties are integer number (TAG1), vector (TAG2), and color (TAG3).

Ideally I would select a set of faces and set TAG1 to be 7 and TAG2 to be (1.0, 0.0, 0.0) and TAG3 to be Red for these faces.

Also I would like to be able to export that model in some format like Collada or OBJ. I use ASSIMP to convert model in my game internal format.

I believe OBJ does not support extra properties.

It sounds like a very common task for game development, but I can't find any simple solution that does not require creating my own 3D editing tool.

I can consider using other 3D modelling tools if any have such functionality.

$\endgroup$
4
  • 1
    $\begingroup$ Did you test what happens if you add custom properties to a Collada file and convert it with ASSIMP to your game engine format? Do the properties transfer over? And if you use ASSIMP, do you use a custom exporter for your format? Or one that ASSIMP offers natively? If ASSIMP allows custom entries in OBJ (and copies them over to your format), then it should be easy to adapt Blender's OBJ export script to include your face properties. You could utilize bmesh custom data layers in Blender to attach data to faces in Blender. $\endgroup$ Commented Dec 17, 2013 at 16:52
  • 1
    $\begingroup$ In Blender object data you have VertexGroup(float) and VertexColor (vector3), I think both collada and fbx able to export these properties, also there is another collada addon of Godot engine that seems export better that blender one, take a look at it may be useful. also I suggest that you right custom exporter for Opengl so you can read your data easily, like vertexgroup data export as int and read in opengl per-vertex data. $\endgroup$ Commented Oct 31, 2014 at 16:44
  • $\begingroup$ You can do this in Maya with Custom Metadata. I'm not sure what you have to do for this metadata to be exported. - knowledge.autodesk.com/support/maya/learn-explore/caas/… $\endgroup$ Commented Apr 23, 2017 at 17:02
  • $\begingroup$ allegedly Blender BMesh supports custom data layers. In the Python BMesh API, custom-data manipulation functions are still labeled TODO. I'm not sure if that's because the docs aren't done, or the functions aren't done. - docs.blender.org/api/blender_python_api_2_70a_release/… $\endgroup$ Commented Apr 24, 2017 at 18:20

1 Answer 1

3
$\begingroup$

The Blender BMesh Python API supports custom-data-layers per vert/edge/face/loop. Per face, it only supports the types (float, int, string, tex), so you'll have to make your own vectors and colors out of floats.

The code would be something like:

import bpy import bmesh ob = bpy.context.object # create a bmesh editing context... bm = bmesh.new() # if we're in edit mode, there is already a BMesh available, else make one if bpy.context.mode == 'EDIT_MESH': bm.from_edit_mesh(ob.data) else: bm.from_mesh(ob.data) # Make the layers.. tag_number = bm.faces.layers.integer.new('number_tag') tag_vector_x = bm.faces.layers.float.new('vector_tag_x') tag_vector_y = bm.faces.layers.float.new('vector_tag_y') tag_vector_z = bm.faces.layers.float.new('vector_tag_z') tag_color_r = bm.faces.layers.float.new('color_tag_r') tag_color_g = bm.faces.layers.float.new('color_tag_g') tag_color_b = bm.faces.layers.float.new('color_tag_b') # fetch the layers tag_number = bm.faces.layers.integer.get('number_tag') tag_vector_x = bm.faces.layers.float.get('vector_tag_x') tag_vector_y = bm.faces.layers.float.get('vector_tag_y') tag_vector_z = bm.faces.layers.float.get('vector_tag_z') tag_color_r = bm.faces.layers.float.get('color_tag_r') tag_color_g = bm.faces.layers.float.get('color_tag_g') tag_color_b = bm.faces.layers.float.get('color_tag_b') # set the tag value for a particular face bm.edges[face_no][tag_number] = new_number_tag_value # retrieve the value for a particular face my_number_tag_value = bm.faces[face_no][tag_number] # save our edits if bpy.context.mode == 'EDIT_MESH': bm.updated_edit_mesh(ob.data) else: bm.to_mesh(ob.data) bm.free() 

At some point, you'll probably want to iterate selected faces, like this:

for f in bm.faces: if f.select: print(f.index) 

I don't know if the collada exporter does anything with this custom BMesh data. If not, you'll either need to extend it, or write your own exporter.

See also:

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.