2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2010-2023 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup collada
|
2011-02-27 20:30:35 +00:00
|
|
|
*/
|
|
|
|
|
|
2020-12-04 11:28:09 +01:00
|
|
|
#include <cstddef>
|
2011-02-27 20:30:35 +00:00
|
|
|
|
2025-01-26 20:08:04 +01:00
|
|
|
#include "COLLADAFWAnimation.h"
|
|
|
|
|
#include "COLLADAFWAnimationCurve.h"
|
|
|
|
|
#include "COLLADAFWAnimationList.h"
|
|
|
|
|
#include "COLLADAFWCamera.h"
|
|
|
|
|
#include "COLLADAFWEffect.h"
|
|
|
|
|
#include "COLLADAFWLight.h"
|
|
|
|
|
#include "COLLADAFWNode.h"
|
|
|
|
|
#include "COLLADAFWRotate.h"
|
|
|
|
|
#include "COLLADAFWUniqueId.h"
|
2011-02-12 06:25:04 +00:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_keyframing.hh"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
#include "ANIM_action.hh"
|
|
|
|
|
#include "ANIM_action_legacy.hh"
|
2023-12-14 10:17:18 +01:00
|
|
|
#include "ANIM_animdata.hh"
|
2023-11-07 14:33:52 +01:00
|
|
|
#include "ANIM_fcurve.hh"
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "BLI_string.h"
|
2013-03-25 08:29:06 +00:00
|
|
|
|
2024-09-10 14:55:47 +02:00
|
|
|
#include "BKE_action.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_armature.hh"
|
2024-03-05 18:39:08 +01:00
|
|
|
#include "BKE_fcurve.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#include "AnimationImporter.h"
|
|
|
|
|
#include "ArmatureImporter.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "collada_utils.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* first try node name, if not available (since is optional), fall back to original id */
|
2010-10-05 00:05:14 +00:00
|
|
|
template<class T> static const char *bc_get_joint_name(T *node)
|
|
|
|
|
{
|
2011-06-20 12:43:10 +00:00
|
|
|
const std::string &id = node->getName();
|
2020-07-03 14:59:27 +02:00
|
|
|
return id.empty() ? node->getOriginalId().c_str() : id.c_str();
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
/**
|
|
|
|
|
* Ensures that the given ID has an action assigned to it and, for layered
|
|
|
|
|
* actions, an assigned slot.
|
|
|
|
|
*/
|
|
|
|
|
static void ensure_action_and_slot_for_id(Main *bmain, ID &id)
|
|
|
|
|
{
|
|
|
|
|
bAction *dna_action = blender::animrig::id_action_ensure(bmain, &id);
|
|
|
|
|
BLI_assert(dna_action != nullptr);
|
|
|
|
|
|
|
|
|
|
if (blender::animrig::legacy::action_treat_as_legacy(*dna_action)) {
|
|
|
|
|
/* We don't ensure a slot for legacy actions, since they don't have slots. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blender::animrig::Action &action = dna_action->wrap();
|
|
|
|
|
blender::animrig::Slot *slot = blender::animrig::assign_action_ensure_slot_for_keying(action,
|
|
|
|
|
id);
|
|
|
|
|
BLI_assert(slot != nullptr);
|
|
|
|
|
UNUSED_VARS_NDEBUG(slot);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path)
|
|
|
|
|
{
|
2020-06-05 08:41:09 +02:00
|
|
|
FCurve *fcu = BKE_fcurve_create();
|
2021-08-26 12:27:16 +10:00
|
|
|
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
|
2010-10-05 00:05:14 +00:00
|
|
|
fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path));
|
|
|
|
|
fcu->array_index = array_index;
|
|
|
|
|
return fcu;
|
|
|
|
|
}
|
2018-03-11 12:44:02 +01:00
|
|
|
|
|
|
|
|
void AnimationImporter::add_bezt(FCurve *fcu,
|
|
|
|
|
float frame,
|
|
|
|
|
float value,
|
|
|
|
|
eBezTriple_Interpolation ipo)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2022-09-25 18:33:28 +10:00
|
|
|
// float fps = float(FPS);
|
2010-10-05 00:05:14 +00:00
|
|
|
BezTriple bez;
|
|
|
|
|
memset(&bez, 0, sizeof(BezTriple));
|
|
|
|
|
bez.vec[1][0] = frame;
|
2018-03-11 12:44:02 +01:00
|
|
|
bez.vec[1][1] = value;
|
|
|
|
|
bez.ipo = ipo; /* use default interpolation mode here... */
|
2010-10-05 00:05:14 +00:00
|
|
|
bez.f1 = bez.f2 = bez.f3 = SELECT;
|
|
|
|
|
bez.h1 = bez.h2 = HD_AUTO;
|
2023-11-07 14:33:52 +01:00
|
|
|
blender::animrig::insert_bezt_fcurve(fcu, &bez, INSERTKEY_NOFLAGS);
|
2022-07-14 10:22:30 +02:00
|
|
|
BKE_fcurve_handles_recalc(fcu);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
|
|
|
|
|
{
|
|
|
|
|
COLLADAFW::FloatOrDoubleArray &input = curve->getInputValues();
|
|
|
|
|
COLLADAFW::FloatOrDoubleArray &output = curve->getOutputValues();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
float fps = float(FPS);
|
2010-10-05 00:05:14 +00:00
|
|
|
size_t dim = curve->getOutDimension();
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *> &fcurves = curve_map[curve->getUniqueId()];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
switch (dim) {
|
2019-04-30 13:41:21 +10:00
|
|
|
case 1: /* X, Y, Z or angle */
|
|
|
|
|
case 3: /* XYZ */
|
2012-06-12 22:05:33 +00:00
|
|
|
case 4:
|
2019-04-30 13:41:21 +10:00
|
|
|
case 16: /* matrix */
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
for (i = 0; i < dim; i++) {
|
2020-06-05 08:41:09 +02:00
|
|
|
FCurve *fcu = BKE_fcurve_create();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-26 12:27:16 +10:00
|
|
|
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
|
2010-10-05 00:05:14 +00:00
|
|
|
fcu->array_index = 0;
|
2019-10-01 21:38:44 +03:00
|
|
|
fcu->auto_smoothing = U.auto_smoothing_new;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < curve->getKeyCount(); j++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
BezTriple bez;
|
|
|
|
|
memset(&bez, 0, sizeof(BezTriple));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* input, output */
|
2018-06-08 08:07:48 +02:00
|
|
|
bez.vec[1][0] = bc_get_float_value(input, j) * fps;
|
2010-10-05 00:05:14 +00:00
|
|
|
bez.vec[1][1] = bc_get_float_value(output, j * dim + 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
|
|
|
bez.h1 = bez.h2 = HD_AUTO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
|
|
|
|
|
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP)
|
|
|
|
|
{
|
2011-06-14 20:42:01 +00:00
|
|
|
COLLADAFW::FloatOrDoubleArray &intan = curve->getInTangentValues();
|
2011-09-04 00:15:59 +00:00
|
|
|
COLLADAFW::FloatOrDoubleArray &outtan = curve->getOutTangentValues();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* In-tangent. */
|
2022-09-25 17:04:52 +10:00
|
|
|
uint index = 2 * (j * dim + i);
|
2019-11-27 10:47:39 +01:00
|
|
|
bez.vec[0][0] = bc_get_float_value(intan, index) * fps;
|
|
|
|
|
bez.vec[0][1] = bc_get_float_value(intan, index + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Out-tangent. */
|
2019-11-27 10:47:39 +01:00
|
|
|
bez.vec[2][0] = bc_get_float_value(outtan, index) * fps;
|
|
|
|
|
bez.vec[2][1] = bc_get_float_value(outtan, index + 1);
|
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 (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) {
|
2011-08-14 16:14:32 +00:00
|
|
|
bez.ipo = BEZT_IPO_BEZ;
|
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
|
|
|
bez.h1 = bez.h2 = HD_AUTO_ANIM;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-09-04 00:15:59 +00:00
|
|
|
bez.ipo = BEZT_IPO_CONST;
|
2019-04-17 06:17:24 +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
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
2011-06-14 20:42:01 +00:00
|
|
|
bez.ipo = BEZT_IPO_LIN;
|
|
|
|
|
}
|
2019-04-30 13:41:21 +10:00
|
|
|
#if 0
|
|
|
|
|
bez.ipo = U.ipo_new; /* use default interpolation mode here... */
|
|
|
|
|
#endif
|
2010-10-05 00:05:14 +00:00
|
|
|
bez.f1 = bez.f2 = bez.f3 = SELECT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-07 14:33:52 +01:00
|
|
|
blender::animrig::insert_bezt_fcurve(fcu, &bez, INSERTKEY_NOFLAGS);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-14 10:22:30 +02:00
|
|
|
BKE_fcurve_handles_recalc(fcu);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
fcurves.push_back(fcu);
|
2015-09-11 18:41:35 +10:00
|
|
|
unused_curves.push_back(fcu);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Output dimension of %d is not yet supported (animation id = %s)\n",
|
2022-09-25 18:33:28 +10:00
|
|
|
int(dim),
|
2012-06-12 22:05:33 +00:00
|
|
|
curve->getOriginalId().c_str());
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationImporter::fcurve_deg_to_rad(FCurve *cu)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < cu->totvert; i++) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: convert handles too. */
|
2011-09-17 09:43:51 +00:00
|
|
|
cu->bezt[i].vec[1][1] *= DEG2RADF(1.0f);
|
|
|
|
|
cu->bezt[i].vec[0][1] *= DEG2RADF(1.0f);
|
|
|
|
|
cu->bezt[i].vec[2][1] *= DEG2RADF(1.0f);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 19:06:14 +02:00
|
|
|
void AnimationImporter::fcurve_scale(FCurve *cu, int scale)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < cu->totvert; i++) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: convert handles too. */
|
2019-06-02 19:06:14 +02:00
|
|
|
cu->bezt[i].vec[1][1] *= scale;
|
|
|
|
|
cu->bezt[i].vec[0][1] *= scale;
|
|
|
|
|
cu->bezt[i].vec[2][1] *= scale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 18:41:35 +10:00
|
|
|
void AnimationImporter::fcurve_is_used(FCurve *fcu)
|
|
|
|
|
{
|
|
|
|
|
unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu),
|
|
|
|
|
unused_curves.end());
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
AnimationImporter::~AnimationImporter()
|
|
|
|
|
{
|
2019-04-30 13:41:21 +10:00
|
|
|
/* free unused FCurves */
|
2020-12-07 12:21:11 +01:00
|
|
|
for (FCurve *unused_curve : unused_curves) {
|
|
|
|
|
BKE_fcurve_free(unused_curve);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2020-07-03 14:59:27 +02:00
|
|
|
if (!unused_curves.empty()) {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "removed %d unused curves\n", int(unused_curves.size()));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
bool AnimationImporter::write_animation(const COLLADAFW::Animation *anim)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
if (anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) {
|
2012-06-12 22:05:33 +00:00
|
|
|
COLLADAFW::AnimationCurve *curve = (COLLADAFW::AnimationCurve *)anim;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* XXX Don't know if it's necessary
|
|
|
|
|
* Should we check outPhysicalDimension? */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) {
|
2012-03-31 00:59:17 +00:00
|
|
|
fprintf(stderr, "Inputs physical dimension is not time.\n");
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* a curve can have mixed interpolation type,
|
|
|
|
|
* in this case curve->getInterpolationTypes returns a list of interpolation types per key */
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::AnimationCurve::InterpolationType interp = curve->getInterpolationType();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (interp != COLLADAFW::AnimationCurve::INTERPOLATION_MIXED) {
|
|
|
|
|
switch (interp) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
|
|
|
|
|
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
|
|
|
|
|
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
|
|
|
|
|
animation_to_fcurves(curve);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: there are also CARDINAL, HERMITE, BSPLINE and STEP types. */
|
2012-06-12 22:05:33 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"CARDINAL, HERMITE and BSPLINE anim interpolation types not supported yet.\n");
|
|
|
|
|
break;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* not supported yet */
|
2010-10-05 00:05:14 +00:00
|
|
|
fprintf(stderr, "MIXED anim interpolation type is not supported yet.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stderr, "FORMULA animation type is not supported yet.\n");
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList *animlist)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
const COLLADAFW::UniqueId &animlist_id = animlist->getUniqueId();
|
|
|
|
|
animlist_map[animlist_id] = animlist;
|
2011-09-04 00:15:59 +00:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#if 0
|
2011-06-14 20:42:01 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* should not happen */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (uid_animated_map.find(animlist_id) == uid_animated_map.end()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-09-04 00:15:59 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for bones rna_path is like: pose.bones["bone-name"].rotation */
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#endif
|
2011-09-04 00:15:59 +00:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationImporter::read_node_transform(COLLADAFW::Node *node, Object *ob)
|
|
|
|
|
{
|
|
|
|
|
float mat[4][4];
|
|
|
|
|
TransformReader::get_node_mat(mat, node, &uid_animated_map, ob);
|
|
|
|
|
if (ob) {
|
2024-02-14 16:14:49 +01:00
|
|
|
copy_m4_m4(ob->runtime->object_to_world.ptr(), mat);
|
|
|
|
|
BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), false, false);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::modify_fcurve(std::vector<FCurve *> *curves,
|
|
|
|
|
const char *rna_path,
|
2019-06-02 19:06:14 +02:00
|
|
|
int array_index,
|
|
|
|
|
int scale)
|
2011-09-04 00:15:59 +00:00
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *>::iterator it;
|
2011-06-14 20:42:01 +00:00
|
|
|
int i;
|
|
|
|
|
for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) {
|
|
|
|
|
FCurve *fcu = *it;
|
2011-08-26 15:16:27 +00:00
|
|
|
fcu->rna_path = BLI_strdup(rna_path);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (array_index == -1) {
|
2011-06-14 20:42:01 +00:00
|
|
|
fcu->array_index = i;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-06-14 20:42:01 +00:00
|
|
|
fcu->array_index = array_index;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-02 19:06:14 +02:00
|
|
|
if (scale != 1) {
|
|
|
|
|
fcurve_scale(fcu, scale);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 18:41:35 +10:00
|
|
|
fcurve_is_used(fcu);
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::unused_fcurve(std::vector<FCurve *> *curves)
|
2012-05-02 18:11:09 +00:00
|
|
|
{
|
2019-04-30 13:41:21 +10:00
|
|
|
/* when an error happens and we can't actually use curve remove it from unused_curves */
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *>::iterator it;
|
2012-05-02 18:11:09 +00:00
|
|
|
for (it = curves->begin(); it != curves->end(); it++) {
|
|
|
|
|
FCurve *fcu = *it;
|
2015-09-11 18:41:35 +10:00
|
|
|
fcurve_is_used(fcu);
|
2012-05-02 18:11:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::find_frames(std::vector<float> *frames, std::vector<FCurve *> *curves)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *>::iterator iter;
|
2011-09-04 00:15:59 +00:00
|
|
|
for (iter = curves->begin(); iter != curves->end(); iter++) {
|
|
|
|
|
FCurve *fcu = *iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint k = 0; k < fcu->totvert; k++) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* get frame value from bezTriple */
|
2011-09-04 00:15:59 +00:00
|
|
|
float fra = fcu->bezt[k].vec[1][0];
|
2019-04-30 13:41:21 +10:00
|
|
|
/* if frame already not added add frame to frames */
|
2019-05-31 22:51:19 +10:00
|
|
|
if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
|
2011-09-04 00:15:59 +00:00
|
|
|
frames->push_back(fra);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2011-09-04 00:15:59 +00:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-27 11:18:10 +01:00
|
|
|
static int get_animation_axis_index(const COLLADABU::Math::Vector3 &axis)
|
|
|
|
|
{
|
|
|
|
|
int index;
|
|
|
|
|
if (COLLADABU::Math::Vector3::UNIT_X == axis) {
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
|
|
|
|
|
index = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
|
|
|
|
|
index = 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
index = -1;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::Assign_transform_animations(
|
|
|
|
|
COLLADAFW::Transformation *transform,
|
|
|
|
|
const COLLADAFW::AnimationList::AnimationBinding *binding,
|
|
|
|
|
std::vector<FCurve *> *curves,
|
|
|
|
|
bool is_joint,
|
|
|
|
|
char *joint_path)
|
2011-06-14 20:42:01 +00:00
|
|
|
{
|
|
|
|
|
COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
|
2010-10-05 00:05:14 +00:00
|
|
|
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
|
2012-06-23 23:22:19 +00:00
|
|
|
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* to check if the no of curves are valid */
|
2022-09-26 13:58:49 +10:00
|
|
|
bool xyz =
|
|
|
|
|
(ELEM(tm_type, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::SCALE) &&
|
|
|
|
|
binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-14 20:42:01 +00:00
|
|
|
if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, int(curves->size()));
|
2011-06-14 20:42:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
char rna_path[100];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-14 20:42:01 +00:00
|
|
|
switch (tm_type) {
|
|
|
|
|
case COLLADAFW::Transformation::TRANSLATE:
|
|
|
|
|
case COLLADAFW::Transformation::SCALE: {
|
2012-06-12 22:05:33 +00:00
|
|
|
bool loc = tm_type == COLLADAFW::Transformation::TRANSLATE;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(rna_path, "%s.%s", joint_path, loc ? "location" : "scale");
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, loc ? "location" : "scale");
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
switch (binding->animationClass) {
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_X:
|
|
|
|
|
modify_fcurve(curves, rna_path, 0);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_Y:
|
|
|
|
|
modify_fcurve(curves, rna_path, 1);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_Z:
|
|
|
|
|
modify_fcurve(curves, rna_path, 2);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_XYZ:
|
|
|
|
|
modify_fcurve(curves, rna_path, -1);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
unused_fcurve(curves);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"AnimationClass %d is not supported for %s.\n",
|
|
|
|
|
binding->animationClass,
|
|
|
|
|
loc ? "TRANSLATE" : "SCALE");
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-14 20:42:01 +00:00
|
|
|
case COLLADAFW::Transformation::ROTATE: {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(rna_path, "%s.rotation_euler", joint_path);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, "rotation_euler");
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *>::iterator iter;
|
|
|
|
|
for (iter = curves->begin(); iter != curves->end(); iter++) {
|
|
|
|
|
FCurve *fcu = *iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* if transform is rotation the fcurves values must be turned in to radian. */
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_rotation) {
|
2012-06-12 22:05:33 +00:00
|
|
|
fcurve_deg_to_rad(fcu);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-09-04 00:15:59 +00:00
|
|
|
}
|
2024-07-22 09:58:43 +10:00
|
|
|
const COLLADAFW::Rotate *rot = (COLLADAFW::Rotate *)transform;
|
|
|
|
|
const COLLADABU::Math::Vector3 &axis = rot->getRotationAxis();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
switch (binding->animationClass) {
|
2019-11-27 11:18:10 +01:00
|
|
|
case COLLADAFW::AnimationList::ANGLE: {
|
|
|
|
|
int axis_index = get_animation_axis_index(axis);
|
|
|
|
|
if (axis_index >= 0) {
|
|
|
|
|
modify_fcurve(curves, rna_path, axis_index);
|
2012-06-12 22:05:33 +00:00
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
else {
|
2012-06-12 22:05:33 +00:00
|
|
|
unused_fcurve(curves);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::AnimationList::AXISANGLE:
|
2024-05-07 12:59:13 +10:00
|
|
|
/* TODO: convert axis-angle to quaternion? or XYZ? */
|
2012-06-12 22:05:33 +00:00
|
|
|
default:
|
|
|
|
|
unused_fcurve(curves);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"AnimationClass %d is not supported for ROTATE transformation.\n",
|
|
|
|
|
binding->animationClass);
|
2011-09-04 00:15:59 +00:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
break;
|
2012-06-12 22:05:33 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-14 20:42:01 +00:00
|
|
|
case COLLADAFW::Transformation::MATRIX:
|
2018-04-16 17:08:27 +02:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
{
|
|
|
|
|
COLLADAFW::Matrix *mat = (COLLADAFW::Matrix *)transform;
|
|
|
|
|
COLLADABU::Math::Matrix4 mat4 = mat->getMatrix();
|
|
|
|
|
switch (binding->animationClass) {
|
|
|
|
|
case COLLADAFW::AnimationList::TRANSFORM:
|
2018-04-16 17:08:27 +02:00
|
|
|
}
|
2019-04-17 08:24:14 +02:00
|
|
|
}
|
2018-04-16 17:08:27 +02:00
|
|
|
#endif
|
2012-05-02 18:11:09 +00:00
|
|
|
unused_fcurve(curves);
|
2011-08-17 18:29:01 +00:00
|
|
|
break;
|
2011-06-14 20:42:01 +00:00
|
|
|
case COLLADAFW::Transformation::SKEW:
|
|
|
|
|
case COLLADAFW::Transformation::LOOKAT:
|
2012-05-02 18:11:09 +00:00
|
|
|
unused_fcurve(curves);
|
2011-08-17 18:29:01 +00:00
|
|
|
fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n");
|
2011-06-14 20:42:01 +00:00
|
|
|
break;
|
2011-09-04 00:15:59 +00:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::Assign_color_animations(const COLLADAFW::UniqueId &listid,
|
2024-10-07 16:49:54 +02:00
|
|
|
AnimData &adt,
|
2012-06-12 22:05:33 +00:00
|
|
|
const char *anim_type)
|
2011-07-03 17:26:02 +00:00
|
|
|
{
|
2024-10-07 16:49:54 +02:00
|
|
|
BLI_assert(adt.action != nullptr);
|
|
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
char rna_path[100];
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, anim_type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-27 17:43:32 +00:00
|
|
|
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
2020-11-06 17:49:09 +01:00
|
|
|
if (animlist == nullptr) {
|
2018-04-06 12:42:38 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Collada: No animlist found for ID: %s of type %s\n",
|
|
|
|
|
listid.toAscii().c_str(),
|
|
|
|
|
anim_type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-27 17:43:32 +00:00
|
|
|
const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
|
2019-04-30 13:41:21 +10:00
|
|
|
/* all the curves belonging to the current binding */
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *> animcurves;
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < bindings.getCount(); j++) {
|
2011-09-04 00:15:59 +00:00
|
|
|
animcurves = curve_map[bindings[j].animation];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-04 00:15:59 +00:00
|
|
|
switch (bindings[j].animationClass) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::AnimationList::COLOR_R:
|
|
|
|
|
modify_fcurve(&animcurves, rna_path, 0);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::COLOR_G:
|
|
|
|
|
modify_fcurve(&animcurves, rna_path, 1);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::COLOR_B:
|
|
|
|
|
modify_fcurve(&animcurves, rna_path, 2);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::COLOR_RGB:
|
2019-04-30 13:41:21 +10:00
|
|
|
case COLLADAFW::AnimationList::COLOR_RGBA: /* to do-> set intensity */
|
2012-06-12 22:05:33 +00:00
|
|
|
modify_fcurve(&animcurves, rna_path, -1);
|
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
default:
|
|
|
|
|
unused_fcurve(&animcurves);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"AnimationClass %d is not supported for %s.\n",
|
|
|
|
|
bindings[j].animationClass,
|
|
|
|
|
"COLOR");
|
2011-07-03 17:26:02 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *>::iterator iter;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* Add the curves of the current animation to the object */
|
2011-07-27 17:43:32 +00:00
|
|
|
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
2012-06-12 22:05:33 +00:00
|
|
|
FCurve *fcu = *iter;
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
adt.action->wrap(), adt.slot_handle, *fcu, std::nullopt);
|
2015-09-11 18:41:35 +10:00
|
|
|
fcurve_is_used(fcu);
|
2011-09-25 12:31:21 +00:00
|
|
|
}
|
2011-07-27 17:43:32 +00:00
|
|
|
}
|
2011-07-03 17:26:02 +00:00
|
|
|
}
|
2011-07-04 19:30:58 +00:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void AnimationImporter::Assign_float_animations(const COLLADAFW::UniqueId &listid,
|
2024-10-07 16:49:54 +02:00
|
|
|
AnimData &adt,
|
2012-06-12 22:05:33 +00:00
|
|
|
const char *anim_type)
|
2011-07-04 19:30:58 +00:00
|
|
|
{
|
2024-10-07 16:49:54 +02:00
|
|
|
BLI_assert(adt.action != nullptr);
|
|
|
|
|
|
2011-07-04 19:30:58 +00:00
|
|
|
char rna_path[100];
|
2012-02-27 10:35:39 +00:00
|
|
|
if (animlist_map.find(listid) == animlist_map.end()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
|
|
|
|
|
/* anim_type has animations */
|
|
|
|
|
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
|
|
|
|
const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
|
|
|
|
|
/* all the curves belonging to the current binding */
|
|
|
|
|
std::vector<FCurve *> animcurves;
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < bindings.getCount(); j++) {
|
2020-08-07 12:40:12 +02:00
|
|
|
animcurves = curve_map[bindings[j].animation];
|
|
|
|
|
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, anim_type);
|
2020-08-07 12:40:12 +02:00
|
|
|
modify_fcurve(&animcurves, rna_path, 0);
|
|
|
|
|
std::vector<FCurve *>::iterator iter;
|
|
|
|
|
/* Add the curves of the current animation to the object */
|
|
|
|
|
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
|
|
|
|
FCurve *fcu = *iter;
|
|
|
|
|
/* All anim_types whose values are to be converted from Degree to Radians can be ORed here
|
|
|
|
|
*/
|
|
|
|
|
if (STREQ("spot_size", anim_type)) {
|
|
|
|
|
/* NOTE: Do NOT convert if imported file was made by blender <= 2.69.10
|
|
|
|
|
* Reason: old blender versions stored spot_size in radians (was a bug)
|
2019-04-30 13:41:21 +10:00
|
|
|
*/
|
2020-08-07 12:40:12 +02:00
|
|
|
if (this->import_from_version.empty() ||
|
|
|
|
|
BLI_strcasecmp_natural(this->import_from_version.c_str(), "2.69.10") != -1)
|
|
|
|
|
{
|
|
|
|
|
fcurve_deg_to_rad(fcu);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-07-05 18:02:08 +00:00
|
|
|
}
|
2022-03-10 11:32:48 +11:00
|
|
|
/** XXX What About animation-type "rotation" ? */
|
2020-08-07 12:40:12 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
adt.action->wrap(), adt.slot_handle, *fcu, std::nullopt);
|
2020-08-07 12:40:12 +02:00
|
|
|
fcurve_is_used(fcu);
|
2011-07-05 18:02:08 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-07-04 19:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-28 17:56:09 +02:00
|
|
|
float AnimationImporter::convert_to_focal_length(float in_xfov,
|
|
|
|
|
int fov_type,
|
|
|
|
|
float aspect,
|
|
|
|
|
float sensorx)
|
|
|
|
|
{
|
2019-07-31 14:25:09 +02:00
|
|
|
/* NOTE: Needs more testing (As we currently have no official test data for this) */
|
2018-03-28 17:56:09 +02:00
|
|
|
float xfov = (fov_type == CAMERA_YFOV) ?
|
|
|
|
|
(2.0f * atanf(aspect * tanf(DEG2RADF(in_xfov) * 0.5f))) :
|
|
|
|
|
DEG2RADF(in_xfov);
|
|
|
|
|
return fov_to_focallength(xfov, sensorx);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-05 21:35:09 +00:00
|
|
|
void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId &listid,
|
2024-10-07 16:49:54 +02:00
|
|
|
AnimData &adt,
|
2012-08-05 21:35:09 +00:00
|
|
|
const double aspect,
|
2024-10-09 14:57:14 +11:00
|
|
|
const Camera *cam,
|
2012-08-05 21:35:09 +00:00
|
|
|
const char *anim_type,
|
|
|
|
|
int fov_type)
|
|
|
|
|
{
|
2024-10-07 16:49:54 +02:00
|
|
|
BLI_assert(adt.action != nullptr);
|
|
|
|
|
|
2012-08-05 21:35:09 +00:00
|
|
|
char rna_path[100];
|
|
|
|
|
if (animlist_map.find(listid) == animlist_map.end()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:40:12 +02:00
|
|
|
/* anim_type has animations */
|
|
|
|
|
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
|
|
|
|
const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
|
|
|
|
|
/* all the curves belonging to the current binding */
|
|
|
|
|
std::vector<FCurve *> animcurves;
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < bindings.getCount(); j++) {
|
2020-08-07 12:40:12 +02:00
|
|
|
animcurves = curve_map[bindings[j].animation];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, anim_type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:40:12 +02:00
|
|
|
modify_fcurve(&animcurves, rna_path, 0);
|
|
|
|
|
std::vector<FCurve *>::iterator iter;
|
|
|
|
|
/* Add the curves of the current animation to the object */
|
|
|
|
|
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
|
|
|
|
FCurve *fcu = *iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < fcu->totvert; i++) {
|
2020-08-07 12:40:12 +02:00
|
|
|
fcu->bezt[i].vec[0][1] = convert_to_focal_length(
|
|
|
|
|
fcu->bezt[i].vec[0][1], fov_type, aspect, cam->sensor_x);
|
|
|
|
|
fcu->bezt[i].vec[1][1] = convert_to_focal_length(
|
|
|
|
|
fcu->bezt[i].vec[1][1], fov_type, aspect, cam->sensor_x);
|
|
|
|
|
fcu->bezt[i].vec[2][1] = convert_to_focal_length(
|
|
|
|
|
fcu->bezt[i].vec[2][1], fov_type, aspect, cam->sensor_x);
|
2012-08-05 21:35:09 +00:00
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
adt.action->wrap(), adt.slot_handle, *fcu, std::nullopt);
|
2020-08-07 12:40:12 +02:00
|
|
|
fcurve_is_used(fcu);
|
2012-08-05 21:35: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
|
|
|
void AnimationImporter::apply_matrix_curves(Object *ob,
|
|
|
|
|
std::vector<FCurve *> &animcurves,
|
|
|
|
|
COLLADAFW::Node *root,
|
|
|
|
|
COLLADAFW::Node *node,
|
2012-06-12 22:05:33 +00:00
|
|
|
COLLADAFW::Transformation *tm)
|
2011-08-10 19:43:40 +00:00
|
|
|
{
|
2011-08-14 16:14:32 +00:00
|
|
|
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
|
2020-11-06 17:49:09 +01:00
|
|
|
const char *bone_name = is_joint ? bc_get_joint_name(node) : nullptr;
|
2011-08-14 16:14:32 +00:00
|
|
|
char joint_path[200];
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2011-08-14 16:14:32 +00:00
|
|
|
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
std::vector<float> frames;
|
|
|
|
|
find_frames(&frames, &animcurves);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
float irest_dae[4][4];
|
|
|
|
|
float rest[4][4], irest[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
if (is_joint) {
|
|
|
|
|
get_joint_rest_mat(irest_dae, root, node);
|
|
|
|
|
invert_m4(irest_dae);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
Bone *bone = BKE_armature_find_bone_name((bArmature *)ob->data, bone_name);
|
2011-08-10 19:43:40 +00:00
|
|
|
if (!bone) {
|
|
|
|
|
fprintf(stderr, "cannot find bone \"%s\"\n", bone_name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
unit_m4(rest);
|
|
|
|
|
copy_m4_m4(rest, bone->arm_mat);
|
|
|
|
|
invert_m4_m4(irest, rest);
|
|
|
|
|
}
|
2019-04-30 13:41:21 +10:00
|
|
|
/* new curves to assign matrix transform animation */
|
|
|
|
|
FCurve *newcu[10]; /* if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale */
|
2022-09-25 17:04:52 +10:00
|
|
|
uint totcu = 10;
|
2020-11-06 17:49:09 +01:00
|
|
|
const char *tm_str = nullptr;
|
2011-08-10 19:43:40 +00:00
|
|
|
char rna_path[200];
|
|
|
|
|
for (int i = 0; i < totcu; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
int axis = i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-04 00:15:59 +00:00
|
|
|
if (i < 4) {
|
|
|
|
|
tm_str = "rotation_quaternion";
|
|
|
|
|
axis = i;
|
|
|
|
|
}
|
|
|
|
|
else if (i < 7) {
|
|
|
|
|
tm_str = "location";
|
|
|
|
|
axis = i - 4;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tm_str = "scale";
|
|
|
|
|
axis = i - 7;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(rna_path, "%s.%s", joint_path, tm_str);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(rna_path, tm_str);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-08-10 19:43:40 +00:00
|
|
|
newcu[i] = create_fcurve(axis, rna_path);
|
2011-08-12 20:38:29 +00:00
|
|
|
newcu[i]->totvert = frames.size();
|
2011-08-10 19:43:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:59:27 +02:00
|
|
|
if (frames.empty()) {
|
2011-08-10 19:43:40 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-04 00:15:59 +00:00
|
|
|
std::sort(frames.begin(), frames.end());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
std::vector<float>::iterator it;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* sample values at each frame */
|
2011-08-10 19:43:40 +00:00
|
|
|
for (it = frames.begin(); it != frames.end(); it++) {
|
|
|
|
|
float fra = *it;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
float mat[4][4];
|
|
|
|
|
float matfra[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-10 19:43:40 +00:00
|
|
|
unit_m4(matfra);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* calc object-space mat */
|
2011-08-12 20:38:29 +00:00
|
|
|
evaluate_transform_at_frame(matfra, node, fra);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for joints, we need a special matrix */
|
2011-08-10 19:43:40 +00:00
|
|
|
if (is_joint) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* special matrix: iR * M * iR_dae * R
|
|
|
|
|
* where R, iR are bone rest and inverse rest mats in world space (Blender bones),
|
|
|
|
|
* iR_dae is joint inverse rest matrix (DAE)
|
|
|
|
|
* and M is an evaluated joint world-space matrix (DAE) */
|
2011-08-10 19:43:40 +00:00
|
|
|
float temp[4][4], par[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* calc M */
|
2020-11-06 17:49:09 +01:00
|
|
|
calc_joint_parent_mat_rest(par, nullptr, root, node);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(temp, par, matfra);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* calc special matrix */
|
2014-07-21 18:55:12 +10:00
|
|
|
mul_m4_series(mat, irest, temp, irest_dae, rest);
|
2011-08-10 19:43:40 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_m4_m4(mat, matfra);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
float rot[4], loc[3], scale[3];
|
2018-02-27 17:02:37 +01:00
|
|
|
mat4_decompose(loc, rot, scale, mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* add keys */
|
2011-08-10 19:43:40 +00:00
|
|
|
for (int i = 0; i < totcu; i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (i < 4) {
|
2011-09-04 00:15:59 +00:00
|
|
|
add_bezt(newcu[i], fra, rot[i]);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else if (i < 7) {
|
2011-09-04 00:15:59 +00:00
|
|
|
add_bezt(newcu[i], fra, loc[i - 4]);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-09-04 00:15:59 +00:00
|
|
|
add_bezt(newcu[i], fra, scale[i - 7]);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-08-10 19:43:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +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
|
|
|
Main *bmain = CTX_data_main(mContext);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
ensure_action_and_slot_for_id(bmain, ob->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* add curves */
|
2012-06-12 22:05:33 +00:00
|
|
|
for (int i = 0; i < totcu; i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2011-08-10 19:43:40 +00:00
|
|
|
add_bone_fcurve(ob, node, newcu[i]);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
ob->adt->action->wrap(), ob->adt->slot_handle, *newcu[i], std::nullopt);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-30 13:41:21 +10:00
|
|
|
#if 0
|
2023-08-09 10:47:43 +10:00
|
|
|
fcurve_is_used(newcu[i]); /* never added to unused */
|
2019-04-30 13:41:21 +10:00
|
|
|
#endif
|
2011-08-10 19:43:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-04 00:15:59 +00:00
|
|
|
if (is_joint) {
|
2012-05-05 16:03:57 +00:00
|
|
|
bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name);
|
2011-09-04 00:15:59 +00:00
|
|
|
chan->rotmode = ROT_MODE_QUAT;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ob->rotmode = ROT_MODE_QUAT;
|
|
|
|
|
}
|
2011-08-10 19:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-05 21:35:09 +00:00
|
|
|
/*
|
2019-08-02 12:00:07 +10:00
|
|
|
* This function returns the aspect ration from the Collada camera.
|
2012-08-05 21:35:09 +00:00
|
|
|
*
|
2021-07-03 23:08:40 +10:00
|
|
|
* NOTE:COLLADA allows to specify either XFov, or YFov alone.
|
2012-11-12 07:33:01 +00:00
|
|
|
* In that case the aspect ratio can be determined from
|
2012-08-05 21:35:09 +00:00
|
|
|
* the viewport aspect ratio (which is 1:1 ?)
|
|
|
|
|
* XXX: check this: its probably wrong!
|
|
|
|
|
* If both values are specified, then the aspect ration is simply xfov/yfov
|
2020-03-24 10:27:12 +11:00
|
|
|
* and if aspect ratio is defined, then .. well then its that one.
|
2012-08-05 21:35:09 +00:00
|
|
|
*/
|
2020-09-04 12:04:47 +02:00
|
|
|
static double get_aspect_ratio(const COLLADAFW::Camera *camera)
|
2012-08-05 21:35:09 +00:00
|
|
|
{
|
|
|
|
|
double aspect = camera->getAspectRatio().getValue();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
if (aspect == 0) {
|
2012-08-05 21:35:09 +00:00
|
|
|
const double yfov = camera->getYFov().getValue();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
if (yfov == 0) {
|
2019-04-30 13:41:21 +10:00
|
|
|
aspect = 1; /* assume yfov and xfov are equal */
|
2012-10-21 07:58:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-08-05 21:35:09 +00:00
|
|
|
const double xfov = camera->getXFov().getValue();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (xfov == 0) {
|
2012-08-05 21:35:09 +00:00
|
|
|
aspect = 1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-08-05 21:35:09 +00:00
|
|
|
aspect = xfov / yfov;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-08-05 21:35:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return aspect;
|
|
|
|
|
}
|
|
|
|
|
|
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 AnimationImporter::translate_Animations(
|
|
|
|
|
COLLADAFW::Node *node,
|
2012-06-12 22:05:33 +00:00
|
|
|
std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
|
|
|
|
|
std::multimap<COLLADAFW::UniqueId, Object *> &object_map,
|
2018-04-06 12:42:38 +02:00
|
|
|
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map,
|
|
|
|
|
std::map<COLLADAFW::UniqueId, Material *> uid_material_map)
|
2011-06-14 20:42:01 +00:00
|
|
|
{
|
|
|
|
|
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
|
2012-08-05 10:23:34 +00:00
|
|
|
COLLADAFW::UniqueId uid = node->getUniqueId();
|
|
|
|
|
COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-05 10:23:34 +00:00
|
|
|
Object *ob;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2012-08-05 10:23:34 +00:00
|
|
|
ob = armature_importer->get_armature_for_joint(root);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-03-29 14:21:38 +11:00
|
|
|
ob = object_map.find(uid) == object_map.end() ? nullptr : object_map.find(uid)->second;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (!ob) {
|
2011-07-03 17:26:02 +00:00
|
|
|
fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-11 19:12:25 +10:00
|
|
|
AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map);
|
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
|
|
|
Main *bmain = CTX_data_main(mContext);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->transform) != 0) {
|
2023-04-13 13:13:57 +10:00
|
|
|
// const char *bone_name = is_joint ? bc_get_joint_name(node) : nullptr; /* UNUSED */
|
2011-09-04 00:15:59 +00:00
|
|
|
char joint_path[200];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_joint) {
|
2011-09-04 00:15:59 +00:00
|
|
|
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
ensure_action_and_slot_for_id(bmain, ob->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for each transformation in node */
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeTransforms.getCount(); i++) {
|
2011-07-03 17:26:02 +00:00
|
|
|
COLLADAFW::Transformation *transform = nodeTransforms[i];
|
|
|
|
|
COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
|
|
|
|
|
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = transform->getAnimationList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* check if transformation has animations */
|
2012-02-27 10:35:39 +00:00
|
|
|
if (animlist_map.find(listid) == animlist_map.end()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
|
|
|
|
|
/* transformation has animations */
|
|
|
|
|
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
|
|
|
|
const COLLADAFW::AnimationList::AnimationBindings &bindings =
|
|
|
|
|
animlist->getAnimationBindings();
|
|
|
|
|
/* all the curves belonging to the current binding */
|
|
|
|
|
std::vector<FCurve *> animcurves;
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < bindings.getCount(); j++) {
|
2020-08-07 12:40:12 +02:00
|
|
|
animcurves = curve_map[bindings[j].animation];
|
|
|
|
|
if (is_matrix) {
|
|
|
|
|
apply_matrix_curves(ob, animcurves, root, node, transform);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-04-18 20:17:41 -04:00
|
|
|
/* Calculate RNA-paths and array index of F-Curves according to transformation and
|
2020-08-07 12:40:12 +02:00
|
|
|
* animation class */
|
|
|
|
|
Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path);
|
|
|
|
|
|
|
|
|
|
std::vector<FCurve *>::iterator iter;
|
|
|
|
|
/* Add the curves of the current animation to the object */
|
|
|
|
|
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
|
|
|
|
FCurve *fcu = *iter;
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
ob->adt->action->wrap(), ob->adt->slot_handle, *fcu, std::nullopt);
|
2020-08-07 12:40:12 +02:00
|
|
|
fcurve_is_used(fcu);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-09-04 00:15:59 +00:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
|
2019-06-02 19:06:14 +02:00
|
|
|
if (is_rotation && !(is_joint || is_matrix)) {
|
2012-02-18 06:22:20 +00:00
|
|
|
ob->rotmode = ROT_MODE_EUL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2011-07-03 17:26:02 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if ((animType->light) != 0) {
|
2019-02-27 10:46:48 +11:00
|
|
|
Light *lamp = (Light *)ob->data;
|
2024-10-07 16:49:54 +02:00
|
|
|
ensure_action_and_slot_for_id(bmain, lamp->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-03 17:26:02 +00:00
|
|
|
const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeLights.getCount(); i++) {
|
2011-07-03 17:26:02 +00:00
|
|
|
const COLLADAFW::Light *light = (COLLADAFW::Light *)
|
|
|
|
|
FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if ((animType->light & LIGHT_COLOR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::Color *col = &light->getColor();
|
2011-07-04 19:30:58 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = col->getAnimationList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_color_animations(listid, *lamp->adt, "color");
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->light & LIGHT_FOA) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *foa = &light->getFallOffAngle();
|
2011-07-04 19:30:58 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = foa->getAnimationList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *lamp->adt, "spot_size");
|
2011-07-05 18:02:08 +00:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->light & LIGHT_FOE) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *foe = &light->getFallOffExponent();
|
2011-07-05 18:02:08 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = foe->getAnimationList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *lamp->adt, "spot_blend");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-07-05 18:02:08 +00:00
|
|
|
}
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-21 22:58:08 +00:00
|
|
|
if (animType->camera != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-05 21:35:09 +00:00
|
|
|
Camera *cam = (Camera *)ob->data;
|
2024-10-07 16:49:54 +02:00
|
|
|
ensure_action_and_slot_for_id(bmain, cam->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeCameras.getCount(); i++) {
|
2011-07-06 18:34:01 +00:00
|
|
|
const COLLADAFW::Camera *camera = (COLLADAFW::Camera *)
|
|
|
|
|
FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->camera & CAMERA_XFOV) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *xfov = &camera->getXFov();
|
2011-07-06 18:34:01 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = xfov->getAnimationList();
|
2018-06-08 08:07:48 +02:00
|
|
|
double aspect = get_aspect_ratio(camera);
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_lens_animations(listid, *cam->adt, aspect, cam, "lens", CAMERA_XFOV);
|
2011-07-06 18:34:01 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-04 21:25:19 +00:00
|
|
|
else if ((animType->camera & CAMERA_YFOV) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *yfov = &camera->getYFov();
|
2012-08-04 21:25:19 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = yfov->getAnimationList();
|
2018-06-08 08:07:48 +02:00
|
|
|
double aspect = get_aspect_ratio(camera);
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_lens_animations(listid, *cam->adt, aspect, cam, "lens", CAMERA_YFOV);
|
2012-08-04 21:25:19 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
else if ((animType->camera & CAMERA_XMAG) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *xmag = &camera->getXMag();
|
2011-07-07 16:56:56 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = xmag->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *cam->adt, "ortho_scale");
|
2011-07-07 16:56:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-04 21:25:19 +00:00
|
|
|
else if ((animType->camera & CAMERA_YMAG) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *ymag = &camera->getYMag();
|
2012-08-04 21:25:19 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = ymag->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *cam->adt, "ortho_scale");
|
2012-08-04 21:25:19 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->camera & CAMERA_ZFAR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *zfar = &camera->getFarClippingPlane();
|
2011-07-13 16:53:36 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = zfar->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *cam->adt, "clip_end");
|
2011-07-13 16:53:36 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
if ((animType->camera & CAMERA_ZNEAR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::AnimatableFloat *znear = &camera->getNearClippingPlane();
|
2011-07-13 16:53:36 +00:00
|
|
|
const COLLADAFW::UniqueId &listid = znear->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *cam->adt, "clip_start");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-07-13 16:53:36 +00:00
|
|
|
}
|
2011-07-06 18:34:01 +00:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
if (animType->material != 0) {
|
2011-07-23 20:49:26 +00:00
|
|
|
const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeGeoms.getCount(); i++) {
|
2011-07-23 20:49:26 +00:00
|
|
|
const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < matBinds.getCount(); j++) {
|
2011-07-23 20:49:26 +00:00
|
|
|
const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
|
|
|
|
|
const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]);
|
2023-08-01 21:15:52 +10:00
|
|
|
if (ef != nullptr) { /* can be nullptr #28909. */
|
2018-04-06 12:42:38 +02:00
|
|
|
Material *ma = uid_material_map[matuid];
|
|
|
|
|
if (!ma) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Collada: Node %s refers to undefined material\n",
|
|
|
|
|
node->getName().c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-07 16:49:54 +02:00
|
|
|
ensure_action_and_slot_for_id(bmain, ma->id);
|
|
|
|
|
|
2018-04-06 12:42:38 +02:00
|
|
|
const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
|
2011-10-14 02:31:04 +00:00
|
|
|
COLLADAFW::EffectCommon *efc = commonEffects[0];
|
2012-03-28 05:03:24 +00:00
|
|
|
if ((animType->material & MATERIAL_SHININESS) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::FloatOrParam *shin = &efc->getShininess();
|
2018-04-06 12:42:38 +02:00
|
|
|
const COLLADAFW::UniqueId &listid = shin->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *ma->adt, "specular_hardness");
|
2011-10-14 02:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
if ((animType->material & MATERIAL_IOR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::FloatOrParam *ior = &efc->getIndexOfRefraction();
|
2018-04-06 12:42:38 +02:00
|
|
|
const COLLADAFW::UniqueId &listid = ior->getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_float_animations(listid, *ma->adt, "raytrace_transparency.ior");
|
2011-10-14 02:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
if ((animType->material & MATERIAL_SPEC_COLOR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::ColorOrTexture *cot = &efc->getSpecular();
|
2018-04-06 12:42:38 +02:00
|
|
|
const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_color_animations(listid, *ma->adt, "specular_color");
|
2011-10-14 02:31:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
if ((animType->material & MATERIAL_DIFF_COLOR) != 0) {
|
2023-07-20 11:30:25 +10:00
|
|
|
const COLLADAFW::ColorOrTexture *cot = &efc->getDiffuse();
|
2018-04-06 12:42:38 +02:00
|
|
|
const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
|
2024-10-07 16:49:54 +02:00
|
|
|
Assign_color_animations(listid, *ma->adt, "diffuse_color");
|
2011-10-14 02:31:04 +00:00
|
|
|
}
|
2011-07-27 19:08:18 +00:00
|
|
|
}
|
2011-07-23 20:49:26 +00:00
|
|
|
}
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2011-07-23 20:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-11 19:12:25 +10:00
|
|
|
delete animType;
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
AnimationImporter::AnimMix *AnimationImporter::get_animation_type(
|
|
|
|
|
const COLLADAFW::Node *node,
|
|
|
|
|
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map)
|
2011-06-14 20:42:01 +00:00
|
|
|
{
|
2011-07-10 06:21:39 +00:00
|
|
|
AnimMix *types = new AnimMix();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-14 20:42:01 +00:00
|
|
|
const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for each transformation in node */
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeTransforms.getCount(); i++) {
|
2011-06-14 20:42:01 +00:00
|
|
|
COLLADAFW::Transformation *transform = nodeTransforms[i];
|
|
|
|
|
const COLLADAFW::UniqueId &listid = transform->getAnimationList();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* check if transformation has animations */
|
2012-02-27 10:35:39 +00:00
|
|
|
if (animlist_map.find(listid) == animlist_map.end()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
|
|
|
|
|
types->transform = types->transform | BC_NODE_TRANSFORM;
|
|
|
|
|
break;
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2011-07-03 11:07:34 +00:00
|
|
|
const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeLights.getCount(); i++) {
|
2011-07-03 11:07:34 +00:00
|
|
|
const COLLADAFW::Light *light = (COLLADAFW::Light *)
|
|
|
|
|
FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
|
2023-07-20 11:30:25 +10:00
|
|
|
types->light = setAnimType(&light->getColor(), (types->light), LIGHT_COLOR);
|
|
|
|
|
types->light = setAnimType(&light->getFallOffAngle(), (types->light), LIGHT_FOA);
|
|
|
|
|
types->light = setAnimType(&light->getFallOffExponent(), (types->light), LIGHT_FOE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (types->light != 0) {
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-07-03 11:07:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-06 18:09:36 +00:00
|
|
|
const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeCameras.getCount(); i++) {
|
2012-08-04 21:25:19 +00:00
|
|
|
const COLLADAFW::Camera *camera = (COLLADAFW::Camera *)
|
|
|
|
|
FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
|
2020-11-06 17:49:09 +01:00
|
|
|
if (camera == nullptr) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* Can happen if the node refers to an unknown camera. */
|
2012-08-05 10:23:34 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-04 21:25:19 +00:00
|
|
|
const bool is_perspective_type = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-04 21:25:19 +00:00
|
|
|
int addition;
|
|
|
|
|
const COLLADAFW::Animatable *mag;
|
|
|
|
|
const COLLADAFW::UniqueId listid = camera->getYMag().getAnimationList();
|
|
|
|
|
if (animlist_map.find(listid) != animlist_map.end()) {
|
2023-07-20 11:30:25 +10:00
|
|
|
mag = &camera->getYMag();
|
2012-08-04 21:25:19 +00:00
|
|
|
addition = (is_perspective_type) ? CAMERA_YFOV : CAMERA_YMAG;
|
2011-07-07 16:56:56 +00:00
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
2023-07-20 11:30:25 +10:00
|
|
|
mag = &camera->getXMag();
|
2012-08-04 21:25:19 +00:00
|
|
|
addition = (is_perspective_type) ? CAMERA_XFOV : CAMERA_XMAG;
|
2011-07-09 19:33:02 +00:00
|
|
|
}
|
2012-08-04 21:25:19 +00:00
|
|
|
types->camera = setAnimType(mag, (types->camera), addition);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-20 11:30:25 +10:00
|
|
|
types->camera = setAnimType(&camera->getFarClippingPlane(), (types->camera), CAMERA_ZFAR);
|
|
|
|
|
types->camera = setAnimType(&camera->getNearClippingPlane(), (types->camera), CAMERA_ZNEAR);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (types->camera != 0) {
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2011-07-18 19:32:51 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-07-18 19:32:51 +00:00
|
|
|
const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < nodeGeoms.getCount(); i++) {
|
2011-07-18 19:32:51 +00:00
|
|
|
const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint j = 0; j < matBinds.getCount(); j++) {
|
2011-07-23 20:49:26 +00:00
|
|
|
const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
|
|
|
|
|
const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]);
|
2023-08-01 21:15:52 +10:00
|
|
|
if (ef != nullptr) { /* can be nullptr #28909. */
|
2011-10-14 02:31:04 +00:00
|
|
|
const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!commonEffects.empty()) {
|
2011-10-14 02:31:04 +00:00
|
|
|
COLLADAFW::EffectCommon *efc = commonEffects[0];
|
2012-04-29 15:47:02 +00:00
|
|
|
types->material = setAnimType(
|
2023-07-20 11:30:25 +10:00
|
|
|
&efc->getShininess(), (types->material), MATERIAL_SHININESS);
|
2012-04-29 15:47:02 +00:00
|
|
|
types->material = setAnimType(
|
2023-07-20 11:30:25 +10:00
|
|
|
&efc->getSpecular().getColor(), (types->material), MATERIAL_SPEC_COLOR);
|
2012-04-29 15:47:02 +00:00
|
|
|
types->material = setAnimType(
|
2023-07-20 11:30:25 +10:00
|
|
|
&efc->getDiffuse().getColor(), (types->material), MATERIAL_DIFF_COLOR);
|
2019-04-30 13:41:21 +10:00
|
|
|
#if 0
|
|
|
|
|
types->material = setAnimType(&(efc->get()), (types->material), MATERIAL_TRANSPARENCY);
|
|
|
|
|
#endif
|
2012-04-29 15:47:02 +00:00
|
|
|
types->material = setAnimType(
|
2023-07-20 11:30:25 +10:00
|
|
|
&efc->getIndexOfRefraction(), (types->material), MATERIAL_IOR);
|
2011-10-14 02:31:04 +00:00
|
|
|
}
|
2011-09-04 02:12:03 +00:00
|
|
|
}
|
2011-07-18 19:32:51 +00:00
|
|
|
}
|
2011-07-06 18:09:36 +00:00
|
|
|
}
|
2011-07-09 15:15:17 +00:00
|
|
|
return types;
|
2011-06-14 20:42:01 +00:00
|
|
|
}
|
2011-06-16 19:25:21 +00:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
int AnimationImporter::setAnimType(const COLLADAFW::Animatable *prop, int types, int addition)
|
2011-07-09 19:33:02 +00:00
|
|
|
{
|
2012-08-04 21:25:19 +00:00
|
|
|
int anim_type;
|
|
|
|
|
const COLLADAFW::UniqueId &listid = prop->getAnimationList();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (animlist_map.find(listid) != animlist_map.end()) {
|
2012-08-04 21:25:19 +00:00
|
|
|
anim_type = types | addition;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-08-04 21:25:19 +00:00
|
|
|
anim_type = types;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-04 21:25:19 +00:00
|
|
|
return anim_type;
|
2018-06-08 08:07:48 +02:00
|
|
|
}
|
2011-07-09 19:33:02 +00:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
void AnimationImporter::evaluate_transform_at_frame(float mat[4][4],
|
|
|
|
|
COLLADAFW::Node *node,
|
|
|
|
|
float fra)
|
|
|
|
|
{
|
|
|
|
|
const COLLADAFW::TransformationPointerArray &tms = node->getTransformations();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
unit_m4(mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < tms.getCount(); i++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::Transformation *tm = tms[i];
|
|
|
|
|
COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
|
|
|
|
|
float m[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
unit_m4(m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:59:27 +02:00
|
|
|
std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName();
|
2011-06-20 12:43:10 +00:00
|
|
|
if (!evaluate_animation(tm, m, fra, nodename.c_str())) {
|
2012-02-18 06:22:20 +00:00
|
|
|
switch (type) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::Transformation::ROTATE:
|
|
|
|
|
dae_rotate_to_mat4(tm, m);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::TRANSLATE:
|
|
|
|
|
dae_translate_to_mat4(tm, m);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::SCALE:
|
|
|
|
|
dae_scale_to_mat4(tm, m);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::MATRIX:
|
|
|
|
|
dae_matrix_to_mat4(tm, m);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "unsupported transformation type %d\n", type);
|
2012-02-18 06:22:20 +00:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
float temp[4][4];
|
|
|
|
|
copy_m4_m4(temp, mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(mat, temp, m);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 08:07:48 +02:00
|
|
|
static void report_class_type_unsupported(const char *path,
|
2013-07-15 10:50:04 +00:00
|
|
|
const COLLADAFW::AnimationList::AnimationClass animclass,
|
2018-06-08 08:07:48 +02:00
|
|
|
const COLLADAFW::Transformation::TransformationType type)
|
2013-07-15 10:50:04 +00:00
|
|
|
{
|
|
|
|
|
if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) {
|
|
|
|
|
fprintf(stderr, "%s: UNKNOWN animation class\n", path);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"%s: animation class %d is not supported yet for transformation type %d\n",
|
|
|
|
|
path,
|
|
|
|
|
animclass,
|
|
|
|
|
type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm,
|
|
|
|
|
float mat[4][4],
|
|
|
|
|
float fra,
|
|
|
|
|
const char *node_id)
|
|
|
|
|
{
|
|
|
|
|
const COLLADAFW::UniqueId &listid = tm->getAnimationList();
|
|
|
|
|
COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-26 13:58:49 +10:00
|
|
|
if (!ELEM(type,
|
|
|
|
|
COLLADAFW::Transformation::ROTATE,
|
|
|
|
|
COLLADAFW::Transformation::SCALE,
|
|
|
|
|
COLLADAFW::Transformation::TRANSLATE,
|
|
|
|
|
COLLADAFW::Transformation::MATRIX))
|
|
|
|
|
{
|
2010-10-05 00:05:14 +00:00
|
|
|
fprintf(stderr, "animation of transformation %d is not supported yet\n", type);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (animlist_map.find(listid) == animlist_map.end()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
|
|
|
|
const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (bindings.getCount()) {
|
|
|
|
|
float vec[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
bool is_scale = (type == COLLADAFW::Transformation::SCALE);
|
|
|
|
|
bool is_translate = (type == COLLADAFW::Transformation::TRANSLATE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_scale) {
|
2010-10-05 00:05:14 +00:00
|
|
|
dae_scale_to_v3(tm, vec);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else if (is_translate) {
|
2010-10-05 00:05:14 +00:00
|
|
|
dae_translate_to_v3(tm, vec);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint index = 0; index < bindings.getCount(); index++) {
|
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
|
|
|
const COLLADAFW::AnimationList::AnimationBinding &binding = bindings[index];
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<FCurve *> &curves = curve_map[binding.animation];
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::AnimationList::AnimationClass animclass = binding.animationClass;
|
|
|
|
|
char path[100];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
switch (type) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::Transformation::ROTATE:
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(path, "%s.rotate (binding %u)", node_id, index);
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::SCALE:
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(path, "%s.scale (binding %u)", node_id, index);
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::TRANSLATE:
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(path, "%s.translate (binding %u)", node_id, index);
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
|
|
|
|
case COLLADAFW::Transformation::MATRIX:
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(path, "%s.matrix (binding %u)", node_id, index);
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (type == COLLADAFW::Transformation::ROTATE) {
|
|
|
|
|
if (curves.size() != 1) {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "expected 1 curve, got %d\n", int(curves.size()));
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-10 11:32:48 +11:00
|
|
|
/* TODO: support other animation-classes. */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (animclass != COLLADAFW::AnimationList::ANGLE) {
|
2013-07-15 10:50:04 +00:00
|
|
|
report_class_type_unsupported(path, animclass, type);
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
COLLADABU::Math::Vector3 &axis = ((COLLADAFW::Rotate *)tm)->getRotationAxis();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
float ax[3] = {float(axis[0]), float(axis[1]), float(axis[2])};
|
2010-10-05 00:05:14 +00:00
|
|
|
float angle = evaluate_fcurve(curves[0], fra);
|
|
|
|
|
axis_angle_to_mat4(mat, ax, angle);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-07 12:40:12 +02:00
|
|
|
if (is_scale || is_translate) {
|
2010-10-05 00:05:14 +00:00
|
|
|
bool is_xyz = animclass == COLLADAFW::AnimationList::POSITION_XYZ;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if ((!is_xyz && curves.size() != 1) || (is_xyz && curves.size() != 3)) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_xyz) {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "%s: expected 3 curves, got %d\n", path, int(curves.size()));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "%s: expected 1 curve, got %d\n", path, int(curves.size()));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
switch (animclass) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::AnimationList::POSITION_X:
|
|
|
|
|
vec[0] = evaluate_fcurve(curves[0], fra);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_Y:
|
|
|
|
|
vec[1] = evaluate_fcurve(curves[0], fra);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_Z:
|
|
|
|
|
vec[2] = evaluate_fcurve(curves[0], fra);
|
|
|
|
|
break;
|
|
|
|
|
case COLLADAFW::AnimationList::POSITION_XYZ:
|
|
|
|
|
vec[0] = evaluate_fcurve(curves[0], fra);
|
|
|
|
|
vec[1] = evaluate_fcurve(curves[1], fra);
|
|
|
|
|
vec[2] = evaluate_fcurve(curves[2], fra);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-07-15 10:50:04 +00:00
|
|
|
report_class_type_unsupported(path, animclass, type);
|
2012-06-12 22:05:33 +00:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
else if (type == COLLADAFW::Transformation::MATRIX) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for now, of matrix animation,
|
|
|
|
|
* support only the case when all values are packed into one animation */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (curves.size() != 16) {
|
2022-09-25 18:33:28 +10:00
|
|
|
fprintf(stderr, "%s: expected 16 curves, got %d\n", path, int(curves.size()));
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADABU::Math::Matrix4 matrix;
|
2018-03-11 19:57:40 +01:00
|
|
|
int mi = 0, mj = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-05-21 13:13:09 +10:00
|
|
|
for (const FCurve *curve : curves) {
|
2020-12-07 12:21:11 +01:00
|
|
|
matrix.setElement(mi, mj, evaluate_fcurve(curve, fra));
|
2018-03-11 19:57:40 +01:00
|
|
|
mj++;
|
|
|
|
|
if (mj == 4) {
|
|
|
|
|
mi++;
|
|
|
|
|
mj = 0;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-04 12:26:24 +02:00
|
|
|
UnitConverter::dae_matrix_to_mat4_(mat, matrix);
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (is_scale) {
|
2010-10-05 00:05:14 +00:00
|
|
|
size_to_mat4(mat, vec);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2010-10-05 00:05:14 +00:00
|
|
|
copy_v3_v3(mat[3], vec);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return is_scale || is_translate;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationImporter::get_joint_rest_mat(float mat[4][4],
|
|
|
|
|
COLLADAFW::Node *root,
|
|
|
|
|
COLLADAFW::Node *node)
|
|
|
|
|
{
|
2019-04-30 13:41:21 +10:00
|
|
|
/* if bind mat is not available,
|
|
|
|
|
* use "current" node transform, i.e. all those tms listed inside <node> */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (!armature_importer->get_joint_bind_mat(mat, node)) {
|
|
|
|
|
float par[4][4], m[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
calc_joint_parent_mat_rest(par, nullptr, root, node);
|
|
|
|
|
get_node_mat(m, node, nullptr, nullptr);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(mat, par, m);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AnimationImporter::calc_joint_parent_mat_rest(float mat[4][4],
|
|
|
|
|
float par[4][4],
|
|
|
|
|
COLLADAFW::Node *node,
|
|
|
|
|
COLLADAFW::Node *end)
|
|
|
|
|
{
|
|
|
|
|
float m[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (node == end) {
|
|
|
|
|
par ? copy_m4_m4(mat, par) : unit_m4(mat);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* use bind matrix if available or calc "current" world mat */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (!armature_importer->get_joint_bind_mat(m, node)) {
|
|
|
|
|
if (par) {
|
|
|
|
|
float temp[4][4];
|
2020-11-06 17:49:09 +01:00
|
|
|
get_node_mat(temp, node, nullptr, nullptr);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(m, par, temp);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2020-11-06 17:49:09 +01:00
|
|
|
get_node_mat(m, node, nullptr, nullptr);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::NodePointerArray &children = node->getChildNodes();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < children.getCount(); i++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (calc_joint_parent_mat_rest(mat, m, children[i], end)) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationImporter::add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu)
|
|
|
|
|
{
|
2024-10-07 16:49:54 +02:00
|
|
|
BLI_assert(ob->adt != nullptr && ob->adt->action != nullptr);
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
const char *bone_name = bc_get_joint_name(node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-07 16:49:54 +02:00
|
|
|
blender::animrig::action_fcurve_attach(
|
|
|
|
|
ob->adt->action->wrap(), ob->adt->slot_handle, *fcu, bone_name);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 13:04:51 +01:00
|
|
|
void AnimationImporter::set_import_from_version(std::string import_from_version)
|
|
|
|
|
{
|
|
|
|
|
this->import_from_version = import_from_version;
|
|
|
|
|
}
|