2013-01-21 13:45:49 +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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup collada
|
2013-01-21 13:45:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "COLLADASWBaseInputElement.h"
|
|
|
|
#include "COLLADASWInstanceController.h"
|
|
|
|
#include "COLLADASWPrimitves.h"
|
|
|
|
#include "COLLADASWSource.h"
|
|
|
|
|
|
|
|
#include "DNA_action_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
|
|
|
|
#include "BKE_action.h"
|
|
|
|
#include "BKE_armature.h"
|
|
|
|
#include "BKE_global.h"
|
2014-02-18 21:53:25 +01:00
|
|
|
#include "BKE_idprop.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_mesh.h"
|
2013-01-21 13:45:49 +00:00
|
|
|
|
|
|
|
#include "ED_armature.h"
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
|
|
|
#include "ArmatureExporter.h"
|
|
|
|
#include "ControllerExporter.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "GeometryExporter.h"
|
2013-01-21 13:45:49 +00:00
|
|
|
#include "SceneExporter.h"
|
|
|
|
|
|
|
|
#include "collada_utils.h"
|
|
|
|
|
|
|
|
bool ControllerExporter::is_skinned_mesh(Object *ob)
|
|
|
|
{
|
|
|
|
return bc_get_assigned_armature(ob) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::write_bone_URLs(COLLADASW::InstanceController &ins,
|
|
|
|
Object *ob_arm,
|
|
|
|
Bone *bone)
|
|
|
|
{
|
2019-05-23 12:17:17 +02:00
|
|
|
if (bc_is_root_bone(bone, this->export_settings.get_deform_bones_only())) {
|
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 node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
|
|
|
|
ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, node_id));
|
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
else {
|
|
|
|
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
|
|
|
|
write_bone_URLs(ins, ob_arm, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ControllerExporter::add_instance_controller(Object *ob)
|
|
|
|
{
|
|
|
|
Object *ob_arm = bc_get_assigned_armature(ob);
|
|
|
|
bArmature *arm = (bArmature *)ob_arm->data;
|
|
|
|
|
|
|
|
const std::string &controller_id = get_controller_id(ob_arm, ob);
|
|
|
|
|
|
|
|
COLLADASW::InstanceController ins(mSW);
|
|
|
|
ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id));
|
|
|
|
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!me->dvert) {
|
2013-01-21 13:45:49 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* write root bone URLs */
|
2013-01-21 13:45:49 +00:00
|
|
|
Bone *bone;
|
|
|
|
for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) {
|
|
|
|
write_bone_URLs(ins, ob_arm, bone);
|
|
|
|
}
|
2013-02-04 00:18:09 +00:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
InstanceWriter::add_material_bindings(
|
2019-05-23 12:17:17 +02:00
|
|
|
ins.getBindMaterial(), ob, this->export_settings.get_active_uv_only());
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
ins.add();
|
|
|
|
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
|
|
|
void ControllerExporter::export_controllers()
|
2013-01-21 13:45:49 +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
|
|
|
Scene *sce = blender_context.get_scene();
|
2013-01-21 13:45:49 +00:00
|
|
|
openLibrary();
|
|
|
|
|
|
|
|
GeometryFunctor gf;
|
|
|
|
gf.forEachMeshObjectInExportSet<ControllerExporter>(
|
2019-05-23 12:17:17 +02:00
|
|
|
sce, *this, this->export_settings.get_export_set());
|
2013-01-21 13:45:49 +00:00
|
|
|
|
|
|
|
closeLibrary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::operator()(Object *ob)
|
|
|
|
{
|
|
|
|
Object *ob_arm = bc_get_assigned_armature(ob);
|
|
|
|
Key *key = BKE_key_from_object(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-10 17:06:05 +00:00
|
|
|
if (ob_arm) {
|
2013-01-21 13:45:49 +00:00
|
|
|
export_skin_controller(ob, ob_arm);
|
2013-02-10 17:06:05 +00:00
|
|
|
}
|
2019-05-23 12:17:17 +02:00
|
|
|
if (key && this->export_settings.get_include_shapekeys()) {
|
2013-01-21 13:45:49 +00:00
|
|
|
export_morph_controller(ob, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
bool ArmatureExporter::already_written(Object *ob_arm)
|
|
|
|
{
|
2019-04-17 08:24:14 +02:00
|
|
|
return std::find(written_armatures.begin(), written_armatures.end(), ob_arm) !=
|
|
|
|
written_armatures.end();
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ArmatureExporter::wrote(Object *ob_arm)
|
|
|
|
{
|
|
|
|
written_armatures.push_back(ob_arm);
|
|
|
|
}
|
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
void ArmatureExporter::find_objects_using_armature(Object *ob_arm,
|
|
|
|
std::vector<Object *> &objects,
|
|
|
|
Scene *sce)
|
2013-01-21 13:45:49 +00:00
|
|
|
{
|
|
|
|
objects.clear();
|
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
Base *base = (Base *)sce->base.first;
|
2013-01-21 13:45:49 +00:00
|
|
|
while (base) {
|
|
|
|
Object *ob = base->object;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
if (ob->type == OB_MESH && get_assigned_armature(ob) == ob_arm) {
|
|
|
|
objects.push_back(ob);
|
|
|
|
}
|
|
|
|
|
|
|
|
base = base->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::string ControllerExporter::get_controller_id(Object *ob_arm, Object *ob)
|
|
|
|
{
|
|
|
|
return translate_id(id_name(ob_arm)) + "_" + translate_id(id_name(ob)) +
|
|
|
|
SKIN_CONTROLLER_ID_SUFFIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::get_controller_id(Key *key, Object *ob)
|
|
|
|
{
|
|
|
|
return translate_id(id_name(ob)) + MORPH_CONTROLLER_ID_SUFFIX;
|
|
|
|
}
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* ob should be of type OB_MESH
|
|
|
|
* both args are required */
|
2013-01-21 13:45:49 +00:00
|
|
|
void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
|
|
|
|
{
|
2019-04-30 13:41:21 +10:00
|
|
|
/* joint names
|
|
|
|
* joint inverse bind matrices
|
|
|
|
* vertex weights */
|
2013-01-21 13:45:49 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* input:
|
|
|
|
* joint names: ob -> vertex group names
|
|
|
|
* vertex group weights: me->dvert -> groups -> index, weight */
|
2013-01-21 13:45:49 +00:00
|
|
|
|
2019-05-23 12:17:17 +02:00
|
|
|
bool use_instantiation = this->export_settings.get_use_object_instantiation();
|
2013-01-21 13:45:49 +00:00
|
|
|
Mesh *me;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-24 18:40:52 +02:00
|
|
|
if (((Mesh *)ob->data)->dvert == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
me = bc_get_mesh_copy(blender_context,
|
2018-12-20 08:01:39 +11:00
|
|
|
ob,
|
2019-05-23 12:17:17 +02:00
|
|
|
this->export_settings.get_export_mesh_type(),
|
|
|
|
this->export_settings.get_apply_modifiers(),
|
|
|
|
this->export_settings.get_triangulate());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
std::string controller_name = id_name(ob_arm);
|
|
|
|
std::string controller_id = get_controller_id(ob_arm, ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
openSkin(controller_id,
|
|
|
|
controller_name,
|
|
|
|
COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
add_bind_shape_mat(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
std::string joints_source_id = add_joints_source(ob_arm, &ob->defbase, controller_id);
|
|
|
|
std::string inv_bind_mat_source_id = add_inv_bind_mats_source(
|
|
|
|
ob_arm, &ob->defbase, controller_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
std::list<int> vcounts;
|
|
|
|
std::list<int> joints;
|
|
|
|
std::list<float> weights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* def group index -> joint index */
|
2013-01-21 13:45:49 +00:00
|
|
|
std::vector<int> joint_index_by_def_index;
|
|
|
|
bDeformGroup *def;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
for (def = (bDeformGroup *)ob->defbase.first, i = 0, j = 0; def; def = def->next, i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_bone_defgroup(ob_arm, def)) {
|
2013-01-21 13:45:49 +00:00
|
|
|
joint_index_by_def_index.push_back(j++);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
else {
|
2013-01-21 13:45:49 +00:00
|
|
|
joint_index_by_def_index.push_back(-1);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-25 16:02:40 +00:00
|
|
|
int oob_counter = 0;
|
2013-01-21 13:45:49 +00:00
|
|
|
for (i = 0; i < me->totvert; i++) {
|
|
|
|
MDeformVert *vert = &me->dvert[i];
|
|
|
|
std::map<int, float> jw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* We're normalizing the weights later */
|
2013-01-21 13:45:49 +00:00
|
|
|
float sumw = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
for (j = 0; j < vert->totweight; j++) {
|
2020-02-11 12:35:10 +11:00
|
|
|
uint idx = vert->dw[j].def_nr;
|
2013-02-25 16:02:40 +00:00
|
|
|
if (idx >= joint_index_by_def_index.size()) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* XXX: Maybe better find out where and
|
|
|
|
* why the Out Of Bound indexes get created ? */
|
2013-02-25 16:02:40 +00:00
|
|
|
oob_counter += 1;
|
|
|
|
}
|
|
|
|
else {
|
2020-02-11 12:35:10 +11:00
|
|
|
int joint_index = joint_index_by_def_index[idx];
|
|
|
|
if (joint_index != -1 && vert->dw[j].weight > 0.0f) {
|
|
|
|
jw[joint_index] += vert->dw[j].weight;
|
|
|
|
sumw += vert->dw[j].weight;
|
2013-02-08 12:31:47 +00:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
if (sumw > 0.0f) {
|
|
|
|
float invsumw = 1.0f / sumw;
|
|
|
|
vcounts.push_back(jw.size());
|
2019-09-08 03:31:49 +10:00
|
|
|
for (std::map<int, float>::iterator m = jw.begin(); m != jw.end(); ++m) {
|
2013-01-21 13:45:49 +00:00
|
|
|
joints.push_back((*m).first);
|
|
|
|
weights.push_back(invsumw * (*m).second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vcounts.push_back(0);
|
|
|
|
#if 0
|
|
|
|
vcounts.push_back(1);
|
|
|
|
joints.push_back(-1);
|
|
|
|
weights.push_back(1.0f);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2013-02-25 16:02:40 +00:00
|
|
|
|
|
|
|
if (oob_counter > 0) {
|
2018-02-26 16:34:45 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"Ignored %d Vertex weights which use index to non existing VGroup %zu.\n",
|
2015-06-19 12:29:06 +02:00
|
|
|
oob_counter,
|
|
|
|
joint_index_by_def_index.size());
|
2013-02-25 16:02:40 +00:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string weights_source_id = add_weights_source(me, controller_id, weights);
|
|
|
|
add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id);
|
|
|
|
add_vertex_weights_element(weights_source_id, joints_source_id, vcounts, joints);
|
|
|
|
|
2018-06-24 18:40:52 +02:00
|
|
|
BKE_id_free(nullptr, me);
|
2013-03-02 15:58:13 +00:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
closeSkin();
|
|
|
|
closeController();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::export_morph_controller(Object *ob, Key *key)
|
|
|
|
{
|
2019-05-23 12:17:17 +02:00
|
|
|
bool use_instantiation = this->export_settings.get_use_object_instantiation();
|
2013-01-21 13:45:49 +00:00
|
|
|
Mesh *me;
|
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
me = bc_get_mesh_copy(blender_context,
|
2013-03-02 15:58:13 +00:00
|
|
|
ob,
|
2019-05-23 12:17:17 +02:00
|
|
|
this->export_settings.get_export_mesh_type(),
|
|
|
|
this->export_settings.get_apply_modifiers(),
|
|
|
|
this->export_settings.get_triangulate());
|
2013-01-21 13:45:49 +00:00
|
|
|
|
|
|
|
std::string controller_name = id_name(ob) + "-morph";
|
|
|
|
std::string controller_id = get_controller_id(key, ob);
|
|
|
|
|
|
|
|
openMorph(
|
|
|
|
controller_id,
|
|
|
|
controller_name,
|
|
|
|
COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation)));
|
2013-02-04 00:18:09 +00:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
std::string targets_id = add_morph_targets(key, ob);
|
|
|
|
std::string morph_weights_id = add_morph_weights(key, ob);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::TargetsElement targets(mSW);
|
|
|
|
|
|
|
|
COLLADASW::InputList &input = targets.getInputList();
|
|
|
|
|
|
|
|
input.push_back(COLLADASW::Input(
|
|
|
|
COLLADASW::InputSemantic::MORPH_TARGET, /* constant declared in COLLADASWInputList.h */
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, targets_id)));
|
|
|
|
input.push_back(
|
|
|
|
COLLADASW::Input(COLLADASW::InputSemantic::MORPH_WEIGHT,
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id)));
|
|
|
|
targets.add();
|
|
|
|
|
2018-06-24 18:40:52 +02:00
|
|
|
BKE_id_free(nullptr, me);
|
2013-02-04 00:18:09 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* support for animations
|
|
|
|
* can also try the base element and param alternative */
|
2013-01-21 13:45:49 +00:00
|
|
|
add_weight_extras(key);
|
|
|
|
closeMorph();
|
|
|
|
closeController();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::add_morph_targets(Key *key, Object *ob)
|
|
|
|
{
|
|
|
|
std::string source_id = translate_id(id_name(ob)) + TARGETS_SOURCE_ID_SUFFIX;
|
2013-02-04 00:18:09 +00:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::IdRefSource source(mSW);
|
|
|
|
source.setId(source_id);
|
|
|
|
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
|
|
|
source.setAccessorCount(key->totkey - 1);
|
|
|
|
source.setAccessorStride(1);
|
|
|
|
|
|
|
|
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
|
|
|
param.push_back("IDREF");
|
|
|
|
|
|
|
|
source.prepareToAppendValues();
|
|
|
|
|
2013-03-18 11:44:56 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)key->block.first;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* skip the basis */
|
2013-01-21 13:45:49 +00:00
|
|
|
kb = kb->next;
|
|
|
|
for (; kb; kb = kb->next) {
|
|
|
|
std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name);
|
2018-03-17 14:16:19 +01:00
|
|
|
source.appendValues(geom_id);
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source.finish();
|
|
|
|
|
|
|
|
return source_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::add_morph_weights(Key *key, Object *ob)
|
|
|
|
{
|
|
|
|
std::string source_id = translate_id(id_name(ob)) + WEIGHTS_SOURCE_ID_SUFFIX;
|
|
|
|
|
|
|
|
COLLADASW::FloatSourceF source(mSW);
|
|
|
|
source.setId(source_id);
|
|
|
|
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
|
|
|
source.setAccessorCount(key->totkey - 1);
|
|
|
|
source.setAccessorStride(1);
|
2013-02-04 00:18:09 +00:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
|
|
|
param.push_back("MORPH_WEIGHT");
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
source.prepareToAppendValues();
|
|
|
|
|
2013-03-18 11:44:56 +00:00
|
|
|
KeyBlock *kb = (KeyBlock *)key->block.first;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* skip the basis */
|
2013-01-21 13:45:49 +00:00
|
|
|
kb = kb->next;
|
|
|
|
for (; kb; kb = kb->next) {
|
|
|
|
float weight = kb->curval;
|
|
|
|
source.appendValues(weight);
|
|
|
|
}
|
|
|
|
source.finish();
|
|
|
|
|
|
|
|
return source_id;
|
|
|
|
}
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* Added to implement support for animations. */
|
2013-02-10 17:06:05 +00:00
|
|
|
void ControllerExporter::add_weight_extras(Key *key)
|
|
|
|
{
|
2019-04-30 13:41:21 +10:00
|
|
|
/* can also try the base element and param alternative */
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::BaseExtraTechnique extra;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-11 08:49:28 +11:00
|
|
|
KeyBlock *kb = (KeyBlock *)key->block.first;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* skip the basis */
|
2013-01-21 13:45:49 +00:00
|
|
|
kb = kb->next;
|
|
|
|
for (; kb; kb = kb->next) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* XXX why is the weight not used here and set to 0.0?
|
|
|
|
* float weight = kb->curval; */
|
2013-01-21 13:45:49 +00:00
|
|
|
extra.addExtraTechniqueParameter("KHR", "morph_weights", 0.000, "MORPH_WEIGHT_TO_TARGET");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::add_joints_element(ListBase *defbase,
|
|
|
|
const std::string &joints_source_id,
|
|
|
|
const std::string &inv_bind_mat_source_id)
|
|
|
|
{
|
|
|
|
COLLADASW::JointsElement joints(mSW);
|
|
|
|
COLLADASW::InputList &input = joints.getInputList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
input.push_back(COLLADASW::Input(
|
|
|
|
COLLADASW::InputSemantic::JOINT, /* constant declared in COLLADASWInputList.h */
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id)));
|
|
|
|
input.push_back(
|
|
|
|
COLLADASW::Input(COLLADASW::InputSemantic::BINDMATRIX,
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, inv_bind_mat_source_id)));
|
|
|
|
joints.add();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::add_bind_shape_mat(Object *ob)
|
|
|
|
{
|
|
|
|
double bind_mat[4][4];
|
2018-11-26 23:14:25 +01:00
|
|
|
float f_obmat[4][4];
|
|
|
|
BKE_object_matrix_local_get(ob, f_obmat);
|
|
|
|
|
2019-05-23 12:17:17 +02:00
|
|
|
if (export_settings.get_apply_global_orientation()) {
|
|
|
|
/* do nothing, rotation is going to be applied to the Data */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bc_add_global_transform(f_obmat, export_settings.get_global_transform());
|
|
|
|
}
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
// UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat);
|
2018-11-26 23:14:25 +01:00
|
|
|
UnitConverter::mat4_to_dae_double(bind_mat, f_obmat);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (this->export_settings.get_limit_precision()) {
|
2019-06-04 10:51:48 +10:00
|
|
|
BCMatrix::sanitize(bind_mat, LIMITTED_PRECISION);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
|
|
|
|
addBindShapeTransform(bind_mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::add_joints_source(Object *ob_arm,
|
|
|
|
ListBase *defbase,
|
|
|
|
const std::string &controller_id)
|
|
|
|
{
|
|
|
|
std::string source_id = controller_id + JOINTS_SOURCE_ID_SUFFIX;
|
|
|
|
|
|
|
|
int totjoint = 0;
|
|
|
|
bDeformGroup *def;
|
|
|
|
for (def = (bDeformGroup *)defbase->first; def; def = def->next) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_bone_defgroup(ob_arm, def)) {
|
2013-01-21 13:45:49 +00:00
|
|
|
totjoint++;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::NameSource source(mSW);
|
|
|
|
source.setId(source_id);
|
|
|
|
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
|
|
|
source.setAccessorCount(totjoint);
|
|
|
|
source.setAccessorStride(1);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
|
|
|
param.push_back("JOINT");
|
|
|
|
|
|
|
|
source.prepareToAppendValues();
|
|
|
|
|
|
|
|
for (def = (bDeformGroup *)defbase->first; def; def = def->next) {
|
|
|
|
Bone *bone = get_bone_from_defgroup(ob_arm, def);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (bone) {
|
2018-03-17 14:16:19 +01:00
|
|
|
source.appendValues(get_joint_sid(bone));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source.finish();
|
|
|
|
|
|
|
|
return source_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm,
|
|
|
|
ListBase *defbase,
|
|
|
|
const std::string &controller_id)
|
|
|
|
{
|
|
|
|
std::string source_id = controller_id + BIND_POSES_SOURCE_ID_SUFFIX;
|
|
|
|
|
|
|
|
int totjoint = 0;
|
|
|
|
for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_bone_defgroup(ob_arm, def)) {
|
2013-01-21 13:45:49 +00:00
|
|
|
totjoint++;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COLLADASW::FloatSourceF source(mSW);
|
|
|
|
source.setId(source_id);
|
|
|
|
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
2019-04-30 13:41:21 +10:00
|
|
|
source.setAccessorCount(totjoint); // BLI_listbase_count(defbase));
|
2013-01-21 13:45:49 +00:00
|
|
|
source.setAccessorStride(16);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
source.setParameterTypeName(&COLLADASW::CSWC::CSW_VALUE_TYPE_FLOAT4x4);
|
|
|
|
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
|
|
|
param.push_back("TRANSFORM");
|
|
|
|
|
|
|
|
source.prepareToAppendValues();
|
|
|
|
|
|
|
|
bPose *pose = ob_arm->pose;
|
|
|
|
bArmature *arm = (bArmature *)ob_arm->data;
|
|
|
|
|
|
|
|
int flag = arm->flag;
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* put armature in rest position */
|
2013-01-21 13:45:49 +00:00
|
|
|
if (!(arm->flag & ARM_RESTPOS)) {
|
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();
|
|
|
|
Scene *scene = blender_context.get_scene();
|
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
arm->flag |= ARM_RESTPOS;
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_pose_where_is(depsgraph, scene, ob_arm);
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) {
|
|
|
|
if (is_bone_defgroup(ob_arm, def)) {
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(pose, def->name);
|
|
|
|
|
|
|
|
float mat[4][4];
|
|
|
|
float world[4][4];
|
|
|
|
float inv_bind_mat[4][4];
|
|
|
|
|
2017-03-23 12:53:56 +01:00
|
|
|
float bind_mat[4][4]; /* derived from bone->arm_mat */
|
|
|
|
|
|
|
|
bool has_bindmat = bc_get_property_matrix(pchan->bone, "bind_mat", bind_mat);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2017-03-23 12:53:56 +01:00
|
|
|
if (!has_bindmat) {
|
2014-02-19 13:44:28 +01:00
|
|
|
|
2017-03-23 12:53:56 +01:00
|
|
|
/* Have no bind matrix stored, try old style <= Blender 2.78 */
|
|
|
|
|
|
|
|
bc_create_restpose_mat(
|
|
|
|
this->export_settings, pchan->bone, bind_mat, pchan->bone->arm_mat, true);
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* SL/OPEN_SIM COMPATIBILITY */
|
2019-05-23 12:17:17 +02:00
|
|
|
if (export_settings.get_open_sim()) {
|
2017-03-23 12:53:56 +01:00
|
|
|
float loc[3];
|
|
|
|
float rot[3] = {0, 0, 0};
|
|
|
|
float scale[3];
|
|
|
|
bc_decompose(bind_mat, loc, nullptr, nullptr, scale);
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* Only translations, no rotation vs armature */
|
2017-03-23 12:53:56 +01:00
|
|
|
loc_eulO_size_to_mat4(bind_mat, loc, rot, scale, 6);
|
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* make world-space matrix (bind_mat is armature-space) */
|
2017-03-23 12:53:56 +01:00
|
|
|
mul_m4_m4m4(world, ob_arm->obmat, bind_mat);
|
2014-02-18 21:53:25 +01:00
|
|
|
|
2019-05-23 22:27:45 +02:00
|
|
|
if (!has_bindmat) {
|
|
|
|
if (export_settings.get_apply_global_orientation()) {
|
|
|
|
bc_apply_global_transform(world, export_settings.get_global_transform());
|
|
|
|
}
|
2019-05-23 12:17:17 +02:00
|
|
|
}
|
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
invert_m4_m4(mat, world);
|
2018-11-24 14:24:36 +01:00
|
|
|
UnitConverter::mat4_to_dae(inv_bind_mat, mat);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (this->export_settings.get_limit_precision()) {
|
2019-05-28 09:23:05 +02:00
|
|
|
BCMatrix::sanitize(inv_bind_mat, LIMITTED_PRECISION);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-01-21 13:45:49 +00:00
|
|
|
source.appendValues(inv_bind_mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* back from rest position */
|
2013-01-21 13:45:49 +00:00
|
|
|
if (!(flag & ARM_RESTPOS)) {
|
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();
|
|
|
|
Scene *scene = blender_context.get_scene();
|
2013-01-21 13:45:49 +00:00
|
|
|
arm->flag = flag;
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_pose_where_is(depsgraph, scene, ob_arm);
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
source.finish();
|
|
|
|
|
|
|
|
return source_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bone *ControllerExporter::get_bone_from_defgroup(Object *ob_arm, bDeformGroup *def)
|
|
|
|
{
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, def->name);
|
|
|
|
return pchan ? pchan->bone : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ControllerExporter::is_bone_defgroup(Object *ob_arm, bDeformGroup *def)
|
|
|
|
{
|
|
|
|
return get_bone_from_defgroup(ob_arm, def) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ControllerExporter::add_weights_source(Mesh *me,
|
|
|
|
const std::string &controller_id,
|
|
|
|
const std::list<float> &weights)
|
|
|
|
{
|
|
|
|
std::string source_id = controller_id + WEIGHTS_SOURCE_ID_SUFFIX;
|
|
|
|
|
|
|
|
COLLADASW::FloatSourceF source(mSW);
|
|
|
|
source.setId(source_id);
|
|
|
|
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
|
|
|
source.setAccessorCount(weights.size());
|
|
|
|
source.setAccessorStride(1);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
|
|
|
param.push_back("WEIGHT");
|
|
|
|
|
|
|
|
source.prepareToAppendValues();
|
|
|
|
|
2019-09-08 03:31:49 +10:00
|
|
|
for (std::list<float>::const_iterator i = weights.begin(); i != weights.end(); ++i) {
|
2013-01-21 13:45:49 +00:00
|
|
|
source.appendValues(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
source.finish();
|
|
|
|
|
|
|
|
return source_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerExporter::add_vertex_weights_element(const std::string &weights_source_id,
|
|
|
|
const std::string &joints_source_id,
|
|
|
|
const std::list<int> &vcounts,
|
|
|
|
const std::list<int> &joints)
|
|
|
|
{
|
|
|
|
COLLADASW::VertexWeightsElement weightselem(mSW);
|
|
|
|
COLLADASW::InputList &input = weightselem.getInputList();
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
input.push_back(COLLADASW::Input(
|
|
|
|
COLLADASW::InputSemantic::JOINT, /* constant declared in COLLADASWInputList.h */
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id),
|
|
|
|
offset++));
|
|
|
|
input.push_back(
|
|
|
|
COLLADASW::Input(COLLADASW::InputSemantic::WEIGHT,
|
|
|
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, weights_source_id),
|
|
|
|
offset++));
|
|
|
|
|
|
|
|
weightselem.setCount(vcounts.size());
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* write number of deformers per vertex */
|
2013-01-21 13:45:49 +00:00
|
|
|
COLLADASW::PrimitivesBase::VCountList vcountlist;
|
|
|
|
|
|
|
|
vcountlist.resize(vcounts.size());
|
|
|
|
std::copy(vcounts.begin(), vcounts.end(), vcountlist.begin());
|
|
|
|
|
|
|
|
weightselem.prepareToAppendVCountValues();
|
|
|
|
weightselem.appendVertexCount(vcountlist);
|
|
|
|
|
|
|
|
weightselem.CloseVCountAndOpenVElement();
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* write deformer index - weight index pairs */
|
2013-01-21 13:45:49 +00:00
|
|
|
int weight_index = 0;
|
2019-09-08 03:31:49 +10:00
|
|
|
for (std::list<int>::const_iterator i = joints.begin(); i != joints.end(); ++i) {
|
2013-01-21 13:45:49 +00:00
|
|
|
weightselem.appendValues(*i, weight_index++);
|
|
|
|
}
|
|
|
|
|
|
|
|
weightselem.finish();
|
|
|
|
}
|