Skip to content

A python script to export blender objects into equivalent OpenGL code (using vertex_buffer_objects) including textures, materials, and bones.

Notifications You must be signed in to change notification settings

cosmiczilch/blender_to_opengl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

# A python script to export blender objects into equivalent OpenGL code
# (using vertex_buffer_objects) including textures, materials, and bones.

# Usage Steps / Instructions :

. Source this script into Blender. 

. Select all the objects you want to export and run the script.
  NOTE : make sure none of your objects have special characters (non-alnum_underscore)
  in their names. In case they do and you do not want to change that, you will have to
  edit the final .c files that will be exported. 
  (since these characters can't appear in C identifiers)
  NOTE : make sure to clear/apply all rotation and scaling before you export. 
  Click on : object -> clear/apply -> apply scale/rotation to object data

. 2 files will be exported : a .h and a .c

. Include both into your project. 

. In order to use these files, you'll also need to compile vbo_Utilities, CTexture,
  Bone and Transformation into your project. 
  The respective .h and .c files for these modules are found in the repository
  git@github.com:cosmiczilch/misc_opengl_utilities
  [ https://github.com/cosmiczilch/misc_opengl_utilities ]

. Also, since VBO functionality is defined as an OpenGL extension, you'll need to have
  setup your project to work with OpenGL extensions. 

. In your program, you'll need to call just 2 functions to init models,
  and 1 function to draw each object:
  > initialize_all_models () : this will initialize the polymodels objects for use. 
  > ready_all_models_for_render () : this will 'compile' the VBOs for all objects.

  > <ObjectName>.draw() : each ObjectName exported will have an individual .draw ()
    function which will draw the object using VBOs.
    If you pass the flag, RENDER_FLAGS__MAKE_NOW into draw (), you'll not need to
    call ready_all_models_for_render () above

. For textures :
  If you use uv-mapped textures in your object, In the initialize_all_models () function, 
  you'll find <obj>.setTexture() being called with a path to the texture image.
  Ensure that this path points to the correct relative/absolute path of the image.
  * Also, we'll be loading the image via SDL and due to differences in image reading formats,
  you'll have to do the following to your image for the mapping to look correct in the program :
  1. rotate by 180degree
  2. flip horizontally

. That's it!


################################################################################
# TODO : 

# export names of correct texture.png, and correct format

# export rotation/scale data also

# export material properties


V! Must make bone stuff work w/ repeated vertices from textures

About

A python script to export blender objects into equivalent OpenGL code (using vertex_buffer_objects) including textures, materials, and bones.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages