Code Monkey home page Code Monkey logo

blendergltf's Introduction

This project is no longer maintained. Please use the official Khronos exporter instead: https://github.com/KhronosGroup/glTF-Blender-IO

Blendergltf

About

Blendergltf is an addon for Blender that adds the ability to export to the glTF format. This addon started its life as part of the Blender Real TimeEngine addon in order to provide a convenient way of streaming scene data to real time engines. As interest has grown in glTF, the glTF exporting code of the Blender Real Time Engine addon was moved into this repository to be used as both a Python module and a Blender addon.

Versions 1.0 and 2.0 of the glTF format are supported. For currently supported extensions, check out the extension settings.

NOTE: Version 1.2.0 of blendergltf is deprecating support for glTF 1.0. The next release of blendergltf will likely remove support for glTF 1.0 entirely. See issue #135 for more information and discussion.

Installation

  1. Download the blendergltf ZIP file from GitHub: stable, testing, releases

  2. Launch Blender, click File -> User Preferences..., and click the Add-ons tab at the top of the User Preferences dialog. Then, click the Install from file... button in the bottom margin of that dialog. Select your ZIP file to complete the install.

  3. In the left margin there is a Supported Level selector, make sure the Community level is selected. To find the addon quicker, you may need to enter gltf into the search box at the top of the left margin.

  4. You should now see Import-Export: glTF format as a block in the body of the preferences dialog. Put a checkmark on this row to activate it.

  5. Finally, click Save User Settings to keep the changes. Note that any other settings changes you have made to Blender may also be saved.

Usage

Load a scene you wish to export to glTF, and click File -> Export -> glTF (.gltf). Some glTF export options will appear in the lower-left margin, and a file dialog will ask for the location to save the exported file.

Add-On Settings

Axis Conversion

Up

Up axis of output coordinate system.

Forward

Forward axis of output coordinate system.

Nodes

Export Hidden Objects

Export nodes that are not set to visible.

Selection Only

Only export nodes that are currently selected.

Meshes

Apply Modifiers

Apply all modifiers to the output mesh data. When this option is disabled, no modifier data is exported.

Interleave Vertex Data

Store data for each vertex contiguously instead of each vertex property (e.g. position) contiguously. When vertex data is interleaved, all properties share one buffer. Otherwise, each property is stored in a separate buffer. This could give a slight performance improvement to vertex processing, but a lot of importers do not handle interleaved data well. It is not recommended to use this setting unless you are looking for importer bugs.

Export Vertex Color Alpha

Export vertex colors with 4 channels instead of 3. The fourth channel is always filled with a value of 1.0. This option needs to be enabled when exporting for Facebook.

Materials

Disable Material Export

Export minimum default materials. Useful when using material extensions. Additional maps are always exported when outputting glTF 2.0.

Embed Shader Data (glTF 1.0 only)

Embed shader data into the glTF file instead of as a separate file.

Animations

Armatures

  • All Eligible Export all actions that can be used by an armature
  • Active Export the active action per armature

Objects

  • All Eligible Export all actions that can be used by a non-armature object
  • Active Export the active action per non-armature object

Shape Keys

  • All Eligible Export all shape key actions that can be used by an object
  • Active Export the active shape key action per object

Images

Storage

  • Embed Embed image data into the glTF file.
  • Reference Use the same filepath that Blender uses for images.
  • Copy Copy images to output directory and use a relative reference.

sRGB Texture Support (glTF 1.0 only)

Use sRGB texture formats for sRGB textures. This option will produce invalid glTF since the specification currently does not allow for sRGB texture types.

Buffers

Embed Buffer Data

Embed buffer data into the glTF file.

Combine Buffer Data

Combine all buffers into a single buffer.

Extensions

BLENDER_physics (Draft)

Enable the BLENDER_physics extension to export rigid body physics data.

KHR_lights (Draft)

Enable the KHR_lights extension to export light data.

KHR_materials_common (Draft)

Enable the KHR_materials_common extension to export Blinn Phong materials.

KHR_materials_unlit (Draft)

Enable the KHR_materials_unlit extension to export simplified unlit materials.

Output

Copyright

Copyright string to include in output file.

Version

The version of the glTF specification to output as.

Export as binary

Export to the binary glTF file format (.glb).

Profile (glTF 1.0 only)

  • Web Target WebGL 1.0
  • Desktop Target OpenGL and GLSL 1.30. This profile is not explicitly supported by the glTF specification.

Pretty-print / indent JSON

Export JSON with indentation and a newline.

Prune Unused Resources

Do not export any data-blocks that have no users or references.

How to Contribute

The most helpful way to contribute right now is to try and use the output of Blendergltf, and report any issues you find. This will help us identify where work is still needed, and it will help make the addon more robust. If you want to contribute code, there are likely some tasks floating around the issue tracker.

blendergltf's People

Contributors

donmccurdy avatar emackey avatar ideasman42 avatar kupoman avatar lukesanantonio avatar moguri avatar mrdoob avatar onox avatar yrns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blendergltf's Issues

Add support for glTF animations

Currently glTF skins are exported, but not animations. We have the BLENDER_action extension for BlenderPanda, but we need to support specification compliant animations.

How are you merging these pull requests?

It's so weird, my changes are being added to master, but the branch itself is not listed as a parent, so it looks non-merged. What's your process for merging PRs?

exporter overwrites existing buffer_combined.bin files without prompt

In the proccess of exporting multiple gltf files one after the other, I discovered that the exporter names all of them "buffer_combined.bin" (Which would be great to customize in settings or have it use the gltf filename as a base) and if this file already exists it will overwrite without prompting.

accessor.count must be >= 1

If the material / texture of an object is messed up in Blender, a mesh can contain a primitive that has an "indices" member that points to an accessor that has a "count" value that is 0.

"count" must be >= 1. See https://github.com/KhronosGroup/glTF/tree/1.0.1/specification#accessorcount-white_check_mark

The bufferView that the accesor points to, has a "byteLength" of 0 as well. (Not very useful ๐Ÿ˜‰)

Python's assert keyword could be used to make sure generated .gltf file is valid.

Separating BRTE and Exporter code

Would you be supportive of an effort to separate the exporter code to a separate repo? Currently, the exporter will output virtually all data-blocks in a scene, regardless of whether or not they are used. In Issue #37 you explain that it does this to support the BRTE data transport use case, but it can produce grossly sub-optimal .gltf files with large scenes. Even zero-user meshes are exported.

My users need a solid export tool. I don't want to be divisive, but this seems like the cleanest solution. What do you think?

BLENDER_physics: Explore better ways to represent dimensions

The simple dimensions concept we currently use has the following issues:

  • Assumes Z-Up physics engine, but glTF is Y-Up
  • Relies on consuming engines to extract information from dimensions (e.g., pick a dimension to treat as radius/height, perform extra math steps, etc.)
  • Inconsistent use of scale and lack of transform information. Blender's dimensions have scale applied, but there is no clear way to determine scale or transforms of mesh shapes. Further more, with no transform, we cannot easily specify offsets.

However, it does provide the following benefits:

  • Easy to export
  • Does not make assumptions about how the consuming physics engines defines shapes

Error when exporting a model with vertex group not related to bone

When I try to export the model with the vertex group, Blender shows the following error:

2017-03-11_20-08-13

Traceback (most recent call last):
  File "C:\Users\victo\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\__init__.py", line 177, in execute
    gltf = export_gltf(data, settings)
  File "C:\Users\victo\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 1403, in export_gltf
    'skins': export_skins(state),
  File "C:\Users\victo\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 850, in export_skins
    for mesh_name, obj in state['skinned_meshes'].items()
  File "C:\Users\victo\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 850, in <dictcomp>
    for mesh_name, obj in state['skinned_meshes'].items()
  File "C:\Users\victo\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 838, in export_skin
    bone = arm.data.bones[group.name]
KeyError: 'bpy_prop_collection[key]: key "hair" not found'

location: <unknown location>:-1

Also, thank you for the Blender add-on.

BLENDER_physics: Export scene settings

We should explore whether we want to export per-scene physics settings such as gravity, and what this looks like.

One of the issues with exporting a gravity setting is defining units. We could say that BLENDER_physics exports a gravity setting as an acceleration value in m/s^2, but that assumes that one glTF unit will be represented as 1m in the engine consuming the file.

Exporter is writing out bad gltf meshes

Hi,

I'm getting issues exporting the mesh even when just doing it with the simplest settings or more custom settings. Not sure why but it won't handle an Icosphere or even susan without the mesh exploding.

blend_model
file
gltf_messed
settings

Thanks!

BLENDER_physics: Support collision layers

We should support some form of layers or groups/masks in BLENDER_physics. Blender's RigidBodyObjects only expose a layer option, but its game settings expose the full group/mask concept that Bullet supports.

Image URI Missing

I've run into an issue where the URI to a texture image file is missing from the glTF file itself. I am able to reproduce this in a simple case:

  1. Create a new, default blend file with camera, light, and cube.
  2. UV unwrap the cube.
  3. Apply a texture to the cube (in this case the UV color grid) using UV mapping, and place the texture in an "img" folder in the same parent folder as the blend file.
  4. Export the cube to glTF.

Although the image file is copied, the URI reference to it is blank:

"images": { "image_uv_color.png": { "uri": "" } }

I am attaching a source blend file and image, the result of the glTF export, and a snapshot of the export settings I used. I am using Blender 2.78.

export gltf settings
Test Cube glTF.zip
TestCube.zip

Add "selection only" checkbox

Hi, awesome work on this glTF exporter so far! Can I make a small feature request?

Please add a Selection only checkbox, similar to the STL exporter in Blender, such that only the selected objects are written to the exported file. This would help for example when you need to create a file that just has a mesh or a model but no lights or cameras, etc. Thanks!

activating addon causes error

hi,

when I try to active the addon, I get this error:

Traceback (most recent call last):
  File "/private/var/folders/3g/5hppblhd2pzdxhvjt8tj5_z00000gn/T/AppTranslocation/0AEC2418-2E78-40E2-92CD-7E92AB860044/d/blender.app/Contents/MacOS/../Resources/2.78/scripts/modules/addon_utils.py", line 330, in enable
    mod = __import__(module_name)
  File "/Users/freder/Library/Application Support/Blender/2.78/scripts/addons/blendergltf-master/__init__.py", line 43, in <module>
    from . import blendergltf
  File "/Users/freder/Library/Application Support/Blender/2.78/scripts/addons/blendergltf-master/blendergltf.py", line 1019
    else if texture.image.channels not in [3,4]:
          ^
SyntaxError: invalid syntax

Share vertices when possible

This exporter (and every other exporter/converter I've found) currently outputs each vertex once for every face it's a part of. This maximizes compatibility, and it's guaranteed to work, but it adds unnecessary bloat to the file in many cases. The exporter should check to see if a given vertex can be shared (i.e. no per-face normals/colors/UVs), and only output it once in that case.

If no one is available to work on this, I might just do this myself. I've done some Python before, but no Blender scripting, so we'll see how it goes.

Move current material values to an extension

Blendergltf currently exports material parameters as values that don't necessarily line up with a shader. Blendergltf should either switch to the common material extension or create a new Blender material extension instead of abusing material values.

Error exporting Blender file with missing image files

I try to export a Blender model to glTF using this addon. However, the model has a reference to a image file which does not exist any more. I can't seem to easily find out how to remove the missing image either.

Blender version 2.78.

This is the error message:

                                                                                              Traceback (most recent call last):

File "C:\Users\andre\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master_init_.py", line 131, in execute
gltf = blendergltf.export_gltf(scene, settings)
File "C:\Users\andre\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 1207, in export_gltf
'images': export_images(settings, scene_delta.get('images', [])),
File "C:\Users\andre\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 989, in export_images
return {'image_' + image.name: export_image(image) for image in images if check_image(image)}
File "C:\Users\andre\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 989, in
return {'image_' + image.name: export_image(image) for image in images if check_image(image)}
File "C:\Users\andre\AppData\Roaming\Blender Foundation\Blender\2.78\scripts\addons\blendergltf-master\blendergltf.py", line 956, in check_image
errors.add('x dimension is 0')
AttributeError: 'list' object has no attribute 'add'

Error when exporting a model with painted textures using Embed Image Data

Representative traceback:

Traceback (most recent call last):
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/__init__.py", line 89, in execute
    gltf = blendergltf.export_gltf(scene, settings)
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/blendergltf.py", line 1047, in export_gltf
    'images': export_images(settings, scene_delta.get('images', [])),
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/blendergltf.py", line 839, in export_images
    return {image.name: export_image(image) for image in images}
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/blendergltf.py", line 839, in <dictcomp>
    return {image.name: export_image(image) for image in images}
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/blendergltf.py", line 832, in export_image
    uri = image_to_data_uri(image)
  File "/home/filip/.config/blender/2.76/scripts/addons/blendergltf-master/blendergltf.py", line 812, in image_to_data_uri
    for span in range((height - 1) * width_byte_4, -1, - width_byte_4))
ValueError: range() arg 3 must not be zero

"TEXCOORD_" must end with an index

In 1.0.1 of the spec TEXCOORD_ must end with an index. See meshes. So properties like "TEXCOORD_UVMap" are not allowed anymore. (And application-specific must start with an _)

Taking a quick look at the code, it seems babylon.js and three.js expect an integer after TEXCOORD_.

Error exporting a model

I'm getting this error message when trying to export a fairly complex blender file as a gltf:

Traceback (most recent call last):
File ".../Blender/2.78/scripts/addons/blendergltf-master/__init__.py", line 175, in execute data = used_only(data)
File ".../Blender/2.78/scripts/addons/blendergltf-master/filters.py", line 76, in used_only slot.texture for slot in mat.texture_slots.values()
AttributeError: 'NoneType' object has no attribute 'texture_slots'

location: <unknown location>:-1

Exporter does not correctly handle meshes linked from another blend file

I'm not sure why this happens, I haven't had time to dig, but when you attempt to export objects linked from another file, the data is not added to the buffer, but the bytelength is still increased. So I ended up with the size of the output buffer being significantly smaller than buffer.byteLength.

Unused/hidden meshes

Meshes are still exported even if they are unused or used by hidden objects (not in nodes). I would sumbit a PR but maybe I'm missing something.

Option to output smooth normals

Currently, the glTF exporter outputs one vertex for every loop of every polygon. This preserves sharp edges at polygon seams, but dramatically increases the size of the resulting model when polygons share lots of vertices. I propose an option that would prevent vertex duplication by outputting "smooth" vertex normals instead of face normals per vertex. Alternatively, the exporter could decide whether to split edges based on the shading mode ("smooth" or "flat").

Split large meshes

Meshes that have more indexes than can be represented by a short datatype need to be split into multiple primitives. Integer-sized indexes are not currently supported by the glTF spec.

Cleanup - Class-based parsing

I want to float an idea by you guys @Kupoman @Moguri before I actually start work on it. I think it's a good idea.

The export_gltf.py file is getting too large, and it will only get larger as new features are added. I propose moving the parsing code for each type into classes that inherit this base:

class GLTFSerialBase:
    def __init__(self, context, source):
        '''convert source to gltf format, using context
        context contains the object lookup table, and glTF structures so far defined'''
        pass

    def __dict__(self):
        '''returns the converted glTF-compliant data structure'''
        return {}

    def __bytes__(self):
        '''returns the binary content of this object, or None if no binary'''
        pass

I expect this to greatly improve the readability of the code base. What do you think?

Add option to separate node transforms

glTF allows node transforms to be specified as a matrix or as separate translation, rotation, and scale values. We currently always export node transforms as a matrix, but in some cases a user may prefer the separate transforms.

Minify exported JSON

The generated identifiers are quite verbose, producing larger than necessary files. I propose a setting that would compact all the identifiers in the file while preserving the necessary links. Perhaps it could share an option with "Pretty-print JSON"? So material_Material.001 and its ilk would be shortened to a single-character random identifier.

Error exporting modular animated mesh: `line 1403, in export_gltf 'skins': export_skins(state)`

^[read blend: /Users/kev/code/robotbones/assets/models/mechsniper/blender/qubicle/rig-bones-mirrored.blend
Traceback (most recent call last):
  File "/Users/kev/Library/Application Support/Blender/2.78/scripts/addons/blendergltf/__init__.py", line 177, in execute
    gltf = export_gltf(data, settings)
  File "/Users/kev/Library/Application Support/Blender/2.78/scripts/addons/blendergltf/blendergltf.py", line 1403, in export_gltf
    'skins': export_skins(state),
  File "/Users/kev/Library/Application Support/Blender/2.78/scripts/addons/blendergltf/blendergltf.py", line 850, in export_skins
    for mesh_name, obj in state['skinned_meshes'].items()
  File "/Users/kev/Library/Application Support/Blender/2.78/scripts/addons/blendergltf/blendergltf.py", line 850, in <dictcomp>
    for mesh_name, obj in state['skinned_meshes'].items()
  File "/Users/kev/Library/Application Support/Blender/2.78/scripts/addons/blendergltf/blendergltf.py", line 838, in export_skin
    bone = arm.data.bones[group.name]
KeyError: 'bpy_prop_collection[key]: key "Group" not found'

location: <unknown location>:-1

Exported .gltf file contains data from previously failed exports

  1. Try to export a large file that fails to export. For example, one that produces the following exception: struct.error: ushort format requires 0 <= number <= (32767 * 2 + 1).
  2. Ctrl-n to reset Blender to the default state and then open a small .blend file that can be exported successfully.
  3. Export the small .blend file

The exported .gltf will now contain in addition to the expected accessors, buffer views, and buffers, also tons of accessors, buffer views, and buffers from the previous model that failed to export.

Meshes, nodes, and scenes seem to be OK.

How to install?

Can someone fill in how to install this into blender? I am lost and the readme has no information ๐Ÿ˜ข

Texture coordinates flipped in Three.js

For some reason, models exported with this addon display with flipped V coordinates in Three.js compared to the reference models in Three.js. Investigation pending.

Add support for PBR materials

We need a way to handle PBR materials to better support the glTF 2.0 specification. Since Blender 2.7x does not support PBR natively, we will need to add a material panel for PBR settings. The setting for this panel should be linked with Blender materials to give a rough preview to the user.

Clean up settings UI

Right now everything is kind of thrown in at random, and few things actually have tool tips. It would also be nice to group some of the settings like the COLLADA exporter does.

Create tag/release for stable versions

I don't know how often master is updated, but it might not be the best version to use.

Also, tags or releases can be useful to rollback to an older working version.

Vertex color support

I'm preparing to start working on this, but I want to make sure you're not going to beat me to it again lol.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.