2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-10-05 00:05:14 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:30:35 +00:00
|
|
|
/** \file blender/collada/collada_utils.cpp
|
|
|
|
* \ingroup collada
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-02-12 06:25:04 +00:00
|
|
|
/* COLLADABU_ASSERT, may be able to remove later */
|
|
|
|
#include "COLLADABUPlatform.h"
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "COLLADAFWGeometry.h"
|
|
|
|
#include "COLLADAFWMeshPrimitive.h"
|
|
|
|
#include "COLLADAFWMeshVertexData.h"
|
|
|
|
|
2017-06-24 21:36:03 +02:00
|
|
|
#include <set>
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include <string>
|
2012-06-15 22:00:25 +00:00
|
|
|
extern "C" {
|
2012-06-07 17:55:26 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "DNA_customdata_types.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "DNA_key_types.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "DNA_object_types.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "DNA_constraint_types.h"
|
2012-06-07 17:55:26 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2012-05-03 21:32:49 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2012-06-15 22:00:25 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2012-11-01 15:34:38 +00:00
|
|
|
#include "BLI_linklist.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "BLI_listbase.h"
|
2013-03-03 01:24:09 +00:00
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "BKE_action.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_customdata.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "BKE_constraint.h"
|
|
|
|
#include "BKE_key.h"
|
|
|
|
#include "BKE_material.h"
|
|
|
|
#include "BKE_node.h"
|
|
|
|
#include "BKE_object.h"
|
2013-02-05 13:16:21 +00:00
|
|
|
#include "BKE_global.h"
|
2017-11-08 12:16:49 -02:00
|
|
|
#include "BKE_layer.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_library.h"
|
2012-06-07 17:55:26 +00:00
|
|
|
#include "BKE_mesh.h"
|
2018-06-24 18:40:52 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_object.h"
|
2012-05-03 21:32:49 +00:00
|
|
|
#include "BKE_scene.h"
|
2012-06-07 17:55:26 +00:00
|
|
|
|
2016-05-28 18:41:54 +02:00
|
|
|
#include "ED_armature.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_node.h"
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2016-05-28 18:41:54 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "WM_api.h" // XXX hrm, see if we can do without this
|
|
|
|
#include "WM_types.h"
|
2013-08-23 11:16:52 +00:00
|
|
|
|
2013-03-03 01:24:09 +00:00
|
|
|
#include "bmesh.h"
|
2013-08-23 11:16:52 +00:00
|
|
|
#include "bmesh_tools.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2017-04-06 16:17:21 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-04-06 12:07:27 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#if 0
|
|
|
|
#include "NOD_common.h"
|
|
|
|
#endif
|
|
|
|
}
|
2017-04-06 16:17:21 +02:00
|
|
|
|
2017-04-01 15:29:40 +02:00
|
|
|
#include "collada_utils.h"
|
|
|
|
#include "ExportSettings.h"
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
#include "BlenderContext.h"
|
2017-04-01 15:29:40 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index)
|
|
|
|
{
|
|
|
|
if (index >= array.getValuesCount())
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT)
|
|
|
|
return array.getFloatValues()->getData()[index];
|
2018-06-08 08:07:48 +02:00
|
|
|
else
|
2010-10-05 00:05:14 +00:00
|
|
|
return array.getDoubleValues()->getData()[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// copied from /editors/object/object_relations.c
|
|
|
|
int bc_test_parent_loop(Object *par, Object *ob)
|
|
|
|
{
|
|
|
|
/* test if 'ob' is a parent somewhere in par's parents */
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (par == NULL) return 0;
|
|
|
|
if (ob == par) return 1;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return bc_test_parent_loop(par->parent, ob);
|
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer)
|
|
|
|
{
|
|
|
|
Base *base;
|
|
|
|
for (base = (Base *)view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
Object *cob = base->object;
|
|
|
|
if (cob->parent == ob) {
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
case OB_CAMERA:
|
|
|
|
case OB_LAMP:
|
|
|
|
case OB_EMPTY:
|
|
|
|
case OB_ARMATURE:
|
|
|
|
child_set.push_back(cob);
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_validateConstraints(bConstraint *con)
|
|
|
|
{
|
|
|
|
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
|
|
|
|
|
|
|
|
/* these we can skip completely (invalid constraints...) */
|
|
|
|
if (cti == NULL)
|
|
|
|
return false;
|
|
|
|
if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* these constraints can't be evaluated anyway */
|
|
|
|
if (cti->evaluate_constraint == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* influence == 0 should be ignored */
|
|
|
|
if (con->enforce == 0.0f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* validation passed */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
// a shortened version of parent_set_exec()
|
|
|
|
// if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting
|
|
|
|
int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
|
|
|
|
{
|
|
|
|
Object workob;
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_depsgraph(C);
|
2010-10-05 00:05:14 +00:00
|
|
|
Scene *sce = CTX_data_scene(C);
|
2017-07-21 11:53:13 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (!par || bc_test_parent_loop(par, ob))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ob->parent = par;
|
|
|
|
ob->partype = PAROBJECT;
|
|
|
|
|
|
|
|
ob->parsubstr[0] = 0;
|
|
|
|
|
|
|
|
if (is_parent_space) {
|
|
|
|
float mat[4][4];
|
|
|
|
// calc par->obmat
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_object_where_is_calc(depsgraph, sce, par);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
// move child obmat into world space
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(mat, par->obmat, ob->obmat);
|
2010-10-05 00:05:14 +00:00
|
|
|
copy_m4_m4(ob->obmat, mat);
|
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
// apply child obmat (i.e. decompose it into rot/loc/size)
|
2017-07-21 17:44:11 +02:00
|
|
|
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
// compute parentinv
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_object_workob_calc_parent(depsgraph, sce, ob, &workob);
|
2010-10-05 00:05:14 +00:00
|
|
|
invert_m4_m4(ob->parentinv, workob.obmat);
|
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
|
|
|
DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
std::vector<bAction *> bc_getSceneActions(const bContext *C, Object *ob, bool all_actions)
|
2018-02-25 00:06:41 +01:00
|
|
|
{
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
std::vector<bAction *> actions;
|
|
|
|
if (all_actions) {
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
ID *id;
|
|
|
|
|
|
|
|
for (id = (ID *)bmain->action.first; id; id = (ID *)(id->next)) {
|
|
|
|
bAction *act = (bAction *)id;
|
|
|
|
/* XXX This currently creates too many actions.
|
|
|
|
TODO Need to check if the action is compatible to the given object
|
|
|
|
*/
|
|
|
|
actions.push_back(act);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bAction *action = bc_getSceneObjectAction(ob);
|
|
|
|
actions.push_back(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
return actions;
|
2018-02-25 00:06:41 +01:00
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
std::string bc_get_action_id(std::string action_name, std::string ob_name, std::string channel_type, std::string axis_name, std::string axis_separator)
|
2018-02-26 16:34:45 +01:00
|
|
|
{
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
std::string result = action_name + "_" + channel_type;
|
|
|
|
if (ob_name.length() > 0)
|
|
|
|
result = ob_name + "_" + result;
|
|
|
|
if (axis_name.length() > 0)
|
|
|
|
result += axis_separator + axis_name;
|
|
|
|
return translate_id(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bc_update_scene(BlenderContext &blender_context, float ctime)
|
|
|
|
{
|
|
|
|
Main *bmain = blender_context.get_main();
|
|
|
|
Scene *scene = blender_context.get_scene();
|
|
|
|
Depsgraph *depsgraph = blender_context.get_depsgraph();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See remark in physics_fluid.c lines 395...)
|
|
|
|
* BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
|
|
|
|
*/
|
2018-02-26 16:34:45 +01:00
|
|
|
BKE_scene_frame_set(scene, ctime);
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
ED_update_for_newframe(bmain, depsgraph);
|
2018-02-26 16:34:45 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 15:55:51 +02:00
|
|
|
Object *bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name)
|
2012-05-03 21:32:49 +00:00
|
|
|
{
|
2018-06-14 15:15:51 +02:00
|
|
|
Object *ob = BKE_object_add_only_object(bmain, type, name);
|
2012-05-03 21:32:49 +00:00
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
|
2012-06-12 22:05:33 +00:00
|
|
|
ob->lay = scene->lay;
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
|
2012-05-03 21:32:49 +00:00
|
|
|
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
|
2018-06-14 16:43:11 +02:00
|
|
|
BKE_collection_object_add(bmain, layer_collection->collection, ob);
|
2017-11-08 12:16:49 -02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
Base *base = BKE_view_layer_base_find(view_layer, ob);
|
2018-11-08 08:15:22 +11:00
|
|
|
/* TODO: is setting active needed? */
|
|
|
|
BKE_view_layer_base_select_and_set_active(view_layer, base);
|
2012-05-03 21:32:49 +00:00
|
|
|
|
|
|
|
return ob;
|
|
|
|
}
|
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
Mesh *bc_get_mesh_copy(
|
2018-11-25 08:01:30 +11:00
|
|
|
BlenderContext &blender_context,
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
Object *ob,
|
|
|
|
BC_export_mesh_type export_mesh_type,
|
|
|
|
bool apply_modifiers,
|
|
|
|
bool triangulate)
|
2012-06-07 17:55:26 +00:00
|
|
|
{
|
|
|
|
CustomDataMask mask = CD_MASK_MESH;
|
2018-06-24 18:40:52 +02:00
|
|
|
Mesh *tmpmesh = NULL;
|
2013-03-18 18:25:05 +00:00
|
|
|
if (apply_modifiers) {
|
2018-06-24 18:40:52 +02:00
|
|
|
#if 0 /* Not supported by new system currently... */
|
2013-03-02 15:58:13 +00:00
|
|
|
switch (export_mesh_type) {
|
2013-07-19 10:40:43 +00:00
|
|
|
case BC_MESH_TYPE_VIEW:
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
dm = mesh_create_derived_view(depsgraph, scene, ob, mask);
|
2013-03-02 15:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
case BC_MESH_TYPE_RENDER:
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
dm = mesh_create_derived_render(depsgraph, scene, ob, mask);
|
2013-03-02 15:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-06-16 23:35:53 +00:00
|
|
|
}
|
2018-06-24 18:40:52 +02:00
|
|
|
#else
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
Depsgraph *depsgraph = blender_context.get_depsgraph();
|
2018-12-01 15:38:18 +01:00
|
|
|
Scene *scene_eval = blender_context.get_evaluated_scene();
|
|
|
|
Object *ob_eval = blender_context.get_evaluated_object(ob);
|
|
|
|
tmpmesh = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, mask);
|
2018-06-24 18:40:52 +02:00
|
|
|
#endif
|
2012-06-16 23:35:53 +00:00
|
|
|
}
|
2013-03-02 15:58:13 +00:00
|
|
|
else {
|
2018-12-01 15:38:18 +01:00
|
|
|
tmpmesh = (Mesh *)ob->data;
|
2013-03-02 15:58:13 +00:00
|
|
|
}
|
2012-06-16 23:35:53 +00:00
|
|
|
|
2018-06-24 18:40:52 +02:00
|
|
|
BKE_id_copy_ex(NULL, &tmpmesh->id, (ID **)&tmpmesh,
|
|
|
|
LIB_ID_CREATE_NO_MAIN |
|
|
|
|
LIB_ID_CREATE_NO_USER_REFCOUNT |
|
|
|
|
LIB_ID_CREATE_NO_DEG_TAG |
|
|
|
|
LIB_ID_COPY_NO_PREVIEW,
|
|
|
|
false);
|
2013-03-02 15:58:13 +00:00
|
|
|
|
|
|
|
if (triangulate) {
|
2015-05-27 13:19:40 +02:00
|
|
|
bc_triangulate_mesh(tmpmesh);
|
2013-03-02 15:58:13 +00:00
|
|
|
}
|
2015-05-27 13:19:40 +02:00
|
|
|
BKE_mesh_tessface_ensure(tmpmesh);
|
2012-06-07 17:55:26 +00:00
|
|
|
return tmpmesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *bc_get_assigned_armature(Object *ob)
|
|
|
|
{
|
|
|
|
Object *ob_arm = NULL;
|
|
|
|
|
|
|
|
if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) {
|
|
|
|
ob_arm = ob->parent;
|
|
|
|
}
|
|
|
|
else {
|
2012-06-12 22:05:33 +00:00
|
|
|
ModifierData *mod;
|
|
|
|
for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
|
2012-06-07 17:55:26 +00:00
|
|
|
if (mod->type == eModifierType_Armature) {
|
2012-06-12 22:05:33 +00:00
|
|
|
ob_arm = ((ArmatureModifierData *)mod)->object;
|
2012-06-07 17:55:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ob_arm;
|
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
/*
|
|
|
|
* Returns the highest selected ancestor
|
|
|
|
* returns NULL if no ancestor is selected
|
|
|
|
* IMPORTANT: This function expects that all exported objects have set:
|
|
|
|
* ob->id.tag & LIB_TAG_DOIT
|
|
|
|
*/
|
2018-06-08 08:07:48 +02:00
|
|
|
Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob)
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
|
2012-06-12 21:25:29 +00:00
|
|
|
{
|
|
|
|
Object *ancestor = ob;
|
2012-06-27 18:29:47 +00:00
|
|
|
while (ob->parent && bc_is_marked(ob->parent)) {
|
2012-06-12 21:25:29 +00:00
|
|
|
ob = ob->parent;
|
|
|
|
ancestor = ob;
|
|
|
|
}
|
|
|
|
return ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_is_base_node(LinkNode *export_set, Object *ob)
|
|
|
|
{
|
|
|
|
Object *root = bc_get_highest_selected_ancestor_or_self(export_set, ob);
|
|
|
|
return (root == ob);
|
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer)
|
2012-06-12 21:25:29 +00:00
|
|
|
{
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
bool to_export = (BLI_linklist_index(export_set, ob) != -1);
|
|
|
|
|
|
|
|
if (!to_export)
|
|
|
|
{
|
2018-11-25 08:01:30 +11:00
|
|
|
/* Mark this object as to_export even if it is not in the
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
export list, but it contains children to export */
|
|
|
|
|
|
|
|
std::vector<Object *> children;
|
|
|
|
bc_get_children(children, ob, view_layer);
|
|
|
|
for (int i = 0; i < children.size(); i++) {
|
|
|
|
if (bc_is_in_Export_set(export_set, children[i], view_layer)) {
|
|
|
|
to_export = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return to_export;
|
2012-06-12 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_has_object_type(LinkNode *export_set, short obtype)
|
|
|
|
{
|
2012-06-16 09:16:24 +00:00
|
|
|
LinkNode *node;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-06-16 09:16:24 +00:00
|
|
|
for (node = export_set; node; node = node->next) {
|
2012-06-12 21:25:29 +00:00
|
|
|
Object *ob = (Object *)node->link;
|
2012-06-16 09:16:24 +00:00
|
|
|
/* XXX - why is this checking for ob->data? - we could be looking for empties */
|
2012-06-12 21:25:29 +00:00
|
|
|
if (ob->type == obtype && ob->data) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bc_is_marked(Object *ob)
|
|
|
|
{
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
return ob && (ob->id.tag & LIB_TAG_DOIT);
|
2012-06-12 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bc_remove_mark(Object *ob)
|
|
|
|
{
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
ob->id.tag &= ~LIB_TAG_DOIT;
|
2012-06-12 21:25:29 +00:00
|
|
|
}
|
2012-06-14 10:38:39 +00:00
|
|
|
|
2012-08-12 17:13:07 +00:00
|
|
|
void bc_set_mark(Object *ob)
|
|
|
|
{
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
ob->id.tag |= LIB_TAG_DOIT;
|
2012-08-12 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 10:38:39 +00:00
|
|
|
// Use bubble sort algorithm for sorting the export set
|
|
|
|
void bc_bubble_sort_by_Object_name(LinkNode *export_set)
|
|
|
|
{
|
2012-06-14 14:48:52 +00:00
|
|
|
bool sorted = false;
|
|
|
|
LinkNode *node;
|
2012-06-16 09:16:24 +00:00
|
|
|
for (node = export_set; node->next && !sorted; node = node->next) {
|
2012-06-14 10:38:39 +00:00
|
|
|
|
2012-06-14 14:48:52 +00:00
|
|
|
sorted = true;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-06-14 14:48:52 +00:00
|
|
|
LinkNode *current;
|
2012-06-16 09:16:24 +00:00
|
|
|
for (current = export_set; current->next; current = current->next) {
|
2012-06-14 10:38:39 +00:00
|
|
|
Object *a = (Object *)current->link;
|
|
|
|
Object *b = (Object *)current->next->link;
|
|
|
|
|
2012-06-16 09:16:24 +00:00
|
|
|
if (strcmp(a->id.name, b->id.name) > 0) {
|
2012-06-14 10:38:39 +00:00
|
|
|
current->link = b;
|
|
|
|
current->next->link = a;
|
2012-06-14 14:48:52 +00:00
|
|
|
sorted = false;
|
2012-06-14 10:38:39 +00:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-06-14 10:38:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 02:21:07 +00:00
|
|
|
}
|
2012-06-15 22:00:25 +00:00
|
|
|
|
2018-06-08 08:07:48 +02:00
|
|
|
/* Check if a bone is the top most exportable bone in the bone hierarchy.
|
2018-06-01 18:19:39 +02:00
|
|
|
* When deform_bones_only == false, then only bones with NO parent
|
2012-06-15 22:00:25 +00:00
|
|
|
* can be root bones. Otherwise the top most deform bones in the hierarchy
|
|
|
|
* are root bones.
|
|
|
|
*/
|
2012-06-20 16:43:48 +00:00
|
|
|
bool bc_is_root_bone(Bone *aBone, bool deform_bones_only)
|
|
|
|
{
|
2012-06-16 09:16:24 +00:00
|
|
|
if (deform_bones_only) {
|
2012-06-15 22:00:25 +00:00
|
|
|
Bone *root = NULL;
|
|
|
|
Bone *bone = aBone;
|
|
|
|
while (bone) {
|
|
|
|
if (!(bone->flag & BONE_NO_DEFORM))
|
|
|
|
root = bone;
|
|
|
|
bone = bone->parent;
|
|
|
|
}
|
2012-06-16 09:16:24 +00:00
|
|
|
return (aBone == root);
|
2012-06-15 22:00:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return !(aBone->parent);
|
|
|
|
}
|
2012-06-22 16:16:58 +00:00
|
|
|
|
|
|
|
int bc_get_active_UVLayer(Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2018-11-28 18:13:58 +01:00
|
|
|
return CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
|
2012-06-22 16:16:58 +00:00
|
|
|
}
|
2013-02-09 00:23:59 +00:00
|
|
|
|
2013-03-05 14:47:49 +00:00
|
|
|
std::string bc_url_encode(std::string data)
|
|
|
|
{
|
2013-02-09 00:23:59 +00:00
|
|
|
/* XXX We probably do not need to do a full encoding.
|
2013-03-05 14:47:49 +00:00
|
|
|
* But in case that is necessary,then it can be added here.
|
|
|
|
*/
|
2013-02-09 00:23:59 +00:00
|
|
|
return bc_replace_string(data,"#", "%23");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string bc_replace_string(std::string data, const std::string& pattern,
|
2013-03-05 14:47:49 +00:00
|
|
|
const std::string& replacement)
|
|
|
|
{
|
2013-02-10 17:06:05 +00:00
|
|
|
size_t pos = 0;
|
2013-06-13 11:59:28 +00:00
|
|
|
while ((pos = data.find(pattern, pos)) != std::string::npos) {
|
2013-02-10 17:06:05 +00:00
|
|
|
data.replace(pos, pattern.length(), replacement);
|
|
|
|
pos += replacement.length();
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
2013-02-10 22:14:56 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-05 14:47:49 +00:00
|
|
|
* Calculate a rescale factor such that the imported scene's scale
|
|
|
|
* is preserved. I.e. 1 meter in the import will also be
|
|
|
|
* 1 meter in the current scene.
|
|
|
|
*/
|
2013-02-10 22:14:56 +00:00
|
|
|
|
2013-07-29 21:51:53 +00:00
|
|
|
void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
|
|
|
|
{
|
|
|
|
if (scale_to_scene) {
|
|
|
|
mul_m4_m4m4(ob->obmat, bc_unit.get_scale(), ob->obmat);
|
2013-02-10 22:14:56 +00:00
|
|
|
}
|
2013-07-29 21:51:53 +00:00
|
|
|
mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
|
|
|
|
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
|
|
|
|
}
|
2013-02-10 22:14:56 +00:00
|
|
|
|
2018-06-08 08:07:48 +02:00
|
|
|
void bc_match_scale(std::vector<Object *> *objects_done,
|
2013-07-29 21:51:53 +00:00
|
|
|
UnitConverter &bc_unit,
|
|
|
|
bool scale_to_scene)
|
|
|
|
{
|
2013-02-11 11:12:44 +00:00
|
|
|
for (std::vector<Object *>::iterator it = objects_done->begin();
|
|
|
|
it != objects_done->end();
|
2018-06-08 08:07:48 +02:00
|
|
|
++it)
|
2013-02-11 11:12:44 +00:00
|
|
|
{
|
2013-07-29 21:51:53 +00:00
|
|
|
Object *ob = *it;
|
|
|
|
if (ob -> parent == NULL) {
|
|
|
|
bc_match_scale(*it, bc_unit, scale_to_scene);
|
|
|
|
}
|
2013-02-10 22:14:56 +00:00
|
|
|
}
|
2013-02-21 19:33:04 +00:00
|
|
|
}
|
2013-03-02 15:58:13 +00:00
|
|
|
|
2017-03-23 12:38:41 +01:00
|
|
|
/*
|
2018-09-02 18:28:27 +10:00
|
|
|
* Convenience function to get only the needed components of a matrix
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
void bc_decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size)
|
|
|
|
{
|
|
|
|
if (size) {
|
|
|
|
mat4_to_size(size, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eul) {
|
|
|
|
mat4_to_eul(eul, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quat) {
|
|
|
|
mat4_to_quat(quat, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loc) {
|
|
|
|
copy_v3_v3(loc, mat[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 12:37:36 +01:00
|
|
|
/*
|
2018-09-02 18:28:27 +10:00
|
|
|
* Create rotation_quaternion from a delta rotation and a reference quat
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* mat_from: The rotation matrix before rotation
|
|
|
|
* mat_to : The rotation matrix after rotation
|
|
|
|
* qref : the quat corresponding to mat_from
|
|
|
|
*
|
|
|
|
* Output:
|
|
|
|
* rot : the calculated result (quaternion)
|
|
|
|
*/
|
2018-02-16 12:37:36 +01:00
|
|
|
void bc_rotate_from_reference_quat(float quat_to[4], float quat_from[4], float mat_to[4][4])
|
|
|
|
{
|
|
|
|
float qd[4];
|
|
|
|
float matd[4][4];
|
|
|
|
float mati[4][4];
|
|
|
|
float mat_from[4][4];
|
|
|
|
quat_to_mat4(mat_from, quat_from);
|
|
|
|
|
|
|
|
// Calculate the difference matrix matd between mat_from and mat_to
|
|
|
|
invert_m4_m4(mati, mat_from);
|
|
|
|
mul_m4_m4m4(matd, mati, mat_to);
|
|
|
|
|
|
|
|
mat4_to_quat(qd, matd);
|
|
|
|
|
2018-02-16 16:58:20 +01:00
|
|
|
mul_qt_qtqt(quat_to, qd, quat_from); // rot is the final rotation corresponding to mat_to
|
2018-02-16 12:37:36 +01:00
|
|
|
}
|
|
|
|
|
2013-06-02 23:20:49 +00:00
|
|
|
void bc_triangulate_mesh(Mesh *me)
|
|
|
|
{
|
2013-10-29 10:49:44 +00:00
|
|
|
bool use_beauty = false;
|
|
|
|
bool tag_only = false;
|
|
|
|
int quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE; /* XXX: The triangulation method selection could be offered in the UI */
|
2016-07-02 20:21:39 +10:00
|
|
|
|
|
|
|
const struct BMeshCreateParams bm_create_params = {0};
|
2016-07-01 19:07:11 +10:00
|
|
|
BMesh *bm = BM_mesh_create(
|
|
|
|
&bm_mesh_allocsize_default,
|
2016-07-02 20:21:39 +10:00
|
|
|
&bm_create_params);
|
2016-04-29 16:56:20 +02:00
|
|
|
BMeshFromMeshParams bm_from_me_params = {0};
|
|
|
|
bm_from_me_params.calc_face_normal = true;
|
|
|
|
BM_mesh_bm_from_me(bm, me, &bm_from_me_params);
|
2015-11-06 01:56:29 +11:00
|
|
|
BM_mesh_triangulate(bm, quad_method, use_beauty, tag_only, NULL, NULL, NULL);
|
2013-10-29 10:49:44 +00:00
|
|
|
|
2016-04-29 16:56:20 +02:00
|
|
|
BMeshToMeshParams bm_to_me_params = {0};
|
2018-06-13 16:29:12 +02:00
|
|
|
bm_to_me_params.calc_object_remap = false;
|
|
|
|
BM_mesh_bm_to_me(NULL, bm, me, &bm_to_me_params);
|
2013-03-02 15:58:13 +00:00
|
|
|
BM_mesh_free(bm);
|
|
|
|
}
|
2016-05-26 18:22:36 +02:00
|
|
|
|
|
|
|
/*
|
2016-07-02 10:02:04 +10:00
|
|
|
* A bone is a leaf when it has no children or all children are not connected.
|
|
|
|
*/
|
2016-05-26 18:22:36 +02:00
|
|
|
bool bc_is_leaf_bone(Bone *bone)
|
|
|
|
{
|
|
|
|
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
|
|
|
|
if (child->flag & BONE_CONNECTED)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-28 18:41:54 +02:00
|
|
|
|
|
|
|
EditBone *bc_get_edit_bone(bArmature * armature, char *name) {
|
|
|
|
EditBone *eBone;
|
|
|
|
|
|
|
|
for (eBone = (EditBone *)armature->edbo->first; eBone; eBone = eBone->next) {
|
|
|
|
if (STREQ(name, eBone->name))
|
|
|
|
return eBone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
int bc_set_layer(int bitfield, int layer)
|
|
|
|
{
|
|
|
|
return bc_set_layer(bitfield, layer, true); /* enable */
|
|
|
|
}
|
|
|
|
|
|
|
|
int bc_set_layer(int bitfield, int layer, bool enable)
|
|
|
|
{
|
|
|
|
int bit = 1u << layer;
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
bitfield |= bit;
|
|
|
|
else
|
|
|
|
bitfield &= ~bit;
|
|
|
|
|
|
|
|
return bitfield;
|
|
|
|
}
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
/**
|
|
|
|
* This method creates a new extension map when needed.
|
|
|
|
* \note The ~BoneExtensionManager destructor takes care
|
|
|
|
* to delete the created maps when the manager is removed.
|
|
|
|
*/
|
2016-09-23 12:56:04 +02:00
|
|
|
BoneExtensionMap &BoneExtensionManager::getExtensionMap(bArmature *armature)
|
|
|
|
{
|
|
|
|
std::string key = armature->id.name;
|
|
|
|
BoneExtensionMap *result = extended_bone_maps[key];
|
|
|
|
if (result == NULL)
|
|
|
|
{
|
|
|
|
result = new BoneExtensionMap();
|
|
|
|
extended_bone_maps[key] = result;
|
|
|
|
}
|
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoneExtensionManager::~BoneExtensionManager()
|
|
|
|
{
|
|
|
|
std::map<std::string, BoneExtensionMap *>::iterator map_it;
|
|
|
|
for (map_it = extended_bone_maps.begin(); map_it != extended_bone_maps.end(); ++map_it)
|
|
|
|
{
|
|
|
|
BoneExtensionMap *extended_bones = map_it->second;
|
|
|
|
for (BoneExtensionMap::iterator ext_it = extended_bones->begin(); ext_it != extended_bones->end(); ++ext_it) {
|
|
|
|
if (ext_it->second != NULL)
|
|
|
|
delete ext_it->second;
|
|
|
|
}
|
|
|
|
extended_bones->clear();
|
|
|
|
delete extended_bones;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-28 18:41:54 +02:00
|
|
|
/**
|
2016-07-02 10:02:04 +10:00
|
|
|
* BoneExtended is a helper class needed for the Bone chain finder
|
|
|
|
* See ArmatureImporter::fix_leaf_bones()
|
|
|
|
* and ArmatureImporter::connect_bone_chains()
|
|
|
|
*/
|
2016-05-28 18:41:54 +02:00
|
|
|
|
|
|
|
BoneExtended::BoneExtended(EditBone *aBone)
|
|
|
|
{
|
|
|
|
this->set_name(aBone->name);
|
|
|
|
this->chain_length = 0;
|
|
|
|
this->is_leaf = false;
|
|
|
|
this->tail[0] = 0.0f;
|
|
|
|
this->tail[1] = 0.5f;
|
|
|
|
this->tail[2] = 0.0f;
|
|
|
|
this->use_connect = -1;
|
|
|
|
this->roll = 0;
|
|
|
|
this->bone_layers = 0;
|
|
|
|
|
|
|
|
this->has_custom_tail = false;
|
|
|
|
this->has_custom_roll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *BoneExtended::get_name()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoneExtended::set_name(char *aName)
|
|
|
|
{
|
|
|
|
BLI_strncpy(name, aName, MAXBONENAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
int BoneExtended::get_chain_length()
|
|
|
|
{
|
|
|
|
return chain_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoneExtended::set_chain_length(const int aLength)
|
|
|
|
{
|
|
|
|
chain_length = aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoneExtended::set_leaf_bone(bool state)
|
|
|
|
{
|
|
|
|
is_leaf = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BoneExtended::is_leaf_bone()
|
|
|
|
{
|
|
|
|
return is_leaf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoneExtended::set_roll(float roll)
|
|
|
|
{
|
|
|
|
this->roll = roll;
|
|
|
|
this->has_custom_roll = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BoneExtended::has_roll()
|
|
|
|
{
|
|
|
|
return this->has_custom_roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
float BoneExtended::get_roll()
|
|
|
|
{
|
|
|
|
return this->roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoneExtended::set_tail(float vec[])
|
|
|
|
{
|
|
|
|
this->tail[0] = vec[0];
|
|
|
|
this->tail[1] = vec[1];
|
|
|
|
this->tail[2] = vec[2];
|
|
|
|
this->has_custom_tail = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BoneExtended::has_tail()
|
|
|
|
{
|
|
|
|
return this->has_custom_tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
float *BoneExtended::get_tail()
|
|
|
|
{
|
|
|
|
return this->tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isInteger(const std::string & s)
|
|
|
|
{
|
|
|
|
if (s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+'))) return false;
|
|
|
|
|
2018-10-11 08:49:28 +11:00
|
|
|
char *p;
|
2016-05-28 18:41:54 +02:00
|
|
|
strtol(s.c_str(), &p, 10);
|
|
|
|
|
|
|
|
return (*p == 0);
|
|
|
|
}
|
|
|
|
|
2016-05-29 00:35:50 +02:00
|
|
|
void BoneExtended::set_bone_layers(std::string layerString, std::vector<std::string> &layer_labels)
|
2016-05-28 18:41:54 +02:00
|
|
|
{
|
|
|
|
std::stringstream ss(layerString);
|
2016-05-29 00:35:50 +02:00
|
|
|
std::string layer;
|
|
|
|
int pos;
|
2016-05-28 18:41:54 +02:00
|
|
|
|
2016-05-29 00:35:50 +02:00
|
|
|
while (ss >> layer) {
|
2016-05-28 18:41:54 +02:00
|
|
|
|
2016-05-29 00:35:50 +02:00
|
|
|
/* Blender uses numbers to specify layers*/
|
2016-05-28 18:41:54 +02:00
|
|
|
if (isInteger(layer))
|
|
|
|
{
|
2016-05-29 01:30:20 +02:00
|
|
|
pos = atoi(layer.c_str());
|
2016-05-29 01:38:14 +02:00
|
|
|
if (pos >= 0 && pos < 32) {
|
2016-05-29 00:35:50 +02:00
|
|
|
this->bone_layers = bc_set_layer(this->bone_layers, pos);
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-28 18:41:54 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 00:35:50 +02:00
|
|
|
/* layer uses labels (not supported by blender). Map to layer numbers:*/
|
|
|
|
pos = find(layer_labels.begin(), layer_labels.end(), layer) - layer_labels.begin();
|
|
|
|
if (pos >= layer_labels.size()) {
|
|
|
|
layer_labels.push_back(layer); /* remember layer number for future usage*/
|
2016-05-28 18:41:54 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 00:35:50 +02:00
|
|
|
if (pos > 31)
|
2016-05-28 18:41:54 +02:00
|
|
|
{
|
2016-05-29 00:35:50 +02:00
|
|
|
fprintf(stderr, "Too many layers in Import. Layer %s mapped to Blender layer 31\n", layer.c_str());
|
|
|
|
pos = 31;
|
2016-05-28 18:41:54 +02:00
|
|
|
}
|
2016-05-29 00:35:50 +02:00
|
|
|
|
|
|
|
/* If numeric layers and labeled layers are used in parallel (unlikely),
|
2016-07-15 02:36:21 +10:00
|
|
|
* we get a potential mixup. Just leave as is for now.
|
|
|
|
*/
|
2016-05-29 00:35:50 +02:00
|
|
|
this->bone_layers = bc_set_layer(this->bone_layers, pos);
|
|
|
|
|
2016-05-28 18:41:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BoneExtended::get_bone_layers(int bitfield)
|
|
|
|
{
|
|
|
|
std::string result = "";
|
|
|
|
std::string sep = "";
|
|
|
|
int bit = 1u;
|
|
|
|
|
2016-05-29 01:30:20 +02:00
|
|
|
std::ostringstream ss;
|
2016-05-28 18:41:54 +02:00
|
|
|
for (int i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
if (bit & bitfield)
|
|
|
|
{
|
2016-05-29 01:30:20 +02:00
|
|
|
ss << sep << i;
|
2016-05-28 18:41:54 +02:00
|
|
|
sep = " ";
|
|
|
|
}
|
|
|
|
bit = bit << 1;
|
|
|
|
}
|
2016-05-29 01:30:20 +02:00
|
|
|
return ss.str();
|
2016-05-28 18:41:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int BoneExtended::get_bone_layers()
|
|
|
|
{
|
|
|
|
return (bone_layers == 0) ? 1 : bone_layers; // ensure that the bone is in at least one bone layer!
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BoneExtended::set_use_connect(int use_connect)
|
|
|
|
{
|
|
|
|
this->use_connect = use_connect;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BoneExtended::get_use_connect()
|
|
|
|
{
|
|
|
|
return this->use_connect;
|
|
|
|
}
|
2017-03-23 12:38:41 +01:00
|
|
|
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Stores a 4*4 matrix as a custom bone property array of size 16
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
void bc_set_IDPropertyMatrix(EditBone *ebone, const char *key, float mat[4][4])
|
|
|
|
{
|
|
|
|
IDProperty *idgroup = (IDProperty *)ebone->prop;
|
|
|
|
if (idgroup == NULL)
|
|
|
|
{
|
|
|
|
IDPropertyTemplate val = { 0 };
|
|
|
|
idgroup = IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties");
|
|
|
|
ebone->prop = idgroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDPropertyTemplate val = { 0 };
|
|
|
|
val.array.len = 16;
|
|
|
|
val.array.type = IDP_FLOAT;
|
|
|
|
|
|
|
|
IDProperty *data = IDP_New(IDP_ARRAY, &val, key);
|
|
|
|
float *array = (float *)IDP_Array(data);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
array[4 * i + j] = mat[i][j];
|
|
|
|
|
|
|
|
IDP_AddToGroup(idgroup, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Stores a Float value as a custom bone property
|
|
|
|
*
|
|
|
|
* Note: This function is currently not needed. Keep for future usage
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
static void bc_set_IDProperty(EditBone *ebone, const char *key, float value)
|
|
|
|
{
|
|
|
|
if (ebone->prop == NULL)
|
|
|
|
{
|
|
|
|
IDPropertyTemplate val = { 0 };
|
|
|
|
ebone->prop = IDP_New(IDP_GROUP, &val, "RNA_EditBone ID properties");
|
|
|
|
}
|
|
|
|
|
|
|
|
IDProperty *pgroup = (IDProperty *)ebone->prop;
|
|
|
|
IDPropertyTemplate val = { 0 };
|
|
|
|
IDProperty *prop = IDP_New(IDP_FLOAT, &val, key);
|
|
|
|
IDP_Float(prop) = value;
|
|
|
|
IDP_AddToGroup(pgroup, prop);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
/**
|
|
|
|
* Get a custom property when it exists.
|
|
|
|
* This function is also used to check if a property exists.
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
IDProperty *bc_get_IDProperty(Bone *bone, std::string key)
|
|
|
|
{
|
|
|
|
return (bone->prop == NULL) ? NULL : IDP_GetPropertyFromGroup(bone->prop, key.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Read a custom bone property and convert to float
|
|
|
|
* Return def if the property does not exist.
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
float bc_get_property(Bone *bone, std::string key, float def)
|
|
|
|
{
|
|
|
|
float result = def;
|
|
|
|
IDProperty *property = bc_get_IDProperty(bone, key);
|
|
|
|
if (property) {
|
|
|
|
switch (property->type) {
|
2018-04-16 17:08:27 +02:00
|
|
|
case IDP_INT:
|
|
|
|
result = (float)(IDP_Int(property));
|
|
|
|
break;
|
|
|
|
case IDP_FLOAT:
|
|
|
|
result = (float)(IDP_Float(property));
|
|
|
|
break;
|
|
|
|
case IDP_DOUBLE:
|
|
|
|
result = (float)(IDP_Double(property));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = def;
|
2017-03-23 12:38:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Read a custom bone property and convert to matrix
|
2018-09-24 17:27:41 +02:00
|
|
|
* Return true if conversion was successful
|
2018-09-02 18:28:27 +10:00
|
|
|
*
|
|
|
|
* Return false if:
|
|
|
|
* - the property does not exist
|
|
|
|
* - is not an array of size 16
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4])
|
|
|
|
{
|
|
|
|
IDProperty *property = bc_get_IDProperty(bone, key);
|
|
|
|
if (property && property->type == IDP_ARRAY && property->len == 16) {
|
|
|
|
float *array = (float *)IDP_Array(property);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
mat[i][j] = array[4 * i + j];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* get a vector that is stored in 3 custom properties (used in Blender <= 2.78)
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
void bc_get_property_vector(Bone *bone, std::string key, float val[3], const float def[3])
|
|
|
|
{
|
|
|
|
val[0] = bc_get_property(bone, key + "_x", def[0]);
|
|
|
|
val[1] = bc_get_property(bone, key + "_y", def[1]);
|
|
|
|
val[2] = bc_get_property(bone, key + "_z", def[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Check if vector exist stored in 3 custom properties (used in Blender <= 2.78)
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
static bool has_custom_props(Bone *bone, bool enabled, std::string key)
|
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (bc_get_IDProperty(bone, key + "_x")
|
|
|
|
|| bc_get_IDProperty(bone, key + "_y")
|
|
|
|
|| bc_get_IDProperty(bone, key + "_z"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
void bc_enable_fcurves(bAction *act, char *bone_name)
|
|
|
|
{
|
|
|
|
FCurve *fcu;
|
|
|
|
char prefix[200];
|
|
|
|
|
|
|
|
if (bone_name)
|
|
|
|
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
|
|
|
|
|
|
|
|
for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
|
|
|
|
if (bone_name) {
|
|
|
|
if (STREQLEN(fcu->rna_path, prefix, strlen(prefix)))
|
|
|
|
fcu->flag &= ~FCURVE_DISABLED;
|
|
|
|
else
|
|
|
|
fcu->flag |= FCURVE_DISABLED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fcu->flag &= ~FCURVE_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Ok, lets be super cautious and check if the bone exists */
|
|
|
|
bPose *pose = ob->pose;
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(pose, bone->name);
|
|
|
|
if (!pchan) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bAction *action = bc_getSceneObjectAction(ob);
|
|
|
|
bPoseChannel *parchan = pchan->parent;
|
|
|
|
|
|
|
|
bc_enable_fcurves(action, bone->name);
|
|
|
|
float ipar[4][4];
|
|
|
|
|
|
|
|
if (bone->parent) {
|
|
|
|
invert_m4_m4(ipar, parchan->pose_mat);
|
|
|
|
mul_m4_m4m4(mat, ipar, pchan->pose_mat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
copy_m4_m4(mat, pchan->pose_mat);
|
|
|
|
|
|
|
|
/* OPEN_SIM_COMPATIBILITY
|
|
|
|
* AFAIK animation to second life is via BVH, but no
|
|
|
|
* reason to not have the collada-animation be correct
|
|
|
|
*/
|
|
|
|
if (for_opensim) {
|
|
|
|
float temp[4][4];
|
|
|
|
copy_m4_m4(temp, bone->arm_mat);
|
|
|
|
temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
|
|
|
|
invert_m4(temp);
|
|
|
|
|
|
|
|
mul_m4_m4m4(mat, mat, temp);
|
|
|
|
|
|
|
|
if (bone->parent) {
|
|
|
|
copy_m4_m4(temp, bone->parent->arm_mat);
|
|
|
|
temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
|
|
|
|
|
|
|
|
mul_m4_m4m4(mat, temp, mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bc_enable_fcurves(action, NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_is_animated(BCMatrixSampleMap &values)
|
|
|
|
{
|
|
|
|
static float MIN_DISTANCE = 0.00001;
|
|
|
|
|
|
|
|
if (values.size() < 2)
|
|
|
|
return false; // need at least 2 entries to be not flat
|
|
|
|
|
|
|
|
BCMatrixSampleMap::iterator it;
|
|
|
|
const BCMatrix *refmat = NULL;
|
|
|
|
for (it = values.begin(); it != values.end(); ++it) {
|
|
|
|
const BCMatrix *matrix = it->second;
|
|
|
|
|
|
|
|
if (refmat == NULL) {
|
|
|
|
refmat = matrix;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!matrix->in_range(*refmat, MIN_DISTANCE))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bc_has_animations(Object *ob)
|
|
|
|
{
|
|
|
|
/* Check for object,lamp and camera transform animations */
|
|
|
|
if ((bc_getSceneObjectAction(ob) && bc_getSceneObjectAction(ob)->curves.first) ||
|
|
|
|
(bc_getSceneLampAction(ob) && bc_getSceneLampAction(ob)->curves.first) ||
|
|
|
|
(bc_getSceneCameraAction(ob) && bc_getSceneCameraAction(ob)->curves.first))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
//Check Material Effect parameter animations.
|
|
|
|
for (int a = 0; a < ob->totcol; a++) {
|
|
|
|
Material *ma = give_current_material(ob, a + 1);
|
|
|
|
if (!ma) continue;
|
|
|
|
if (ma->adt && ma->adt->action && ma->adt->action->curves.first)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
if ((key && key->adt && key->adt->action) && key->adt->action->curves.first)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool bc_has_animations(Scene *sce, LinkNode &export_set)
|
|
|
|
{
|
|
|
|
LinkNode *node;
|
|
|
|
|
|
|
|
for (node = &export_set; node; node = node->next) {
|
|
|
|
Object *ob = (Object *)node->link;
|
|
|
|
|
|
|
|
if (bc_has_animations(ob))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-23 12:38:41 +01:00
|
|
|
/**
|
2018-09-02 18:28:27 +10:00
|
|
|
* Check if custom information about bind matrix exists and modify the from_mat
|
|
|
|
* accordingly.
|
|
|
|
*
|
|
|
|
* Note: This is old style for Blender <= 2.78 only kept for compatibility
|
|
|
|
*/
|
2017-03-23 12:38:41 +01:00
|
|
|
void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float from_mat[4][4], bool use_local_space)
|
|
|
|
{
|
|
|
|
float loc[3];
|
|
|
|
float rot[3];
|
|
|
|
float scale[3];
|
|
|
|
static const float V0[3] = { 0, 0, 0 };
|
|
|
|
|
|
|
|
if (!has_custom_props(bone, export_settings->keep_bind_info, "restpose_loc") &&
|
|
|
|
!has_custom_props(bone, export_settings->keep_bind_info, "restpose_rot") &&
|
|
|
|
!has_custom_props(bone, export_settings->keep_bind_info, "restpose_scale"))
|
|
|
|
{
|
|
|
|
/* No need */
|
|
|
|
copy_m4_m4(to_mat, from_mat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bc_decompose(from_mat, loc, rot, NULL, scale);
|
|
|
|
loc_eulO_size_to_mat4(to_mat, loc, rot, scale, 6);
|
|
|
|
|
|
|
|
if (export_settings->keep_bind_info) {
|
|
|
|
bc_get_property_vector(bone, "restpose_loc", loc, loc);
|
|
|
|
|
|
|
|
if (use_local_space && bone->parent) {
|
|
|
|
Bone *b = bone;
|
|
|
|
while (b->parent) {
|
|
|
|
b = b->parent;
|
|
|
|
float ploc[3];
|
|
|
|
bc_get_property_vector(b, "restpose_loc", ploc, V0);
|
|
|
|
loc[0] += ploc[0];
|
|
|
|
loc[1] += ploc[1];
|
|
|
|
loc[2] += ploc[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export_settings->keep_bind_info) {
|
|
|
|
if (bc_get_IDProperty(bone, "restpose_rot_x"))
|
|
|
|
rot[0] = DEG2RADF(bc_get_property(bone, "restpose_rot_x", 0));
|
|
|
|
if (bc_get_IDProperty(bone, "restpose_rot_y"))
|
|
|
|
rot[1] = DEG2RADF(bc_get_property(bone, "restpose_rot_y", 0));
|
|
|
|
if (bc_get_IDProperty(bone, "restpose_rot_z"))
|
|
|
|
rot[2] = DEG2RADF(bc_get_property(bone, "restpose_rot_z", 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (export_settings->keep_bind_info) {
|
|
|
|
bc_get_property_vector(bone, "restpose_scale", scale, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
loc_eulO_size_to_mat4(to_mat, loc, rot, scale, 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-02 18:28:27 +10:00
|
|
|
* Make 4*4 matrices better readable
|
|
|
|
*/
|
2017-04-01 15:29:40 +02:00
|
|
|
void bc_sanitize_mat(float mat[4][4], int precision)
|
2017-03-23 12:38:41 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
double val = (double)mat[i][j];
|
|
|
|
val = double_round(val, precision);
|
|
|
|
mat[i][j] = (float)val;
|
|
|
|
}
|
2017-06-08 10:14:53 +02:00
|
|
|
}
|
2017-06-24 21:36:03 +02:00
|
|
|
|
2018-11-26 23:05:55 +01:00
|
|
|
void bc_sanitize_v3(float v[3], int precision)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
double val = (double)v[i];
|
|
|
|
val = double_round(val, precision);
|
|
|
|
v[i] = (float)val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 16:53:16 +01:00
|
|
|
void bc_sanitize_mat(double mat[4][4], int precision)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
mat[i][j] = double_round(mat[i][j], precision);
|
|
|
|
}
|
|
|
|
|
2018-11-26 23:05:55 +01:00
|
|
|
void bc_sanitize_v3(double v[3], int precision)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
v[i] = double_round(v[i], precision);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:34:45 +01:00
|
|
|
void bc_copy_m4_farray(float r[4][4], float *a)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
r[i][j] = *a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bc_copy_farray_m4(float *r, float a[4][4])
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
*r++ = a[i][j];
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void bc_copy_darray_m4d(double *r, double a[4][4])
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
*r++ = a[i][j];
|
|
|
|
}
|
|
|
|
|
|
|
|
void bc_copy_v44_m4d(std::vector<std::vector<double>> &r, double(&a)[4][4])
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
r[i][j] = a[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 16:34:45 +01:00
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
void bc_copy_m4d_v44(double (&r)[4][4], std::vector<std::vector<double>> &a)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
r[i][j] = a[i][j];
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 16:34:45 +01:00
|
|
|
}
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
/**
|
2017-06-24 21:36:03 +02:00
|
|
|
* Returns name of Active UV Layer or empty String if no active UV Layer defined
|
|
|
|
*/
|
|
|
|
std::string bc_get_active_uvlayer_name(Mesh *me)
|
|
|
|
{
|
2018-11-28 18:13:58 +01:00
|
|
|
int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
|
2017-06-24 21:36:03 +02:00
|
|
|
if (num_layers) {
|
2018-11-28 18:13:58 +01:00
|
|
|
char *layer_name = bc_CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV);
|
2018-01-01 15:02:26 +01:00
|
|
|
if (layer_name) {
|
|
|
|
return std::string(layer_name);
|
|
|
|
}
|
2017-06-24 21:36:03 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
/**
|
|
|
|
* Returns name of Active UV Layer or empty String if no active UV Layer defined.
|
|
|
|
* Assuming the Object is of type MESH
|
|
|
|
*/
|
2018-02-26 22:49:30 +01:00
|
|
|
std::string bc_get_active_uvlayer_name(Object *ob)
|
|
|
|
{
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
|
|
|
return bc_get_active_uvlayer_name(me);
|
|
|
|
}
|
|
|
|
|
2018-09-02 18:28:27 +10:00
|
|
|
/**
|
2017-06-24 21:36:03 +02:00
|
|
|
* Returns UV Layer name or empty string if layer index is out of range
|
|
|
|
*/
|
|
|
|
std::string bc_get_uvlayer_name(Mesh *me, int layer)
|
|
|
|
{
|
2018-11-28 18:13:58 +01:00
|
|
|
int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
|
2017-06-24 21:36:03 +02:00
|
|
|
if (num_layers && layer < num_layers) {
|
2018-11-28 18:13:58 +01:00
|
|
|
char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, layer);
|
2018-01-01 15:02:26 +01:00
|
|
|
if (layer_name) {
|
|
|
|
return std::string(layer_name);
|
|
|
|
}
|
2017-06-24 21:36:03 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
|
|
|
|
std::string bc_find_bonename_in_path(std::string path, std::string probe)
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
char *boneName = BLI_str_quoted_substrN(path.c_str(), probe.c_str());
|
|
|
|
if (boneName) {
|
|
|
|
result = std::string(boneName);
|
|
|
|
MEM_freeN(boneName);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bNodeTree *prepare_material_nodetree(Material *ma)
|
|
|
|
{
|
|
|
|
if (ma->nodetree == NULL) {
|
|
|
|
ma->nodetree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree");
|
|
|
|
ma->use_nodes = true;
|
|
|
|
}
|
|
|
|
return ma->nodetree;
|
|
|
|
}
|
|
|
|
|
|
|
|
bNode *bc_add_node(bContext *C, bNodeTree *ntree, int node_type, int locx, int locy, std::string label)
|
|
|
|
{
|
|
|
|
bNode *node = nodeAddStaticNode(C, ntree, node_type);
|
|
|
|
if (node) {
|
|
|
|
if (label.length() > 0) {
|
|
|
|
strcpy(node->label, label.c_str());
|
|
|
|
}
|
|
|
|
node->locx = locx;
|
|
|
|
node->locy = locy;
|
|
|
|
node->flag |= NODE_SELECT;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bNode *bc_add_node(bContext *C, bNodeTree *ntree, int node_type, int locx, int locy)
|
|
|
|
{
|
|
|
|
return bc_add_node(C, ntree, node_type, locx, locy, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// experimental, probably not used
|
|
|
|
static bNodeSocket *bc_group_add_input_socket(bNodeTree *ntree, bNode *to_node, int to_index, std::string label)
|
|
|
|
{
|
|
|
|
bNodeSocket *to_socket = (bNodeSocket *)BLI_findlink(&to_node->inputs, to_index);
|
2017-06-24 21:36:03 +02:00
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
//bNodeSocket *socket = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
|
|
|
//return socket;
|
|
|
|
|
|
|
|
bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
|
|
|
bNode *inputGroup = ntreeFindType(ntree, NODE_GROUP_INPUT);
|
|
|
|
node_group_input_verify(ntree, inputGroup, (ID *)ntree);
|
|
|
|
bNodeSocket *newsock = node_group_input_find_socket(inputGroup, gsock->identifier);
|
|
|
|
nodeAddLink(ntree, inputGroup, newsock, to_node, to_socket);
|
|
|
|
strcpy(newsock->name, label.c_str());
|
|
|
|
return newsock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bNodeSocket *bc_group_add_output_socket(bNodeTree *ntree, bNode *from_node, int from_index, std::string label)
|
|
|
|
{
|
|
|
|
bNodeSocket *from_socket = (bNodeSocket *)BLI_findlink(&from_node->outputs, from_index);
|
|
|
|
|
|
|
|
//bNodeSocket *socket = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
|
|
|
//return socket;
|
|
|
|
|
|
|
|
bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket(ntree, from_node, from_socket);
|
|
|
|
bNode *outputGroup = ntreeFindType(ntree, NODE_GROUP_OUTPUT);
|
|
|
|
node_group_output_verify(ntree, outputGroup, (ID *)ntree);
|
|
|
|
bNodeSocket *newsock = node_group_output_find_socket(outputGroup, gsock->identifier);
|
|
|
|
nodeAddLink(ntree, from_node, from_socket, outputGroup, newsock);
|
|
|
|
strcpy(newsock->name, label.c_str());
|
|
|
|
return newsock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bc_make_group(bContext *C, bNodeTree *ntree, std::map<std::string, bNode *> nmap)
|
|
|
|
{
|
2018-12-07 20:48:49 +11:00
|
|
|
bNode *gnode = node_group_make_from_selected(C, ntree, "ShaderNodeGroup", "ShaderNodeTree");
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
bNodeTree *gtree = (bNodeTree *)gnode->id;
|
|
|
|
|
|
|
|
bc_group_add_input_socket(gtree, nmap["main"], 0, "Diffuse");
|
|
|
|
bc_group_add_input_socket(gtree, nmap["emission"], 0, "Emission");
|
|
|
|
bc_group_add_input_socket(gtree, nmap["mix"], 0, "Transparency");
|
|
|
|
bc_group_add_input_socket(gtree, nmap["emission"], 1, "Emission");
|
|
|
|
bc_group_add_input_socket(gtree, nmap["main"], 4, "Metallic");
|
|
|
|
bc_group_add_input_socket(gtree, nmap["main"], 5, "Specular");
|
|
|
|
|
|
|
|
bc_group_add_output_socket(gtree, nmap["mix"], 0, "Shader");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void bc_node_add_link(bNodeTree *ntree, bNode *from_node, int from_index, bNode *to_node, int to_index)
|
|
|
|
{
|
|
|
|
bNodeSocket *from_socket = (bNodeSocket *)BLI_findlink(&from_node->outputs, from_index);
|
|
|
|
bNodeSocket *to_socket = (bNodeSocket *)BLI_findlink(&to_node->inputs, to_index);
|
|
|
|
|
|
|
|
nodeAddLink(ntree, from_node, from_socket, to_node, to_socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bc_add_default_shader(bContext *C, Material *ma)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = prepare_material_nodetree(ma);
|
|
|
|
std::map<std::string, bNode *> nmap;
|
|
|
|
#if 0
|
|
|
|
nmap["main"] = bc_add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, -300, 300);
|
|
|
|
nmap["emission"] = bc_add_node(C, ntree, SH_NODE_EMISSION, -300, 500, "emission");
|
|
|
|
nmap["add"] = bc_add_node(C, ntree, SH_NODE_ADD_SHADER, 100, 400);
|
|
|
|
nmap["transparent"] = bc_add_node(C, ntree, SH_NODE_BSDF_TRANSPARENT, 100, 200);
|
|
|
|
nmap["mix"] = bc_add_node(C, ntree, SH_NODE_MIX_SHADER, 400, 300, "transparency");
|
|
|
|
nmap["out"] = bc_add_node(C, ntree, SH_NODE_OUTPUT_MATERIAL, 600, 300);
|
|
|
|
nmap["out"]->flag &= ~NODE_SELECT;
|
|
|
|
|
|
|
|
bc_node_add_link(ntree, nmap["emission"], 0, nmap["add"], 0);
|
|
|
|
bc_node_add_link(ntree, nmap["main"], 0, nmap["add"], 1);
|
|
|
|
bc_node_add_link(ntree, nmap["add"], 0, nmap["mix"], 1);
|
|
|
|
bc_node_add_link(ntree, nmap["transparent"], 0, nmap["mix"], 2);
|
|
|
|
|
|
|
|
bc_node_add_link(ntree, nmap["mix"], 0, nmap["out"], 0);
|
|
|
|
// experimental, probably not used.
|
|
|
|
bc_make_group(C, ntree, nmap);
|
|
|
|
#else
|
|
|
|
nmap["main"] = bc_add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, 0, 300);
|
|
|
|
nmap["out"] = bc_add_node(C, ntree, SH_NODE_OUTPUT_MATERIAL, 300, 300);
|
|
|
|
bc_node_add_link(ntree, nmap["main"], 0, nmap["out"], 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::ColorOrTexture bc_get_base_color(Material *ma)
|
|
|
|
{
|
|
|
|
bNode *master_shader = bc_get_master_shader(ma);
|
|
|
|
if (master_shader) {
|
|
|
|
return bc_get_base_color(master_shader);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return bc_get_cot(ma->r, ma->g, ma->b, ma->alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::ColorOrTexture bc_get_specular_color(Material *ma, bool use_fallback)
|
|
|
|
{
|
|
|
|
bNode *master_shader = bc_get_master_shader(ma);
|
|
|
|
if (master_shader) {
|
|
|
|
return bc_get_specular_color(master_shader);
|
|
|
|
}
|
|
|
|
else if (use_fallback) {
|
|
|
|
return bc_get_cot(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return bc_get_cot(0.0, 0.0, 0.0, 1.0); // no specular
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::ColorOrTexture bc_get_base_color(bNode *shader)
|
|
|
|
{
|
|
|
|
bNodeSocket *socket = nodeFindSocket(shader, SOCK_IN, "Base Color");
|
|
|
|
if (socket)
|
|
|
|
{
|
|
|
|
bNodeSocketValueRGBA *dcol = (bNodeSocketValueRGBA *)socket->default_value;
|
|
|
|
float* col = dcol->value;
|
|
|
|
return bc_get_cot(col[0], col[1], col[2], col[3]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return bc_get_cot(0.8, 0.8, 0.8, 1.0); //default white
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::ColorOrTexture bc_get_specular_color(bNode *shader)
|
|
|
|
{
|
|
|
|
bNodeSocket *socket = nodeFindSocket(shader, SOCK_IN, "Specular");
|
|
|
|
if (socket)
|
|
|
|
{
|
|
|
|
bNodeSocketValueRGBA *dcol = (bNodeSocketValueRGBA *)socket->default_value;
|
|
|
|
float* col = dcol->value;
|
|
|
|
return bc_get_cot(col[0], col[1], col[2], col[3]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return bc_get_cot(0.8, 0.8, 0.8, 1.0); //default white
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bNode *bc_get_master_shader(Material *ma)
|
|
|
|
{
|
|
|
|
bNodeTree *nodetree = ma->nodetree;
|
|
|
|
if (nodetree) {
|
|
|
|
for (bNode *node = (bNode *)nodetree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->typeinfo->type == SH_NODE_BSDF_PRINCIPLED) {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::ColorOrTexture bc_get_cot(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
COLLADASW::Color color(r, g, b, a);
|
|
|
|
COLLADASW::ColorOrTexture cot(color);
|
|
|
|
return cot;
|
|
|
|
}
|