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
|
|
|
*/
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2014-09-01 14:33:05 +02:00
|
|
|
#include "BLI_listbase.h"
|
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"
|
2014-09-01 14:33:05 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
|
#include "DNA_modifier_types.h"
|
2013-06-24 13:17:21 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2014-11-18 23:52:17 +01:00
|
|
|
|
2024-09-10 14:55:47 +02:00
|
|
|
#include "BKE_action.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2014-11-18 23:52:17 +01:00
|
|
|
#include "BKE_object_deform.h"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_mesh.hh"
|
|
|
|
|
#include "ED_object.hh"
|
2024-03-26 21:51:09 -04:00
|
|
|
#include "ED_object_vgroup.hh"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#include "SkinInfo.h"
|
|
|
|
|
#include "collada_utils.h"
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* use name, or fall back to original id if name not present (name is optional) */
|
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
|
|
|
}
|
|
|
|
|
|
2021-04-08 11:07:12 +02:00
|
|
|
SkinInfo::SkinInfo() = default;
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
SkinInfo::SkinInfo(const SkinInfo &skin)
|
|
|
|
|
: weights(skin.weights),
|
2012-06-12 22:05:33 +00:00
|
|
|
joint_data(skin.joint_data),
|
|
|
|
|
unit_converter(skin.unit_converter),
|
|
|
|
|
ob_arm(skin.ob_arm),
|
|
|
|
|
controller_uid(skin.controller_uid),
|
|
|
|
|
parent(skin.parent)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
copy_m4_m4(bind_shape_matrix, (float(*)[4])skin.bind_shape_matrix);
|
|
|
|
|
|
|
|
|
|
transfer_uint_array_data_const(skin.joints_per_vertex, joints_per_vertex);
|
|
|
|
|
transfer_uint_array_data_const(skin.weight_indices, weight_indices);
|
|
|
|
|
transfer_int_array_data_const(skin.joint_indices, joint_indices);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
SkinInfo::SkinInfo(UnitConverter *conv) : unit_converter(conv), ob_arm(nullptr), parent(nullptr) {}
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
template<class T> void SkinInfo::transfer_array_data(T &src, T &dest)
|
|
|
|
|
{
|
|
|
|
|
dest.setData(src.getData(), src.getCount());
|
|
|
|
|
src.yieldOwnerShip();
|
|
|
|
|
dest.yieldOwnerShip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SkinInfo::transfer_int_array_data_const(const COLLADAFW::IntValuesArray &src,
|
|
|
|
|
COLLADAFW::IntValuesArray &dest)
|
|
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
dest.setData((int *)src.getData(), src.getCount());
|
2010-10-05 00:05:14 +00:00
|
|
|
dest.yieldOwnerShip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SkinInfo::transfer_uint_array_data_const(const COLLADAFW::UIntValuesArray &src,
|
|
|
|
|
COLLADAFW::UIntValuesArray &dest)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
dest.setData((uint *)src.getData(), src.getCount());
|
2010-10-05 00:05:14 +00:00
|
|
|
dest.yieldOwnerShip();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void SkinInfo::borrow_skin_controller_data(const COLLADAFW::SkinControllerData *skin)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
transfer_array_data((COLLADAFW::UIntValuesArray &)skin->getJointsPerVertex(), joints_per_vertex);
|
|
|
|
|
transfer_array_data((COLLADAFW::UIntValuesArray &)skin->getWeightIndices(), weight_indices);
|
|
|
|
|
transfer_array_data((COLLADAFW::IntValuesArray &)skin->getJointIndices(), joint_indices);
|
2010-10-05 00:05:14 +00:00
|
|
|
// transfer_array_data(skin->getWeights(), weights);
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* cannot transfer data for FloatOrDoubleArray, copy values manually */
|
2010-10-05 00:05:14 +00:00
|
|
|
const COLLADAFW::FloatOrDoubleArray &weight = skin->getWeights();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < weight.getValuesCount(); i++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
weights.push_back(bc_get_float_value(weight, i));
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2020-09-04 12:26:24 +02:00
|
|
|
UnitConverter::dae_matrix_to_mat4_(bind_shape_matrix, skin->getBindShapeMatrix());
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
void SkinInfo::free()
|
|
|
|
|
{
|
|
|
|
|
joints_per_vertex.releaseMemory();
|
|
|
|
|
weight_indices.releaseMemory();
|
|
|
|
|
joint_indices.releaseMemory();
|
|
|
|
|
// weights.releaseMemory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SkinInfo::add_joint(const COLLADABU::Math::Matrix4 &matrix)
|
|
|
|
|
{
|
|
|
|
|
JointData jd;
|
2020-09-04 12:26:24 +02:00
|
|
|
UnitConverter::dae_matrix_to_mat4_(jd.inv_bind_mat, matrix);
|
2010-10-05 00:05:14 +00:00
|
|
|
joint_data.push_back(jd);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void SkinInfo::set_controller(const COLLADAFW::SkinController *co)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
controller_uid = co->getUniqueId();
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* fill in joint UIDs */
|
2010-10-05 00:05:14 +00:00
|
|
|
const COLLADAFW::UniqueIdArray &joint_uids = co->getJoints();
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint i = 0; i < joint_uids.getCount(); i++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
joint_data[i].joint_uid = joint_uids[i];
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* store armature pointer */
|
2010-10-05 00:05:14 +00:00
|
|
|
// JointData& jd = joint_index_to_joint_info_map[i];
|
|
|
|
|
// jd.ob_arm = ob_arm;
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* now we'll be able to get inv bind matrix from joint id */
|
2010-10-05 00:05:14 +00:00
|
|
|
// joint_id_to_joint_index_map[joint_ids[i]] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 15:55:51 +02:00
|
|
|
Object *SkinInfo::create_armature(Main *bmain, Scene *scene, ViewLayer *view_layer)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
ob_arm = bc_add_object(bmain, scene, view_layer, OB_ARMATURE, nullptr);
|
2010-10-05 00:05:14 +00:00
|
|
|
return ob_arm;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
Object *SkinInfo::set_armature(Object *ob_arm)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (this->ob_arm) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return this->ob_arm;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
this->ob_arm = ob_arm;
|
|
|
|
|
return ob_arm;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
bool SkinInfo::get_joint_inv_bind_matrix(float inv_bind_mat[4][4], COLLADAFW::Node *node)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
const COLLADAFW::UniqueId &uid = node->getUniqueId();
|
|
|
|
|
std::vector<JointData>::iterator it;
|
|
|
|
|
for (it = joint_data.begin(); it != joint_data.end(); it++) {
|
|
|
|
|
if ((*it).joint_uid == uid) {
|
|
|
|
|
copy_m4_m4(inv_bind_mat, (*it).inv_bind_mat);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
Object *SkinInfo::BKE_armature_from_object()
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
return ob_arm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const COLLADAFW::UniqueId &SkinInfo::get_controller_uid()
|
|
|
|
|
{
|
|
|
|
|
return controller_uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SkinInfo::uses_joint_or_descendant(COLLADAFW::Node *node)
|
|
|
|
|
{
|
|
|
|
|
const COLLADAFW::UniqueId &uid = node->getUniqueId();
|
|
|
|
|
std::vector<JointData>::iterator it;
|
|
|
|
|
for (it = joint_data.begin(); it != joint_data.end(); it++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if ((*it).joint_uid == uid) {
|
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
|
|
|
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 (uses_joint_or_descendant(children[i])) {
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void SkinInfo::link_armature(bContext *C,
|
|
|
|
|
Object *ob,
|
|
|
|
|
std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &joint_by_uid,
|
|
|
|
|
TransformReader *tm)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
|
2024-03-28 01:30:38 +01:00
|
|
|
ModifierData *md = blender::ed::object::modifier_add(
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr, bmain, scene, ob, nullptr, eModifierType_Armature);
|
2012-05-06 04:50:04 +00:00
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData *)md;
|
|
|
|
|
amd->object = ob_arm;
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#if 1
|
2021-06-24 15:56:58 +10:00
|
|
|
/* XXX Why do we enforce objects to be children of Armatures if they weren't so before? */
|
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 (!BKE_object_is_child_recursive(ob_arm, ob)) {
|
|
|
|
|
bc_set_parent(ob, ob_arm, C);
|
|
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
#else
|
2024-02-28 15:06:02 +01:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
ob->parent = ob_arm;
|
|
|
|
|
ob->partype = PAROBJECT;
|
|
|
|
|
|
2024-02-28 15:06:02 +01:00
|
|
|
invert_m4_m4(ob->parentinv, BKE_object_calc_parent(depsgraph, scene, ob).ptr());
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&obn->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
|
2010-10-05 00:05:14 +00:00
|
|
|
#endif
|
2024-02-14 16:14:49 +01:00
|
|
|
copy_m4_m4(ob->runtime->object_to_world.ptr(), bind_shape_matrix);
|
|
|
|
|
BKE_object_apply_mat4(ob, ob->object_to_world().ptr(), false, false);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2012-05-06 04:50:04 +00:00
|
|
|
amd->deformflag = ARM_DEF_VGROUP;
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* create all vertex groups */
|
2010-10-05 00:05:14 +00:00
|
|
|
std::vector<JointData>::iterator it;
|
|
|
|
|
int joint_index;
|
|
|
|
|
for (it = joint_data.begin(), joint_index = 0; it != joint_data.end(); it++, joint_index++) {
|
|
|
|
|
const char *name = "Group";
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* skip joints that have invalid UID */
|
2019-05-31 22:51:19 +10:00
|
|
|
if ((*it).joint_uid == COLLADAFW::UniqueId::INVALID) {
|
2011-01-10 23:31:14 +00:00
|
|
|
continue;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* name group by joint node name */
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (joint_by_uid.find((*it).joint_uid) != joint_by_uid.end()) {
|
|
|
|
|
name = bc_get_joint_name(joint_by_uid[(*it).joint_uid]);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 23:52:17 +01:00
|
|
|
BKE_object_defgroup_add_name(ob, name);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* <vcount> - number of joints per vertex - joints_per_vertex
|
|
|
|
|
* <v> - [[bone index, weight index] * joints per vertex] * vertices - weight indices
|
|
|
|
|
* ^ bone index can be -1 meaning weight toward bind shape, how to express this in Blender?
|
|
|
|
|
*
|
|
|
|
|
* for each vertex in weight indices
|
2023-02-27 21:44:59 +11:00
|
|
|
* for each bone index in vertex
|
2019-04-30 13:41:21 +10:00
|
|
|
* add vertex to group at group index
|
|
|
|
|
* treat group index -1 specially
|
|
|
|
|
*
|
|
|
|
|
* get def group by index with BLI_findlink */
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
for (uint vertex = 0, weight = 0; vertex < joints_per_vertex.getCount(); vertex++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
uint limit = weight + joints_per_vertex[vertex];
|
2012-06-12 22:05:33 +00:00
|
|
|
for (; weight < limit; weight++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
int joint = joint_indices[weight], joint_weight = weight_indices[weight];
|
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* -1 means "weight towards the bind shape", we just don't assign it to any group */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (joint != -1) {
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
|
|
|
|
bDeformGroup *def = (bDeformGroup *)BLI_findlink(defbase, joint);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2024-03-28 01:30:38 +01:00
|
|
|
blender::ed::object::vgroup_vert_add(
|
|
|
|
|
ob, def, vertex, weights[joint_weight], WEIGHT_REPLACE);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bPoseChannel *SkinInfo::get_pose_channel_from_node(COLLADAFW::Node *node)
|
|
|
|
|
{
|
2012-05-05 16:03:57 +00:00
|
|
|
return BKE_pose_channel_find_name(ob_arm->pose, bc_get_joint_name(node));
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SkinInfo::set_parent(Object *_parent)
|
|
|
|
|
{
|
|
|
|
|
parent = _parent;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
Object *SkinInfo::get_parent()
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
void SkinInfo::find_root_joints(const std::vector<COLLADAFW::Node *> &root_joints,
|
|
|
|
|
std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &joint_by_uid,
|
|
|
|
|
std::vector<COLLADAFW::Node *> &result)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2012-06-12 22:05:33 +00:00
|
|
|
std::vector<COLLADAFW::Node *>::const_iterator it;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for each root_joint */
|
2010-10-05 00:05:14 +00:00
|
|
|
for (it = root_joints.begin(); it != root_joints.end(); it++) {
|
|
|
|
|
COLLADAFW::Node *root = *it;
|
|
|
|
|
std::vector<JointData>::iterator ji;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* for each joint_data in this skin */
|
2010-10-05 00:05:14 +00:00
|
|
|
for (ji = joint_data.begin(); ji != joint_data.end(); ji++) {
|
2013-04-22 15:49:15 +00:00
|
|
|
if (joint_by_uid.find((*ji).joint_uid) != joint_by_uid.end()) {
|
2019-04-30 13:41:21 +10:00
|
|
|
/* get joint node from joint map */
|
2013-04-22 15:49:15 +00:00
|
|
|
COLLADAFW::Node *joint = joint_by_uid[(*ji).joint_uid];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* find if joint node is in the tree belonging to the root_joint */
|
2013-04-22 15:49:15 +00:00
|
|
|
if (find_node_in_tree(joint, root)) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (std::find(result.begin(), result.end(), root) == result.end()) {
|
2013-04-22 15:49:15 +00:00
|
|
|
result.push_back(root);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-04-22 15:49:15 +00:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SkinInfo::find_node_in_tree(COLLADAFW::Node *node, COLLADAFW::Node *tree_root)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (node == tree_root) {
|
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
|
|
|
|
|
|
|
|
COLLADAFW::NodePointerArray &children = tree_root->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 (find_node_in_tree(node, children[i])) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2010-10-05 00:49:39 +00:00
|
|
|
}
|