2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <math.h>
|
2013-11-01 08:31:36 +00:00
|
|
|
#include <stdio.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.h>
|
2002-11-25 12:02:15 +00:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
#include "DNA_camera_types.h"
|
2018-08-29 15:32:50 +02:00
|
|
|
#include "DNA_collection_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_constraint_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_defaults.h"
|
|
|
|
#include "DNA_fluid_types.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "DNA_gpencil_modifier_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_gpencil_types.h"
|
2009-12-28 15:26:36 +00:00
|
|
|
#include "DNA_key_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_lattice_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_light_types.h"
|
|
|
|
#include "DNA_lightprobe_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_material_types.h"
|
2012-02-19 22:17:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_meta_types.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "DNA_movieclip_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_rigidbody_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
2010-03-09 13:52:52 +00:00
|
|
|
#include "DNA_sequence_types.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "DNA_shader_fx_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_kdtree.h"
|
|
|
|
#include "BLI_linklist.h"
|
2010-03-22 11:59:36 +00:00
|
|
|
#include "BLI_math.h"
|
2014-01-09 16:19:51 +06:00
|
|
|
#include "BLI_threads.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-24 12:13:13 +00:00
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_action.h"
|
2020-04-03 13:07:36 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "BKE_anim_path.h"
|
|
|
|
#include "BKE_anim_visualization.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_armature.h"
|
|
|
|
#include "BKE_camera.h"
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
#include "BKE_collection.h"
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
#include "BKE_constraint.h"
|
|
|
|
#include "BKE_curve.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_deform.h"
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
#include "BKE_displist.h"
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "BKE_duplilist.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_editmesh.h"
|
2020-05-25 20:16:42 +10:00
|
|
|
#include "BKE_editmesh_cache.h"
|
Unified effector functionality for particles, cloth and softbody
* Unified scene wide gravity (currently in scene buttons)
instead of each simulation having it's own gravity.
* Weight parameters for all effectors and an effector group
setting.
* Every effector can use noise.
* Most effectors have "shapes" point, plane, surface, every point.
- "Point" is most like the old effectors and uses the
effector location as the effector point.
- "Plane" uses the closest point on effectors local xy-plane
as the effector point.
- "Surface" uses the closest point on an effector object's
surface as the effector point.
- "Every Point" uses every point in a mesh effector object
as an effector point.
- The falloff is calculated from this point, so for example
with "surface" shape and "use only negative z axis" it's
possible to apply force only "inside" the effector object.
* Spherical effector is now renamed as "force" as it's no longer
just spherical.
* New effector parameter "flow", which makes the effector act as
surrounding air velocity, so the resulting force is
proportional to the velocity difference of the point and "air
velocity". For example a wind field with flow=1.0 results in
proper non-accelerating wind.
* New effector fields "turbulence", which creates nice random
flow paths, and "drag", which slows the points down.
* Much improved vortex field.
* Effectors can now effect particle rotation as well as location.
* Use full, or only positive/negative z-axis to apply force
(note. the z-axis is the surface normal in the case of
effector shape "surface")
* New "force field" submenu in add menu, which adds an empty
with the chosen effector (curve object for corve guides).
* Other dynamics should be quite easy to add to the effector
system too if wanted.
* "Unified" doesn't mean that force fields give the exact same results for
particles, softbody & cloth, since their final effect depends on many external
factors, like for example the surface area of the effected faces.
Code changes
* Subversion bump for correct handling of global gravity.
* Separate ui py file for common dynamics stuff.
* Particle settings updating is flushed with it's id through
DAG_id_flush_update(..).
Known issues
* Curve guides don't yet have all ui buttons in place, but they
should work none the less.
* Hair dynamics don't yet respect force fields.
Other changes
* Particle emission defaults now to frames 1-200 with life of 50
frames to fill the whole default timeline.
* Many particles drawing related crashes fixed.
* Sometimes particles didn't update on first frame properly.
* Hair with object/group visualization didn't work properly.
* Memory leaks with PointCacheID lists (Genscher, remember to
free pidlists after use :).
2009-09-30 22:10:14 +00:00
|
|
|
#include "BKE_effect.h"
|
2009-08-03 12:11:50 +00:00
|
|
|
#include "BKE_fcurve.h"
|
2020-05-01 12:43:12 +02:00
|
|
|
#include "BKE_fcurve_driver.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_font.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_gpencil.h"
|
2020-03-19 11:35:17 +01:00
|
|
|
#include "BKE_gpencil_geom.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "BKE_gpencil_modifier.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_hair.h"
|
2015-08-10 15:41:28 +02:00
|
|
|
#include "BKE_icons.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_idprop.h"
|
2020-03-05 10:54:00 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_image.h"
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
#include "BKE_key.h"
|
|
|
|
#include "BKE_lattice.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_layer.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
#include "BKE_lib_query.h"
|
|
|
|
#include "BKE_lib_remap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_light.h"
|
|
|
|
#include "BKE_lightprobe.h"
|
2013-03-23 03:00:37 +00:00
|
|
|
#include "BKE_linestyle.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_mball.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_mesh.h"
|
2020-06-10 22:32:06 +10:00
|
|
|
#include "BKE_mesh_wrapper.h"
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 20:30:33 +00:00
|
|
|
#include "BKE_modifier.h"
|
2015-05-07 15:16:10 +02:00
|
|
|
#include "BKE_multires.h"
|
2014-11-06 17:55:55 +01:00
|
|
|
#include "BKE_node.h"
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
#include "BKE_object.h"
|
2017-05-30 17:58:24 +10:00
|
|
|
#include "BKE_object_facemap.h"
|
2009-08-28 21:47:11 +00:00
|
|
|
#include "BKE_paint.h"
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
#include "BKE_particle.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_pbvh.h"
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
#include "BKE_pointcache.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_pointcloud.h"
|
2013-01-23 05:56:22 +00:00
|
|
|
#include "BKE_rigidbody.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_scene.h"
|
2010-03-09 13:52:52 +00:00
|
|
|
#include "BKE_sequencer.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "BKE_shader_fx.h"
|
2004-10-01 14:04:17 +00:00
|
|
|
#include "BKE_softbody.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_speaker.h"
|
2018-09-25 12:31:01 +02:00
|
|
|
#include "BKE_subdiv_ccg.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_subsurf.h"
|
2020-03-17 14:41:48 +01:00
|
|
|
#include "BKE_volume.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2017-04-06 15:37:46 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-05-25 12:27:54 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2017-04-06 15:37:46 +02:00
|
|
|
|
2017-04-03 19:01:10 +02:00
|
|
|
#include "DRW_engine.h"
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2019-04-17 06:17:24 +02:00
|
|
|
# include "BPY_extern.h"
|
2008-10-28 18:47:13 +00:00
|
|
|
#endif
|
2003-11-23 14:28:46 +00:00
|
|
|
|
2014-10-31 20:06:19 +01:00
|
|
|
#include "CCGSubSurf.h"
|
2017-04-26 15:40:32 +02:00
|
|
|
#include "atomic_ops.h"
|
2014-10-31 20:06:19 +01:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
static CLG_LogRef LOG = {"bke.object"};
|
|
|
|
|
2014-01-09 16:19:51 +06:00
|
|
|
/* Vertex parent modifies original BMesh which is not safe for threading.
|
|
|
|
* Ideally such a modification should be handled as a separate DAG update
|
|
|
|
* callback for mesh datablock, but for until it is actually supported use
|
|
|
|
* simpler solution with a mutex lock.
|
|
|
|
* - sergey -
|
|
|
|
*/
|
|
|
|
#define VPARENT_THREADING_HACK
|
|
|
|
|
|
|
|
#ifdef VPARENT_THREADING_HACK
|
|
|
|
static ThreadMutex vparent_lock = BLI_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
|
2020-03-05 10:54:00 +01:00
|
|
|
static void copy_object_pose(Object *obn, const Object *ob, const int flag);
|
|
|
|
static void copy_object_lod(Object *obn, const Object *ob, const int flag);
|
|
|
|
|
|
|
|
static void object_init_data(ID *id)
|
|
|
|
{
|
|
|
|
Object *ob = (Object *)id;
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ob, id));
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(ob, DNA_struct_default_get(Object), id);
|
|
|
|
|
|
|
|
ob->type = OB_EMPTY;
|
|
|
|
|
|
|
|
ob->trackflag = OB_POSY;
|
|
|
|
ob->upflag = OB_POSZ;
|
|
|
|
|
|
|
|
/* Animation Visualization defaults */
|
|
|
|
animviz_settings_init(&ob->avs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void object_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
{
|
|
|
|
Object *ob_dst = (Object *)id_dst;
|
|
|
|
const Object *ob_src = (const Object *)id_src;
|
|
|
|
|
|
|
|
/* Do not copy runtime data. */
|
|
|
|
BKE_object_runtime_reset_on_copy(ob_dst, flag);
|
|
|
|
|
|
|
|
/* We never handle usercount here for own data. */
|
|
|
|
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
|
|
|
|
|
|
|
|
if (ob_src->totcol) {
|
|
|
|
ob_dst->mat = MEM_dupallocN(ob_src->mat);
|
|
|
|
ob_dst->matbits = MEM_dupallocN(ob_src->matbits);
|
|
|
|
ob_dst->totcol = ob_src->totcol;
|
|
|
|
}
|
|
|
|
else if (ob_dst->mat != NULL || ob_dst->matbits != NULL) {
|
|
|
|
/* This shall not be needed, but better be safe than sorry. */
|
|
|
|
BLI_assert(!"Object copy: non-NULL material pointers with zero counter, should not happen.");
|
|
|
|
ob_dst->mat = NULL;
|
|
|
|
ob_dst->matbits = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob_src->iuser) {
|
|
|
|
ob_dst->iuser = MEM_dupallocN(ob_src->iuser);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob_src->runtime.bb) {
|
|
|
|
ob_dst->runtime.bb = MEM_dupallocN(ob_src->runtime.bb);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ob_dst->modifiers);
|
|
|
|
|
2020-05-07 10:11:40 +02:00
|
|
|
LISTBASE_FOREACH (ModifierData *, md, &ob_src->modifiers) {
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *nmd = BKE_modifier_new(md->type);
|
2020-03-05 10:54:00 +01:00
|
|
|
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_copydata_ex(md, nmd, flag_subdata);
|
2020-03-05 10:54:00 +01:00
|
|
|
BLI_addtail(&ob_dst->modifiers, nmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ob_dst->greasepencil_modifiers);
|
|
|
|
|
2020-05-07 10:11:40 +02:00
|
|
|
LISTBASE_FOREACH (GpencilModifierData *, gmd, &ob_src->greasepencil_modifiers) {
|
2020-03-05 10:54:00 +01:00
|
|
|
GpencilModifierData *nmd = BKE_gpencil_modifier_new(gmd->type);
|
|
|
|
BLI_strncpy(nmd->name, gmd->name, sizeof(nmd->name));
|
2020-05-08 10:32:30 +02:00
|
|
|
BKE_gpencil_modifier_copydata_ex(gmd, nmd, flag_subdata);
|
2020-03-05 10:54:00 +01:00
|
|
|
BLI_addtail(&ob_dst->greasepencil_modifiers, nmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ob_dst->shader_fx);
|
|
|
|
|
2020-05-07 10:11:40 +02:00
|
|
|
LISTBASE_FOREACH (ShaderFxData *, fx, &ob_src->shader_fx) {
|
2020-03-05 10:54:00 +01:00
|
|
|
ShaderFxData *nfx = BKE_shaderfx_new(fx->type);
|
|
|
|
BLI_strncpy(nfx->name, fx->name, sizeof(nfx->name));
|
2020-05-08 10:32:30 +02:00
|
|
|
BKE_shaderfx_copydata_ex(fx, nfx, flag_subdata);
|
2020-03-05 10:54:00 +01:00
|
|
|
BLI_addtail(&ob_dst->shader_fx, nfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob_src->pose) {
|
|
|
|
copy_object_pose(ob_dst, ob_src, flag_subdata);
|
|
|
|
/* backwards compat... non-armatures can get poses in older files? */
|
|
|
|
if (ob_src->type == OB_ARMATURE) {
|
|
|
|
const bool do_pose_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
|
|
|
|
BKE_pose_rebuild(bmain, ob_dst, ob_dst->data, do_pose_id_user);
|
|
|
|
}
|
|
|
|
}
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_defgroup_copy_list(&ob_dst->defbase, &ob_src->defbase);
|
2020-03-05 10:54:00 +01:00
|
|
|
BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps);
|
|
|
|
BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true);
|
|
|
|
|
|
|
|
ob_dst->mode = ob_dst->type != OB_GPENCIL ? OB_MODE_OBJECT : ob_dst->mode;
|
|
|
|
ob_dst->sculpt = NULL;
|
|
|
|
|
|
|
|
if (ob_src->pd) {
|
|
|
|
ob_dst->pd = MEM_dupallocN(ob_src->pd);
|
|
|
|
if (ob_dst->pd->rng) {
|
|
|
|
ob_dst->pd->rng = MEM_dupallocN(ob_src->pd->rng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BKE_object_copy_softbody(ob_dst, ob_src, flag_subdata);
|
|
|
|
BKE_rigidbody_object_copy(bmain, ob_dst, ob_src, flag_subdata);
|
|
|
|
|
|
|
|
BKE_object_copy_particlesystems(ob_dst, ob_src, flag_subdata);
|
|
|
|
|
|
|
|
BLI_listbase_clear((ListBase *)&ob_dst->drawdata);
|
|
|
|
BLI_listbase_clear(&ob_dst->pc_ids);
|
|
|
|
|
|
|
|
ob_dst->avs = ob_src->avs;
|
|
|
|
ob_dst->mpath = animviz_copy_motionpath(ob_src->mpath);
|
|
|
|
|
|
|
|
copy_object_lod(ob_dst, ob_src, flag_subdata);
|
|
|
|
|
|
|
|
/* Do not copy object's preview
|
|
|
|
* (mostly due to the fact renderers create temp copy of objects). */
|
|
|
|
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */
|
|
|
|
BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ob_dst->preview = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void object_free_data(ID *id)
|
|
|
|
{
|
|
|
|
Object *ob = (Object *)id;
|
|
|
|
|
|
|
|
DRW_drawdata_free((ID *)ob);
|
|
|
|
|
|
|
|
/* BKE_<id>_free shall never touch to ID->us. Never ever. */
|
|
|
|
BKE_object_free_modifiers(ob, LIB_ID_CREATE_NO_USER_REFCOUNT);
|
|
|
|
BKE_object_free_shaderfx(ob, LIB_ID_CREATE_NO_USER_REFCOUNT);
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(ob->mat);
|
|
|
|
MEM_SAFE_FREE(ob->matbits);
|
|
|
|
MEM_SAFE_FREE(ob->iuser);
|
|
|
|
MEM_SAFE_FREE(ob->runtime.bb);
|
|
|
|
|
|
|
|
BLI_freelistN(&ob->defbase);
|
|
|
|
BLI_freelistN(&ob->fmaps);
|
|
|
|
if (ob->pose) {
|
|
|
|
BKE_pose_free_ex(ob->pose, false);
|
|
|
|
ob->pose = NULL;
|
|
|
|
}
|
|
|
|
if (ob->mpath) {
|
|
|
|
animviz_free_motionpath(ob->mpath);
|
|
|
|
ob->mpath = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_constraints_free_ex(&ob->constraints, false);
|
|
|
|
|
|
|
|
BKE_partdeflect_free(ob->pd);
|
|
|
|
BKE_rigidbody_free_object(ob, NULL);
|
|
|
|
BKE_rigidbody_free_constraint(ob);
|
|
|
|
|
|
|
|
sbFree(ob);
|
|
|
|
|
|
|
|
BKE_sculptsession_free(ob);
|
|
|
|
|
|
|
|
BLI_freelistN(&ob->pc_ids);
|
|
|
|
|
|
|
|
BLI_freelistN(&ob->lodlevels);
|
|
|
|
|
|
|
|
/* Free runtime curves data. */
|
|
|
|
if (ob->runtime.curve_cache) {
|
|
|
|
BKE_curve_bevelList_free(&ob->runtime.curve_cache->bev);
|
|
|
|
if (ob->runtime.curve_cache->path) {
|
|
|
|
free_path(ob->runtime.curve_cache->path);
|
|
|
|
}
|
|
|
|
MEM_freeN(ob->runtime.curve_cache);
|
|
|
|
ob->runtime.curve_cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_previewimg_free(&ob->preview);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void object_make_local(Main *bmain, ID *id, const int flags)
|
|
|
|
{
|
|
|
|
Object *ob = (Object *)id;
|
|
|
|
const bool lib_local = (flags & LIB_ID_MAKELOCAL_FULL_LIBRARY) != 0;
|
|
|
|
const bool clear_proxy = (flags & LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING) == 0;
|
|
|
|
bool is_local = false, is_lib = false;
|
|
|
|
|
|
|
|
/* - only lib users: do nothing (unless force_local is set)
|
|
|
|
* - only local users: set flag
|
|
|
|
* - mixed: make copy
|
|
|
|
* In case we make a whole lib's content local,
|
|
|
|
* we always want to localize, and we skip remapping (done later).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!ID_IS_LINKED(ob)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_library_ID_test_usages(bmain, ob, &is_local, &is_lib);
|
|
|
|
|
|
|
|
if (lib_local || is_local) {
|
|
|
|
if (!is_lib) {
|
|
|
|
BKE_lib_id_clear_library_data(bmain, &ob->id);
|
|
|
|
BKE_lib_id_expand_local(bmain, &ob->id);
|
|
|
|
if (clear_proxy) {
|
|
|
|
if (ob->proxy_from != NULL) {
|
|
|
|
ob->proxy_from->proxy = NULL;
|
|
|
|
ob->proxy_from->proxy_group = NULL;
|
|
|
|
}
|
|
|
|
ob->proxy = ob->proxy_from = ob->proxy_group = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Object *ob_new = BKE_object_copy(bmain, ob);
|
|
|
|
|
|
|
|
ob_new->id.us = 0;
|
|
|
|
ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL;
|
|
|
|
|
|
|
|
/* setting newid is mandatory for complex make_lib_local logic... */
|
|
|
|
ID_NEW_SET(ob, ob_new);
|
|
|
|
|
|
|
|
if (!lib_local) {
|
|
|
|
BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:09:48 +02:00
|
|
|
static void library_foreach_modifiersForeachIDLink(void *user_data,
|
|
|
|
Object *UNUSED(object),
|
|
|
|
ID **id_pointer,
|
|
|
|
int cb_flag)
|
|
|
|
{
|
|
|
|
LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
|
|
|
|
BKE_lib_query_foreachid_process(data, id_pointer, cb_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void library_foreach_gpencil_modifiersForeachIDLink(void *user_data,
|
|
|
|
Object *UNUSED(object),
|
|
|
|
ID **id_pointer,
|
|
|
|
int cb_flag)
|
|
|
|
{
|
|
|
|
LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
|
|
|
|
BKE_lib_query_foreachid_process(data, id_pointer, cb_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void library_foreach_shaderfxForeachIDLink(void *user_data,
|
|
|
|
Object *UNUSED(object),
|
|
|
|
ID **id_pointer,
|
|
|
|
int cb_flag)
|
|
|
|
{
|
|
|
|
LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
|
|
|
|
BKE_lib_query_foreachid_process(data, id_pointer, cb_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void library_foreach_constraintObjectLooper(bConstraint *UNUSED(con),
|
|
|
|
ID **id_pointer,
|
|
|
|
bool is_reference,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
|
|
|
|
const int cb_flag = is_reference ? IDWALK_CB_USER : IDWALK_CB_NOP;
|
|
|
|
BKE_lib_query_foreachid_process(data, id_pointer, cb_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void library_foreach_particlesystemsObjectLooper(ParticleSystem *UNUSED(psys),
|
|
|
|
ID **id_pointer,
|
|
|
|
void *user_data,
|
|
|
|
int cb_flag)
|
|
|
|
{
|
|
|
|
LibraryForeachIDData *data = (LibraryForeachIDData *)user_data;
|
|
|
|
BKE_lib_query_foreachid_process(data, id_pointer, cb_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void object_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
{
|
|
|
|
Object *object = (Object *)id;
|
|
|
|
|
|
|
|
/* Object is special, proxies make things hard... */
|
|
|
|
const int proxy_cb_flag = ((BKE_lib_query_foreachid_process_flags_get(data) &
|
|
|
|
IDWALK_NO_INDIRECT_PROXY_DATA_USAGE) == 0 &&
|
|
|
|
(object->proxy || object->proxy_group)) ?
|
|
|
|
IDWALK_CB_INDIRECT_USAGE :
|
|
|
|
0;
|
|
|
|
|
|
|
|
/* object data special case */
|
|
|
|
if (object->type == OB_EMPTY) {
|
|
|
|
/* empty can have NULL or Image */
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID(data, object->data, proxy_cb_flag | IDWALK_CB_USER);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* when set, this can't be NULL */
|
|
|
|
if (object->data) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID(
|
|
|
|
data, object->data, proxy_cb_flag | IDWALK_CB_USER | IDWALK_CB_NEVER_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->parent, IDWALK_CB_NEVER_SELF);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->track, IDWALK_CB_NEVER_SELF);
|
|
|
|
/* object->proxy is refcounted, but not object->proxy_group... *sigh* */
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->proxy, IDWALK_CB_USER | IDWALK_CB_NEVER_SELF);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->proxy_group, IDWALK_CB_NOP);
|
|
|
|
|
|
|
|
/* Special case!
|
|
|
|
* Since this field is set/owned by 'user' of this ID (and not ID itself),
|
|
|
|
* it is only indirect usage if proxy object is linked... Twisted. */
|
|
|
|
{
|
|
|
|
const int cb_flag_orig = BKE_lib_query_foreachid_process_callback_flag_override(
|
|
|
|
data,
|
|
|
|
(object->proxy_from != NULL && ID_IS_LINKED(object->proxy_from)) ?
|
|
|
|
IDWALK_CB_INDIRECT_USAGE :
|
|
|
|
0,
|
|
|
|
true);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->proxy_from, IDWALK_CB_LOOPBACK | IDWALK_CB_NEVER_SELF);
|
|
|
|
BKE_lib_query_foreachid_process_callback_flag_override(data, cb_flag_orig, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->poselib, IDWALK_CB_USER);
|
|
|
|
|
|
|
|
for (int i = 0; i < object->totcol; i++) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->mat[i], proxy_cb_flag | IDWALK_CB_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that ob->gpd is deprecated, so no need to handle it here. */
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->instance_collection, IDWALK_CB_USER);
|
|
|
|
|
|
|
|
if (object->pd) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->pd->tex, IDWALK_CB_USER);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->pd->f_source, IDWALK_CB_NOP);
|
|
|
|
}
|
|
|
|
/* Note that ob->effect is deprecated, so no need to handle it here. */
|
|
|
|
|
|
|
|
if (object->pose) {
|
|
|
|
const int cb_flag_orig = BKE_lib_query_foreachid_process_callback_flag_override(
|
|
|
|
data, proxy_cb_flag, false);
|
|
|
|
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
|
|
|
|
IDP_foreach_property(
|
|
|
|
pchan->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, pchan->custom, IDWALK_CB_USER);
|
|
|
|
BKE_constraints_id_loop(&pchan->constraints, library_foreach_constraintObjectLooper, data);
|
|
|
|
}
|
|
|
|
BKE_lib_query_foreachid_process_callback_flag_override(data, cb_flag_orig, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object->rigidbody_constraint) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->rigidbody_constraint->ob1, IDWALK_CB_NEVER_SELF);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->rigidbody_constraint->ob2, IDWALK_CB_NEVER_SELF);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object->lodlevels.first) {
|
|
|
|
LISTBASE_FOREACH (LodLevel *, level, &object->lodlevels) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, level->source, IDWALK_CB_NEVER_SELF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_modifiers_foreach_ID_link(object, library_foreach_modifiersForeachIDLink, data);
|
|
|
|
BKE_gpencil_modifiers_foreach_ID_link(
|
2020-05-21 23:20:29 +02:00
|
|
|
object, library_foreach_gpencil_modifiersForeachIDLink, data);
|
2020-05-21 19:09:48 +02:00
|
|
|
BKE_constraints_id_loop(&object->constraints, library_foreach_constraintObjectLooper, data);
|
|
|
|
BKE_shaderfx_foreach_ID_link(object, library_foreach_shaderfxForeachIDLink, data);
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
|
|
|
|
BKE_particlesystem_id_loop(psys, library_foreach_particlesystemsObjectLooper, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object->soft) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->soft->collision_group, IDWALK_CB_NOP);
|
|
|
|
|
|
|
|
if (object->soft->effector_weights) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, object->soft->effector_weights->group, IDWALK_CB_NOP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 10:54:00 +01:00
|
|
|
IDTypeInfo IDType_ID_OB = {
|
|
|
|
.id_code = ID_OB,
|
|
|
|
.id_filter = FILTER_ID_OB,
|
|
|
|
.main_listbase_index = INDEX_ID_OB,
|
|
|
|
.struct_size = sizeof(Object),
|
|
|
|
.name = "Object",
|
|
|
|
.name_plural = "objects",
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_OBJECT,
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
.init_data = object_init_data,
|
|
|
|
.copy_data = object_copy_data,
|
|
|
|
.free_data = object_free_data,
|
|
|
|
.make_local = object_make_local,
|
2020-05-21 19:09:48 +02:00
|
|
|
.foreach_id = object_foreach_id,
|
2020-03-05 10:54:00 +01:00
|
|
|
};
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_workob_clear(Object *workob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(workob, 0, sizeof(Object));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f;
|
|
|
|
workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f;
|
|
|
|
workob->rotmode = ROT_MODE_EUL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_free_particlesystems(Object *ob)
|
2008-02-27 17:04:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ParticleSystem *psys;
|
2013-08-26 23:37:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((psys = BLI_pophead(&ob->particlesystem))) {
|
|
|
|
psys_free(ob, psys);
|
|
|
|
}
|
2008-02-27 17:04:58 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_free_softbody(Object *ob)
|
2008-02-27 17:04:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
sbFree(ob);
|
2008-02-27 17:04:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-19 09:25:24 +00:00
|
|
|
void BKE_object_free_curve_cache(Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->runtime.curve_cache) {
|
|
|
|
BKE_displist_free(&ob->runtime.curve_cache->disp);
|
|
|
|
BKE_curve_bevelList_free(&ob->runtime.curve_cache->bev);
|
|
|
|
if (ob->runtime.curve_cache->path) {
|
|
|
|
free_path(ob->runtime.curve_cache->path);
|
|
|
|
}
|
|
|
|
BKE_nurbList_free(&ob->runtime.curve_cache->deformed_nurbs);
|
|
|
|
MEM_freeN(ob->runtime.curve_cache);
|
|
|
|
ob->runtime.curve_cache = NULL;
|
|
|
|
}
|
2013-08-19 09:25:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 14:56:32 +02:00
|
|
|
void BKE_object_free_modifiers(Object *ob, const int flag)
|
2005-07-19 20:14:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md;
|
|
|
|
GpencilModifierData *gp_md;
|
2013-08-26 23:37:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((md = BLI_pophead(&ob->modifiers))) {
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_free_ex(md, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((gp_md = BLI_pophead(&ob->greasepencil_modifiers))) {
|
|
|
|
BKE_gpencil_modifier_free_ex(gp_md, flag);
|
|
|
|
}
|
|
|
|
/* particle modifiers were freed, so free the particlesystems as well */
|
|
|
|
BKE_object_free_particlesystems(ob);
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same for softbody */
|
|
|
|
BKE_object_free_softbody(ob);
|
2015-11-11 01:56:39 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* modifiers may have stored data in the DM cache */
|
|
|
|
BKE_object_free_derived_caches(ob);
|
2005-07-19 20:14:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
void BKE_object_free_shaderfx(Object *ob, const int flag)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ShaderFxData *fx;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((fx = BLI_pophead(&ob->shader_fx))) {
|
|
|
|
BKE_shaderfx_free_ex(fx, flag);
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2013-10-15 20:15:45 +00:00
|
|
|
void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* reset functionality */
|
|
|
|
if (hmd->object) {
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget);
|
2013-10-15 20:15:45 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (hmd->subtarget[0] && pchan) {
|
|
|
|
float imat[4][4], mat[4][4];
|
2013-10-15 20:15:45 +00:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Calculate the world-space matrix for the pose-channel target first,
|
|
|
|
* then carry on as usual. */
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat);
|
2013-10-15 20:15:45 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
mul_m4_m4m4(hmd->parentinv, imat, ob->obmat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
invert_m4_m4(hmd->object->imat, hmd->object->obmat);
|
|
|
|
mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat);
|
|
|
|
}
|
|
|
|
}
|
2013-10-15 20:15:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
void BKE_object_modifier_gpencil_hook_reset(Object *ob, HookGpencilModifierData *hmd)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (hmd->object == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* reset functionality */
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (hmd->subtarget[0] && pchan) {
|
|
|
|
float imat[4][4], mat[4][4];
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Calculate the world-space matrix for the pose-channel target first,
|
|
|
|
* then carry on as usual. */
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
mul_m4_m4m4(hmd->parentinv, imat, ob->obmat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
invert_m4_m4(hmd->object->imat, hmd->object->obmat);
|
|
|
|
mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat);
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
|
2012-03-12 14:35:07 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const ModifierTypeInfo *mti;
|
2012-03-12 14:35:07 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
mti = BKE_modifier_get_info(modifier_type);
|
2012-03-12 14:35:07 +00:00
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
/* Only geometry objects should be able to get modifiers [#25291] */
|
|
|
|
if (ob->type == OB_HAIR) {
|
|
|
|
return (mti->modifyHair != NULL) || (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-04-21 13:09:41 +02:00
|
|
|
else if (ob->type == OB_POINTCLOUD) {
|
|
|
|
return (mti->modifyPointCloud != NULL) ||
|
|
|
|
(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_VOLUME) {
|
|
|
|
return (mti->modifyVolume != NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-04-21 13:09:41 +02:00
|
|
|
else if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
|
|
|
|
if (ob->type == OB_LATTICE && (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
|
|
|
|
(ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 22:21:46 +10:00
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-12 14:35:07 +00:00
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
return false;
|
2012-03-12 14:35:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 12:35:51 +01:00
|
|
|
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
|
2010-01-04 16:26:07 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_free_modifiers(ob_dst, 0);
|
2010-01-04 16:26:07 +00:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* only objects listed above can have modifiers and linking them to objects
|
|
|
|
* which doesn't have modifiers stack is quite silly */
|
|
|
|
return;
|
|
|
|
}
|
2012-03-12 14:35:07 +00:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
/* No grease pencil modifiers. */
|
|
|
|
if ((ob_src->type != OB_GPENCIL) && (ob_dst->type != OB_GPENCIL)) {
|
|
|
|
LISTBASE_FOREACH (ModifierData *, md, &ob_src->modifiers) {
|
|
|
|
ModifierData *nmd = NULL;
|
2010-01-04 16:26:07 +00:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-01-04 16:26:07 +00:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-02 20:23:01 +10:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
switch (md->type) {
|
|
|
|
case eModifierType_Softbody:
|
|
|
|
BKE_object_copy_softbody(ob_dst, ob_src, 0);
|
|
|
|
break;
|
|
|
|
case eModifierType_Skin:
|
|
|
|
/* ensure skin-node customdata exists */
|
|
|
|
BKE_mesh_ensure_skin_customdata(ob_dst->data);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-12 14:35:07 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
nmd = BKE_modifier_new(md->type);
|
2020-05-07 09:57:28 +02:00
|
|
|
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
|
2015-05-07 15:16:10 +02:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
if (md->type == eModifierType_Multires) {
|
|
|
|
/* Has to be done after mod creation, but *before* we actually copy its settings! */
|
|
|
|
multiresModifier_sync_levels_ex(
|
|
|
|
ob_dst, (MultiresModifierData *)md, (MultiresModifierData *)nmd);
|
|
|
|
}
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_copydata(md, nmd);
|
2020-05-07 09:57:28 +02:00
|
|
|
BLI_addtail(&ob_dst->modifiers, nmd);
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_unique_name(&ob_dst->modifiers, nmd);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-05-07 09:57:28 +02:00
|
|
|
}
|
2015-05-07 15:16:10 +02:00
|
|
|
|
2020-05-07 09:57:28 +02:00
|
|
|
/* Copy grease pencil modifiers. */
|
|
|
|
if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
|
|
|
|
LISTBASE_FOREACH (GpencilModifierData *, md, &ob_src->greasepencil_modifiers) {
|
|
|
|
GpencilModifierData *nmd = NULL;
|
|
|
|
|
|
|
|
nmd = BKE_gpencil_modifier_new(md->type);
|
|
|
|
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
|
|
|
|
|
2020-05-08 10:32:30 +02:00
|
|
|
const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
|
2020-05-07 09:57:28 +02:00
|
|
|
mti->copyData(md, nmd);
|
|
|
|
|
|
|
|
BLI_addtail(&ob_dst->greasepencil_modifiers, nmd);
|
|
|
|
BKE_gpencil_modifier_unique_name(&ob_dst->greasepencil_modifiers, nmd);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-01-04 16:26:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_copy_particlesystems(ob_dst, ob_src, 0);
|
2010-01-04 16:26:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: smoke?, cloth? */
|
2010-01-04 16:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 12:31:01 +02:00
|
|
|
/* Copy CCG related data. Used to sync copy of mesh with reshaped original
|
|
|
|
* mesh.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
static void copy_ccg_data(Mesh *mesh_destination, Mesh *mesh_source, int layer_type)
|
|
|
|
{
|
|
|
|
BLI_assert(mesh_destination->totloop == mesh_source->totloop);
|
|
|
|
CustomData *data_destination = &mesh_destination->ldata;
|
|
|
|
CustomData *data_source = &mesh_source->ldata;
|
|
|
|
const int num_elements = mesh_source->totloop;
|
|
|
|
if (!CustomData_has_layer(data_source, layer_type)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int layer_index = CustomData_get_layer_index(data_destination, layer_type);
|
|
|
|
CustomData_free_layer(data_destination, layer_type, num_elements, layer_index);
|
|
|
|
BLI_assert(!CustomData_has_layer(data_destination, layer_type));
|
|
|
|
CustomData_add_layer(data_destination, layer_type, CD_CALLOC, NULL, num_elements);
|
|
|
|
BLI_assert(CustomData_has_layer(data_destination, layer_type));
|
|
|
|
CustomData_copy_layer_type_data(data_source, data_destination, layer_type, 0, 0, num_elements);
|
2018-09-25 12:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void object_update_from_subsurf_ccg(Object *object)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Currently CCG is only created for Mesh objects. */
|
|
|
|
if (object->type != OB_MESH) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-27 11:45:33 +02:00
|
|
|
/* If object does not own evaluated mesh we can not access it since it might be freed already
|
|
|
|
* (happens on dependency graph free where order of CoW-ed IDs free is undefined).
|
|
|
|
*
|
|
|
|
* Good news is: such mesh does not have modifiers applied, so no need to worry about CCG. */
|
2020-02-27 11:23:15 +01:00
|
|
|
if (!object->runtime.is_data_eval_owned) {
|
2019-05-27 11:45:33 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Object was never evaluated, so can not have CCG subdivision surface. */
|
2020-02-27 11:23:15 +01:00
|
|
|
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (mesh_eval == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SubdivCCG *subdiv_ccg = mesh_eval->runtime.subdiv_ccg;
|
|
|
|
if (subdiv_ccg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Check whether there is anything to be reshaped. */
|
|
|
|
if (!subdiv_ccg->dirty.coords && !subdiv_ccg->dirty.hidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int tot_level = mesh_eval->runtime.subdiv_ccg_tot_level;
|
|
|
|
Object *object_orig = DEG_get_original_object(object);
|
|
|
|
Mesh *mesh_orig = (Mesh *)object_orig->data;
|
|
|
|
multiresModifier_reshapeFromCCG(tot_level, mesh_orig, subdiv_ccg);
|
|
|
|
/* NOTE: we need to reshape into an original mesh from main database,
|
|
|
|
* allowing:
|
|
|
|
*
|
|
|
|
* - Update copies of that mesh at any moment.
|
|
|
|
* - Save the file without doing extra reshape.
|
|
|
|
* - All the users of the mesh have updated displacement.
|
|
|
|
*
|
|
|
|
* However, the tricky part here is that we only know about sculpted
|
|
|
|
* state of a mesh on an object level, and object is being updated after
|
|
|
|
* mesh datablock is updated. This forces us to:
|
|
|
|
*
|
|
|
|
* - Update mesh datablock from object evaluation, which is technically
|
|
|
|
* forbidden, but there is no other place for this yet.
|
|
|
|
* - Reshape to the original mesh from main database, and then copy updated
|
|
|
|
* layer to copy of that mesh (since copy of the mesh has decoupled
|
|
|
|
* custom data layers).
|
|
|
|
*
|
|
|
|
* All this is defeating all the designs we need to follow to allow safe
|
|
|
|
* threaded evaluation, but this is as good as we can make it within the
|
|
|
|
* current sculpt//evaluated mesh design. This is also how we've survived
|
|
|
|
* with old DerivedMesh based solutions. So, while this is all wrong and
|
|
|
|
* needs reconsideration, doesn't seem to be a big stopper for real
|
|
|
|
* production artists.
|
|
|
|
*/
|
|
|
|
/* TODO(sergey): Solve this somehow, to be fully stable for threaded
|
|
|
|
* evaluation environment.
|
|
|
|
*/
|
2020-02-27 11:23:15 +01:00
|
|
|
/* NOTE: runtime.data_orig is what was before assigning mesh_eval,
|
2019-04-17 06:17:24 +02:00
|
|
|
* it is orig as in what was in object_eval->data before evaluating
|
|
|
|
* modifier stack.
|
|
|
|
*
|
|
|
|
* mesh_cow is a copy-on-written version od object_orig->data.
|
|
|
|
*/
|
2020-02-27 11:23:15 +01:00
|
|
|
Mesh *mesh_cow = (Mesh *)object->runtime.data_orig;
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_ccg_data(mesh_cow, mesh_orig, CD_MDISPS);
|
|
|
|
copy_ccg_data(mesh_cow, mesh_orig, CD_GRID_PAINT_MASK);
|
|
|
|
/* Everything is now up-to-date. */
|
|
|
|
subdiv_ccg->dirty.coords = false;
|
|
|
|
subdiv_ccg->dirty.hidden = false;
|
2018-09-25 12:31:01 +02:00
|
|
|
}
|
|
|
|
|
2020-02-27 11:23:15 +01:00
|
|
|
/* Assign data after modifier stack evaluation. */
|
|
|
|
void BKE_object_eval_assign_data(Object *object_eval, ID *data_eval, bool is_owned)
|
|
|
|
{
|
|
|
|
BLI_assert(object_eval->id.tag & LIB_TAG_COPIED_ON_WRITE);
|
|
|
|
BLI_assert(object_eval->runtime.data_eval == NULL);
|
|
|
|
BLI_assert(data_eval->tag & LIB_TAG_NO_MAIN);
|
|
|
|
|
|
|
|
if (is_owned) {
|
|
|
|
/* Set flag for debugging. */
|
|
|
|
data_eval->tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assigned evaluated data. */
|
|
|
|
object_eval->runtime.data_eval = data_eval;
|
|
|
|
object_eval->runtime.is_data_eval_owned = is_owned;
|
|
|
|
|
|
|
|
/* Overwrite data of evaluated object, if the datablock types match. */
|
|
|
|
ID *data = object_eval->data;
|
|
|
|
if (GS(data->name) == GS(data_eval->name)) {
|
|
|
|
/* NOTE: we are not supposed to invoke evaluation for original objects,
|
|
|
|
* but some areas are still being ported, so we play safe here. */
|
|
|
|
if (object_eval->id.tag & LIB_TAG_COPIED_ON_WRITE) {
|
|
|
|
object_eval->data = data_eval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-18 10:24:34 +00:00
|
|
|
/* free data derived from mesh, called when mesh changes or is freed */
|
|
|
|
void BKE_object_free_derived_caches(Object *ob)
|
2005-11-27 20:49:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_SAFE_FREE(ob->runtime.bb);
|
|
|
|
|
|
|
|
object_update_from_subsurf_ccg(ob);
|
|
|
|
|
2020-02-27 11:23:15 +01:00
|
|
|
if (ob->runtime.data_eval != NULL) {
|
|
|
|
if (ob->runtime.is_data_eval_owned) {
|
|
|
|
ID *data_eval = ob->runtime.data_eval;
|
|
|
|
if (GS(data_eval->name) == ID_ME) {
|
|
|
|
BKE_mesh_eval_delete((Mesh *)data_eval);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_libblock_free_datablock(data_eval, 0);
|
|
|
|
MEM_freeN(data_eval);
|
|
|
|
}
|
2019-05-31 17:03:40 +02:00
|
|
|
}
|
2020-02-27 11:23:15 +01:00
|
|
|
ob->runtime.data_eval = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (ob->runtime.mesh_deform_eval != NULL) {
|
|
|
|
Mesh *mesh_deform_eval = ob->runtime.mesh_deform_eval;
|
2019-07-28 15:12:38 +02:00
|
|
|
BKE_mesh_eval_delete(mesh_deform_eval);
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->runtime.mesh_deform_eval = NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-27 11:23:15 +01:00
|
|
|
/* Restore initial pointer for copy-on-write datablocks, object->data
|
|
|
|
* might be pointing to an evaluated datablock data was just freed above. */
|
|
|
|
if (ob->runtime.data_orig != NULL) {
|
|
|
|
ob->data = ob->runtime.data_orig;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:49:21 +02:00
|
|
|
BKE_object_to_mesh_clear(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_free_curve_cache(ob);
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
/* Clear grease pencil data. */
|
|
|
|
if (ob->runtime.gpd_eval != NULL) {
|
|
|
|
BKE_gpencil_eval_delete(ob->runtime.gpd_eval);
|
|
|
|
ob->runtime.gpd_eval = NULL;
|
|
|
|
}
|
2005-11-27 20:49:25 +00:00
|
|
|
}
|
2011-09-14 00:37:27 +00:00
|
|
|
|
2015-02-17 17:27:15 +05:00
|
|
|
void BKE_object_free_caches(Object *object)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md;
|
|
|
|
short update_flag = 0;
|
|
|
|
|
|
|
|
/* Free particle system caches holding paths. */
|
|
|
|
if (object->particlesystem.first) {
|
|
|
|
ParticleSystem *psys;
|
|
|
|
for (psys = object->particlesystem.first; psys != NULL; psys = psys->next) {
|
|
|
|
psys_free_path_cache(psys, psys->edit);
|
|
|
|
update_flag |= ID_RECALC_PSYS_REDO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free memory used by cached derived meshes in the particle system modifiers. */
|
|
|
|
for (md = object->modifiers.first; md != NULL; md = md->next) {
|
|
|
|
if (md->type == eModifierType_ParticleSystem) {
|
|
|
|
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
|
2019-06-21 11:49:43 +02:00
|
|
|
if (psmd->mesh_final) {
|
|
|
|
BKE_id_free(NULL, psmd->mesh_final);
|
|
|
|
psmd->mesh_final = NULL;
|
|
|
|
if (psmd->mesh_original) {
|
|
|
|
BKE_id_free(NULL, psmd->mesh_original);
|
|
|
|
psmd->mesh_original = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
psmd->flag |= eParticleSystemFlag_file_loaded;
|
|
|
|
update_flag |= ID_RECALC_GEOMETRY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: If object is coming from a duplicator, it might be a temporary
|
|
|
|
* object created by dependency graph, which shares pointers with original
|
|
|
|
* object. In this case we can not free anything.
|
|
|
|
*/
|
|
|
|
if ((object->base_flag & BASE_FROM_DUPLI) == 0) {
|
|
|
|
BKE_object_free_derived_caches(object);
|
|
|
|
update_flag |= ID_RECALC_GEOMETRY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tag object for update, so once memory critical operation is over and
|
|
|
|
* scene update routines are back to it's business the object will be
|
|
|
|
* guaranteed to be in a known state.
|
|
|
|
*/
|
|
|
|
if (update_flag != 0) {
|
|
|
|
DEG_id_tag_update(&object->id, update_flag);
|
|
|
|
}
|
2015-02-17 17:27:15 +05:00
|
|
|
}
|
|
|
|
|
2012-12-17 14:51:06 +00:00
|
|
|
/* actual check for internal data, not context or flags */
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_is_in_editmode(const Object *ob)
|
2012-12-17 14:51:06 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->data == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return ((Mesh *)ob->data)->edit_mesh != NULL;
|
|
|
|
case OB_ARMATURE:
|
|
|
|
return ((bArmature *)ob->data)->edbo != NULL;
|
|
|
|
case OB_FONT:
|
|
|
|
return ((Curve *)ob->data)->editfont != NULL;
|
|
|
|
case OB_MBALL:
|
|
|
|
return ((MetaBall *)ob->data)->editelems != NULL;
|
|
|
|
case OB_LATTICE:
|
|
|
|
return ((Lattice *)ob->data)->editlatt != NULL;
|
|
|
|
case OB_SURF:
|
|
|
|
case OB_CURVE:
|
|
|
|
return ((Curve *)ob->data)->editnurb != NULL;
|
2020-03-09 16:27:24 +01:00
|
|
|
case OB_GPENCIL:
|
|
|
|
/* Grease Pencil object has no edit mode data. */
|
|
|
|
return GPENCIL_EDIT_MODE((bGPdata *)ob->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-17 14:51:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
|
2013-07-01 20:27:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (OB_TYPE_SUPPORT_VGROUP(ob->type) && BKE_object_is_in_editmode(ob));
|
2013-07-01 20:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 10:15:36 +02:00
|
|
|
bool BKE_object_data_is_in_editmode(const ID *id)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const short type = GS(id->name);
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_EDITMODE(type));
|
|
|
|
switch (type) {
|
|
|
|
case ID_ME:
|
|
|
|
return ((const Mesh *)id)->edit_mesh != NULL;
|
|
|
|
case ID_CU:
|
|
|
|
return ((((const Curve *)id)->editnurb != NULL) || (((const Curve *)id)->editfont != NULL));
|
|
|
|
case ID_MB:
|
|
|
|
return ((const MetaBall *)id)->editelems != NULL;
|
|
|
|
case ID_LT:
|
|
|
|
return ((const Lattice *)id)->editlatt != NULL;
|
|
|
|
case ID_AR:
|
|
|
|
return ((const bArmature *)id)->edbo != NULL;
|
|
|
|
default:
|
|
|
|
BLI_assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 10:15:36 +02:00
|
|
|
}
|
|
|
|
|
2019-11-07 16:52:03 +11:00
|
|
|
char *BKE_object_data_editmode_flush_ptr_get(struct ID *id)
|
|
|
|
{
|
|
|
|
const short type = GS(id->name);
|
|
|
|
switch (type) {
|
|
|
|
case ID_ME: {
|
|
|
|
BMEditMesh *em = ((Mesh *)id)->edit_mesh;
|
|
|
|
if (em != NULL) {
|
|
|
|
return &em->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_CU: {
|
|
|
|
if (((Curve *)id)->vfont != NULL) {
|
|
|
|
EditFont *ef = ((Curve *)id)->editfont;
|
|
|
|
if (ef != NULL) {
|
|
|
|
return &ef->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EditNurb *editnurb = ((Curve *)id)->editnurb;
|
|
|
|
if (editnurb) {
|
|
|
|
return &editnurb->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_MB: {
|
|
|
|
MetaBall *mb = (MetaBall *)id;
|
|
|
|
return &mb->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
case ID_LT: {
|
|
|
|
EditLatt *editlatt = ((Lattice *)id)->editlatt;
|
|
|
|
if (editlatt) {
|
|
|
|
return &editlatt->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_AR: {
|
|
|
|
bArmature *arm = (bArmature *)id;
|
|
|
|
return &arm->needs_flush_to_id;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
BLI_assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
bool BKE_object_is_in_wpaint_select_vert(const Object *ob)
|
2013-07-01 20:27:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
return ((ob->mode & OB_MODE_WEIGHT_PAINT) && (me->edit_mesh == NULL) &&
|
|
|
|
(ME_EDIT_PAINT_SEL_MODE(me) == SCE_SELECT_VERTEX));
|
|
|
|
}
|
2013-07-01 20:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2013-07-01 20:27:03 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 16:27:55 +02:00
|
|
|
bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (object_mode & OB_MODE_EDIT) {
|
|
|
|
if (BKE_object_is_in_editmode(ob)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (object_mode & OB_MODE_VERTEX_PAINT) {
|
|
|
|
if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (object_mode & OB_MODE_WEIGHT_PAINT) {
|
|
|
|
if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (object_mode & OB_MODE_SCULPT) {
|
|
|
|
if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (object_mode & OB_MODE_POSE) {
|
|
|
|
if (ob->pose != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-04-16 16:27:55 +02:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:43:53 +02:00
|
|
|
bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((ob->mode == object_mode) || (ob->mode & object_mode) != 0);
|
2018-05-29 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 12:55:14 +02:00
|
|
|
/**
|
2018-12-18 18:18:00 +01:00
|
|
|
* Return which parts of the object are visible, as evaluated by depsgraph
|
2017-09-21 12:55:14 +02:00
|
|
|
*/
|
2018-12-18 18:18:00 +01:00
|
|
|
int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
|
2017-09-21 12:55:14 +02:00
|
|
|
{
|
2019-10-03 19:22:36 -03:00
|
|
|
if ((ob->base_flag & BASE_VISIBLE_DEPSGRAPH) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test which components the object has. */
|
|
|
|
int visibility = OB_VISIBLE_SELF;
|
|
|
|
if (ob->particlesystem.first) {
|
|
|
|
visibility |= OB_VISIBLE_INSTANCES | OB_VISIBLE_PARTICLES;
|
|
|
|
}
|
|
|
|
else if (ob->transflag & OB_DUPLI) {
|
|
|
|
visibility |= OB_VISIBLE_INSTANCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Optional hiding of self if there are particles or instancers. */
|
|
|
|
if (visibility & (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) {
|
|
|
|
switch ((eEvaluationMode)dag_eval_mode) {
|
|
|
|
case DAG_EVAL_VIEWPORT:
|
|
|
|
if (!(ob->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT)) {
|
|
|
|
visibility &= ~OB_VISIBLE_SELF;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DAG_EVAL_RENDER:
|
|
|
|
if (!(ob->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER)) {
|
|
|
|
visibility &= ~OB_VISIBLE_SELF;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return visibility;
|
2017-09-21 12:55:14 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:27:47 +02:00
|
|
|
bool BKE_object_exists_check(Main *bmain, const Object *obtest)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (obtest == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = bmain->objects.first;
|
|
|
|
while (ob) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob == obtest) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = ob->id.next;
|
|
|
|
}
|
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* *************************************************** */
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
static const char *get_obdata_defname(int type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return DATA_("Mesh");
|
|
|
|
case OB_CURVE:
|
|
|
|
return DATA_("Curve");
|
|
|
|
case OB_SURF:
|
|
|
|
return DATA_("Surf");
|
|
|
|
case OB_FONT:
|
|
|
|
return DATA_("Text");
|
|
|
|
case OB_MBALL:
|
|
|
|
return DATA_("Mball");
|
|
|
|
case OB_CAMERA:
|
|
|
|
return DATA_("Camera");
|
|
|
|
case OB_LAMP:
|
|
|
|
return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
|
|
|
|
case OB_LATTICE:
|
|
|
|
return DATA_("Lattice");
|
|
|
|
case OB_ARMATURE:
|
|
|
|
return DATA_("Armature");
|
|
|
|
case OB_SPEAKER:
|
|
|
|
return DATA_("Speaker");
|
2020-03-17 14:41:48 +01:00
|
|
|
case OB_HAIR:
|
|
|
|
return DATA_("Hair");
|
|
|
|
case OB_POINTCLOUD:
|
|
|
|
return DATA_("PointCloud");
|
|
|
|
case OB_VOLUME:
|
|
|
|
return DATA_("Volume");
|
2019-04-17 06:17:24 +02:00
|
|
|
case OB_EMPTY:
|
|
|
|
return DATA_("Empty");
|
|
|
|
case OB_GPENCIL:
|
|
|
|
return DATA_("GPencil");
|
2020-01-17 19:14:23 +01:00
|
|
|
case OB_LIGHTPROBE:
|
|
|
|
return DATA_("LightProbe");
|
2019-04-17 06:17:24 +02:00
|
|
|
default:
|
|
|
|
CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
|
|
|
|
return DATA_("Empty");
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 11:18:14 +01:00
|
|
|
static void object_init(Object *ob, const short ob_type)
|
|
|
|
{
|
|
|
|
object_init_data(&ob->id);
|
|
|
|
|
|
|
|
ob->type = ob_type;
|
|
|
|
|
|
|
|
if (ob->type != OB_EMPTY) {
|
|
|
|
zero_v2(ob->ima_ofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
|
|
|
|
ob->trackflag = OB_NEGZ;
|
|
|
|
ob->upflag = OB_POSY;
|
|
|
|
}
|
2020-03-09 16:27:24 +01:00
|
|
|
|
|
|
|
if (ob->type == OB_GPENCIL) {
|
|
|
|
ob->dtx |= OB_USE_GPENCIL_LIGHTS;
|
|
|
|
}
|
2020-03-06 11:18:14 +01:00
|
|
|
}
|
|
|
|
|
2015-05-04 12:25:33 +10:00
|
|
|
void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (name == NULL) {
|
|
|
|
name = get_obdata_defname(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return BKE_mesh_add(bmain, name);
|
|
|
|
case OB_CURVE:
|
|
|
|
return BKE_curve_add(bmain, name, OB_CURVE);
|
|
|
|
case OB_SURF:
|
|
|
|
return BKE_curve_add(bmain, name, OB_SURF);
|
|
|
|
case OB_FONT:
|
|
|
|
return BKE_curve_add(bmain, name, OB_FONT);
|
|
|
|
case OB_MBALL:
|
|
|
|
return BKE_mball_add(bmain, name);
|
|
|
|
case OB_CAMERA:
|
|
|
|
return BKE_camera_add(bmain, name);
|
|
|
|
case OB_LAMP:
|
|
|
|
return BKE_light_add(bmain, name);
|
|
|
|
case OB_LATTICE:
|
|
|
|
return BKE_lattice_add(bmain, name);
|
|
|
|
case OB_ARMATURE:
|
|
|
|
return BKE_armature_add(bmain, name);
|
|
|
|
case OB_SPEAKER:
|
|
|
|
return BKE_speaker_add(bmain, name);
|
|
|
|
case OB_LIGHTPROBE:
|
|
|
|
return BKE_lightprobe_add(bmain, name);
|
|
|
|
case OB_GPENCIL:
|
|
|
|
return BKE_gpencil_data_addnew(bmain, name);
|
2020-03-17 14:41:48 +01:00
|
|
|
case OB_HAIR:
|
|
|
|
return BKE_hair_add(bmain, name);
|
|
|
|
case OB_POINTCLOUD:
|
|
|
|
return BKE_pointcloud_add(bmain, name);
|
|
|
|
case OB_VOLUME:
|
|
|
|
return BKE_volume_add(bmain, name);
|
2019-04-17 06:17:24 +02:00
|
|
|
case OB_EMPTY:
|
|
|
|
return NULL;
|
|
|
|
default:
|
|
|
|
CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-04 12:25:33 +10:00
|
|
|
}
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
/* more general add: creates minimum required data, but without vertices etc. */
|
|
|
|
Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!name) {
|
2019-04-17 06:17:24 +02:00
|
|
|
name = get_obdata_defname(type);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = BKE_libblock_alloc(bmain, ID_OB, name, 0);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* We increase object user count when linking to Collections. */
|
|
|
|
id_us_min(&ob->id);
|
2017-11-27 14:33:31 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* default object vars */
|
2020-03-06 11:18:14 +01:00
|
|
|
object_init(ob, type);
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2006-09-11 17:55:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name)
|
2017-10-19 18:01:41 -02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
2017-10-19 18:01:41 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = BKE_object_add_only_object(bmain, type, name);
|
|
|
|
ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
|
|
|
|
BKE_view_layer_base_deselect_all(view_layer);
|
2017-10-19 18:01:41 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_id_tag_update_ex(
|
|
|
|
bmain, &ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
|
|
|
|
return ob;
|
2017-10-19 18:01:41 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General add: to scene, with layer from area and default name
|
|
|
|
*
|
Collections and groups unification
OVERVIEW
* In 2.7 terminology, all layers and groups are now collection datablocks.
* These collections are nestable, linkable, instanceable, overrideable, ..
which opens up new ways to set up scenes and link + override data.
* Viewport/render visibility and selectability are now a part of the collection
and shared across all view layers and linkable.
* View layers define which subset of the scene collection hierarchy is excluded
for each. For many workflows one view layer can be used, these are more of an
advanced feature now.
OUTLINER
* The outliner now has a "View Layer" display mode instead of "Collections",
which can display the collections and/or objects in the view layer.
* In this display mode, collections can be excluded with the right click menu.
These will then be greyed out and their objects will be excluded.
* To view collections not linked to any scene, the "Blender File" display mode
can be used, with the new filtering option to just see Colleciton datablocks.
* The outliner right click menus for collections and objects were reorganized.
* Drag and drop still needs to be improved. Like before, dragging the icon or
text gives different results, we'll unify this later.
LINKING AND OVERRIDES
* Collections can now be linked into the scene without creating an instance,
with the link/append operator or from the collections view in the outliner.
* Collections can get static overrides with the right click menu in the outliner,
but this is rather unreliable and not clearly communicated at the moment.
* We still need to improve the make override operator to turn collection instances
into collections with overrides directly in the scene.
PERFORMANCE
* We tried to make performance not worse than before and improve it in some
cases. The main thing that's still a bit slower is multiple scenes, we have to
change the layer syncing to only updated affected scenes.
* Collections keep a list of their parent collections for faster incremental
updates in syncing and caching.
* View layer bases are now in a object -> base hash to avoid quadratic time
lookups internally and in API functions like visible_get().
VERSIONING
* Compatibility with 2.7 files should be improved due to the new visibility
controls. Of course users may not want to set up their scenes differently
now to avoid having separate layers and groups.
* Compatibility with 2.8 is mostly there, and was tested on Eevee demo and Hero
files. There's a few things which are know to be not quite compatible, like
nested layer collections inside groups.
* The versioning code for 2.8 files is quite complicated, and isolated behind
#ifdef so it can be removed at the end of the release cycle.
KNOWN ISSUES
* The G-key group operators in the 3D viewport were left mostly as is, they
need to be modified still to fit better.
* Same for the groups panel in the object properties. This needs to be updated
still, or perhaps replaced by something better.
* Collections must all have a unique name. Less restrictive namespacing is to
be done later, we'll have to see how important this is as all objects within
the collections must also have a unique name anyway.
* Full scene copy and delete scene are exactly doing the right thing yet.
Differential Revision: https://developer.blender.org/D3383
https://code.blender.org/2018/05/collections-and-groups/
2018-04-30 15:57:22 +02:00
|
|
|
* Object is added to the active Collection.
|
2017-11-22 10:52:39 -02:00
|
|
|
* If there is no linked collection to the active ViewLayer we create a new one.
|
2017-10-19 18:01:41 -02:00
|
|
|
*/
|
2006-09-11 17:55:52 +00:00
|
|
|
/* creates minimum required data, but without vertices etc. */
|
2015-05-04 12:25:33 +10:00
|
|
|
Object *BKE_object_add(
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain, Scene *UNUSED(scene), ViewLayer *view_layer, int type, const char *name)
|
2006-09-11 17:55:52 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
|
|
|
Base *base;
|
|
|
|
LayerCollection *layer_collection;
|
2006-09-11 17:55:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = object_add_common(bmain, view_layer, type, name);
|
2006-09-11 17:55:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
layer_collection = BKE_layer_collection_get_active(view_layer);
|
|
|
|
BKE_collection_object_add(bmain, layer_collection->collection, ob);
|
2006-09-11 17:55:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
base = BKE_view_layer_base_find(view_layer, ob);
|
|
|
|
BKE_view_layer_base_select_and_set_active(view_layer, base);
|
2017-10-19 18:01:41 -02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2017-10-19 18:01:41 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new object, using another one as a reference
|
|
|
|
*
|
2018-12-12 12:55:20 +11:00
|
|
|
* \param ob_src: object to use to determine the collections of the new object.
|
2017-10-19 18:01:41 -02:00
|
|
|
*/
|
|
|
|
Object *BKE_object_add_from(
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name, Object *ob_src)
|
2017-10-19 18:01:41 -02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
|
|
|
Base *base;
|
2017-02-23 12:35:14 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob = object_add_common(bmain, view_layer, type, name);
|
|
|
|
BKE_collection_object_add_from(bmain, scene, ob_src, ob);
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
base = BKE_view_layer_base_find(view_layer, ob);
|
|
|
|
BKE_view_layer_base_select_and_set_active(view_layer, base);
|
2006-09-11 17:55:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
/**
|
|
|
|
* Add a new object, but assign the given datablock as the ob->data
|
|
|
|
* for the newly created object.
|
|
|
|
*
|
2018-12-12 12:55:20 +11:00
|
|
|
* \param data: The datablock to assign as ob->data for the new object.
|
2018-07-31 10:22:19 +02:00
|
|
|
* This is assumed to be of the correct type.
|
2018-12-12 12:55:20 +11:00
|
|
|
* \param do_id_user: If true, id_us_plus() will be called on data when
|
2018-07-31 10:22:19 +02:00
|
|
|
* assigning it to the object.
|
|
|
|
*/
|
|
|
|
Object *BKE_object_add_for_data(
|
2019-04-17 06:17:24 +02:00
|
|
|
Main *bmain, ViewLayer *view_layer, int type, const char *name, ID *data, bool do_id_user)
|
2018-07-31 10:22:19 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob;
|
|
|
|
Base *base;
|
|
|
|
LayerCollection *layer_collection;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same as object_add_common, except we don't create new ob->data */
|
|
|
|
ob = BKE_object_add_only_object(bmain, type, name);
|
|
|
|
ob->data = data;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (do_id_user) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_plus(data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_view_layer_base_deselect_all(view_layer);
|
|
|
|
DEG_id_tag_update_ex(
|
|
|
|
bmain, &ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
layer_collection = BKE_layer_collection_get_active(view_layer);
|
|
|
|
BKE_collection_object_add(bmain, layer_collection->collection, ob);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
base = BKE_view_layer_base_find(view_layer, ob);
|
|
|
|
BKE_view_layer_base_select_and_set_active(view_layer, base);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:20:44 +02:00
|
|
|
void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src, const int flag)
|
2005-04-16 15:06:02 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
SoftBody *sb = ob_src->soft;
|
|
|
|
SoftBody *sbn;
|
|
|
|
bool tagged_no_main = ob_dst->id.tag & LIB_TAG_NO_MAIN;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob_dst->softflag = ob_src->softflag;
|
|
|
|
if (sb == NULL) {
|
|
|
|
ob_dst->soft = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn = MEM_dupallocN(sb);
|
2012-09-27 14:37:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((flag & LIB_ID_COPY_CACHES) == 0) {
|
|
|
|
sbn->totspring = sbn->totpoint = 0;
|
|
|
|
sbn->bpoint = NULL;
|
|
|
|
sbn->bspring = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sbn->totspring = sb->totspring;
|
|
|
|
sbn->totpoint = sb->totpoint;
|
2012-09-27 14:37:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sbn->bpoint) {
|
|
|
|
int i;
|
2012-09-27 14:37:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->bpoint = MEM_dupallocN(sbn->bpoint);
|
2012-09-27 14:37:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 0; i < sbn->totpoint; i++) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sbn->bpoint[i].springs) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->bpoint[i].springs = MEM_dupallocN(sbn->bpoint[i].springs);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-27 14:37:20 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sb->bspring) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->bspring = MEM_dupallocN(sb->bspring);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->keys = NULL;
|
|
|
|
sbn->totkey = sbn->totpointkey = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->scratch = NULL;
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (tagged_no_main == 0) {
|
|
|
|
sbn->shared = MEM_dupallocN(sb->shared);
|
|
|
|
sbn->shared->pointcache = BKE_ptcache_copy_list(
|
|
|
|
&sbn->shared->ptcaches, &sb->shared->ptcaches, flag);
|
|
|
|
}
|
Point Cache Refactoring
=======================
Caching and Baking:
- The point cache is now cleared on DAG_object_flush_update(), and not cleared for time dependency graph updates.
- There is now a Bake button instead of Protect. Also cache start and end frames were added to softbody and particles.
- The cloth autoprotect feature was removed.
- The Ctrl+B menu now also bakes cloth and particles next to softbody and fluids. Additionally there are now frree bake and free cache menu entries.
- The point cache api has been changed. There is now a PTCacheID struct for each point cache type that can be filled and then used to call the point cache functions.
- PointCache struct was added to DNA and is automatically allocated for each physics type.
- Soft body now supports Bake Editing just like cloth.
- Tried to make the systems deal consistently with time ipo's and offsets. Still not sure it all works correct, but too complicated to solve completely now.
Library Linking:
- Added some more warnings to prevent editing settings on library linked objects.
- Linked objects now read from the cache located next to the original library file, and never write to it. This restores old behavior for softbodies. For local simulation the mesh and not the object should be linked.
- Dupligroups and proxies can't create local point caches at the moment, how to implement that I'm not sure. We probably need a proxy point cache for that to work (ugh).
Physics UI:
- Renamed deflection panel to collision for consistency and reorganized the buttons. Also removed some softbody collision buttons from the softbody panel that were duplicated in this panel for cloth.
- Tweaked field panel buttons to not jump around when changing options.
- Tabbing e.g. Soft Body Collision into the Soft Body panel, it now only shows Collision to make the panel names readable.
- I tried to make enabled/disabling physics more consistent, since all three system did things different. Now the two modifier buttons to enable the modifier for the viewport and rendering are also duplicated in the physics panels. Toggling the Soft Body and Cloth buttons now both remove their modifiers.
- Fixed modifier error drawing glitch.
Particles:
- Particles are now recalculated more often than before. Previously it did partial updates based on the changes, but that doesn't work well with DAG_object_flush_update() ..
- Fixed memory leak loading keyed particle system. Now keys are not written to file anymore but always created after loading.
- Make particle threads work with autothreads.
Continue Physics:
- The timeline play now has a Continue Physics option in the playback menu, which keeps the simulations going without writing them to the cache.
- This doesn't always work that well, some changes are not immediately updated, but this can be improved later. Still it's fun to get a feel for the physics.
Todo:
- Point cache can get out of sync with and undo and changing a file without saving it.
- Change the point cache file format to store a version (so old point cache files can be either converted or at least ignored), and to do correct endian conversion.
- Menu item and/or buttons for Ctrl+B.
- A system("rm ..") was changed to remove() since the former is very slow for clearing point caches. These system() calls were already giving trouble in a bug in the tracker, but really most use of this system("") should be changed and tested.
- The Soft Body Collision and Clot Collision panel titles don't mention there's point cache settings there too, doing that makes them unreadable with the default panel setup.. but may need to make the names longer anyway.
2008-04-10 11:39:20 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sb->effector_weights) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sbn->effector_weights = MEM_dupallocN(sb->effector_weights);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
Unified effector functionality for particles, cloth and softbody
* Unified scene wide gravity (currently in scene buttons)
instead of each simulation having it's own gravity.
* Weight parameters for all effectors and an effector group
setting.
* Every effector can use noise.
* Most effectors have "shapes" point, plane, surface, every point.
- "Point" is most like the old effectors and uses the
effector location as the effector point.
- "Plane" uses the closest point on effectors local xy-plane
as the effector point.
- "Surface" uses the closest point on an effector object's
surface as the effector point.
- "Every Point" uses every point in a mesh effector object
as an effector point.
- The falloff is calculated from this point, so for example
with "surface" shape and "use only negative z axis" it's
possible to apply force only "inside" the effector object.
* Spherical effector is now renamed as "force" as it's no longer
just spherical.
* New effector parameter "flow", which makes the effector act as
surrounding air velocity, so the resulting force is
proportional to the velocity difference of the point and "air
velocity". For example a wind field with flow=1.0 results in
proper non-accelerating wind.
* New effector fields "turbulence", which creates nice random
flow paths, and "drag", which slows the points down.
* Much improved vortex field.
* Effectors can now effect particle rotation as well as location.
* Use full, or only positive/negative z-axis to apply force
(note. the z-axis is the surface normal in the case of
effector shape "surface")
* New "force field" submenu in add menu, which adds an empty
with the chosen effector (curve object for corve guides).
* Other dynamics should be quite easy to add to the effector
system too if wanted.
* "Unified" doesn't mean that force fields give the exact same results for
particles, softbody & cloth, since their final effect depends on many external
factors, like for example the surface area of the effected faces.
Code changes
* Subversion bump for correct handling of global gravity.
* Separate ui py file for common dynamics stuff.
* Particle settings updating is flushed with it's id through
DAG_id_flush_update(..).
Known issues
* Curve guides don't yet have all ui buttons in place, but they
should work none the less.
* Hair dynamics don't yet respect force fields.
Other changes
* Particle emission defaults now to frames 1-200 with life of 50
frames to fill the whole default timeline.
* Many particles drawing related crashes fixed.
* Sometimes particles didn't update on first frame properly.
* Hair with object/group visualization didn't work properly.
* Memory leaks with PointCacheID lists (Genscher, remember to
free pidlists after use :).
2009-09-30 22:10:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob_dst->soft = sbn;
|
2005-04-16 15:06:02 +00:00
|
|
|
}
|
2004-10-14 08:52:12 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int flag)
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ParticleSystem *psysn = MEM_dupallocN(psys);
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
psys_copy_particles(psysn, psys);
|
2007-12-01 20:08:31 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (psys->clmd) {
|
2020-05-08 10:14:02 +02:00
|
|
|
psysn->clmd = (ClothModifierData *)BKE_modifier_new(eModifierType_Cloth);
|
|
|
|
BKE_modifier_copydata_ex((ModifierData *)psys->clmd, (ModifierData *)psysn->clmd, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
psys->hair_in_mesh = psys->hair_out_mesh = NULL;
|
|
|
|
}
|
2009-07-12 23:38:47 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_duplicatelist(&psysn->targets, &psys->targets);
|
2010-05-06 21:31:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
psysn->pathcache = NULL;
|
|
|
|
psysn->childcache = NULL;
|
|
|
|
psysn->edit = NULL;
|
|
|
|
psysn->pdd = NULL;
|
|
|
|
psysn->effectors = NULL;
|
|
|
|
psysn->tree = NULL;
|
|
|
|
psysn->bvhtree = NULL;
|
|
|
|
psysn->batch_cache = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_listbase_clear(&psysn->pathcachebufs);
|
|
|
|
BLI_listbase_clear(&psysn->childcachebufs);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & LIB_ID_CREATE_NO_MAIN) {
|
|
|
|
BLI_assert((psys->flag & PSYS_SHARED_CACHES) == 0);
|
|
|
|
psysn->flag |= PSYS_SHARED_CACHES;
|
|
|
|
BLI_assert(psysn->pointcache != NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag);
|
|
|
|
}
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX - from reading existing code this seems correct but intended usage of
|
|
|
|
* pointcache should /w cloth should be added in 'ParticleSystem' - campbell */
|
|
|
|
if (psysn->clmd) {
|
|
|
|
psysn->clmd->point_cache = psysn->pointcache;
|
|
|
|
}
|
2010-02-04 16:54:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
id_us_plus((ID *)psysn->part);
|
|
|
|
}
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return psysn;
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 22:09:57 +00:00
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const int flag)
|
2008-02-27 17:04:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ParticleSystem *psys, *npsys;
|
|
|
|
ModifierData *md;
|
|
|
|
|
|
|
|
if (ob_dst->type != OB_MESH) {
|
|
|
|
/* currently only mesh objects can have soft body */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ob_dst->particlesystem);
|
|
|
|
for (psys = ob_src->particlesystem.first; psys; psys = psys->next) {
|
|
|
|
npsys = BKE_object_copy_particlesystem(psys, flag);
|
|
|
|
|
|
|
|
BLI_addtail(&ob_dst->particlesystem, npsys);
|
|
|
|
|
|
|
|
/* need to update particle modifiers too */
|
|
|
|
for (md = ob_dst->modifiers.first; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_ParticleSystem) {
|
|
|
|
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (psmd->psys == psys) {
|
2019-04-17 06:17:24 +02:00
|
|
|
psmd->psys = npsys;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (md->type == eModifierType_DynamicPaint) {
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
|
|
|
|
if (pmd->brush) {
|
|
|
|
if (pmd->brush->psys == psys) {
|
|
|
|
pmd->brush->psys = npsys;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 15:50:14 +01:00
|
|
|
else if (md->type == eModifierType_Fluid) {
|
|
|
|
FluidModifierData *mmd = (FluidModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-16 15:50:14 +01:00
|
|
|
if (mmd->type == MOD_FLUID_TYPE_FLOW) {
|
|
|
|
if (mmd->flow) {
|
|
|
|
if (mmd->flow->psys == psys) {
|
|
|
|
mmd->flow->psys = npsys;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-27 17:04:58 +00:00
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static void copy_object_pose(Object *obn, const Object *ob, const int flag)
|
2006-11-11 16:45:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bPoseChannel *chan;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* note: need to clear obn->pose pointer first,
|
|
|
|
* so that BKE_pose_copy_data works (otherwise there's a crash) */
|
|
|
|
obn->pose = NULL;
|
|
|
|
BKE_pose_copy_data_ex(&obn->pose, ob->pose, flag, true); /* true = copy constraints */
|
2006-11-11 16:45:17 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (chan = obn->pose->chanbase.first; chan; chan = chan->next) {
|
|
|
|
bConstraint *con;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* XXX Remapping object pointing onto itself should be handled by generic
|
|
|
|
* BKE_library_remap stuff, but...
|
2019-04-17 06:17:24 +02:00
|
|
|
* the flush_constraint_targets callback am not sure about, so will delay that for now. */
|
|
|
|
for (con = chan->constraints.first; con; con = con->next) {
|
|
|
|
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
|
|
|
|
ListBase targets = {NULL, NULL};
|
|
|
|
bConstraintTarget *ct;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (cti && cti->get_constraint_targets) {
|
|
|
|
cti->get_constraint_targets(con, &targets);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (ct = targets.first; ct; ct = ct->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ct->tar == ob) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ct->tar = obn;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cti->flush_constraint_targets) {
|
2019-04-17 06:17:24 +02:00
|
|
|
cti->flush_constraint_targets(con, &targets, 0);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-11 16:45:17 +00:00
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static void copy_object_lod(Object *obn, const Object *ob, const int UNUSED(flag))
|
2013-12-17 14:42:47 -08:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_duplicatelist(&obn->lodlevels, &ob->lodlevels);
|
2013-12-17 14:42:47 -08:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
obn->currentlod = (LodLevel *)obn->lodlevels.first;
|
2013-12-17 14:42:47 -08:00
|
|
|
}
|
|
|
|
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_pose_context_check(const Object *ob)
|
2011-09-14 01:48:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((ob) && (ob->type == OB_ARMATURE) && (ob->pose) && (ob->mode & OB_MODE_POSE)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-14 01:48:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
Object *BKE_object_pose_armature_get(Object *ob)
|
2011-09-14 01:48:55 +00:00
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-09-14 01:48:55 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (BKE_object_pose_context_check(ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-09-14 01:48:55 +00:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
ob = BKE_modifiers_is_deformed_by_armature(ob);
|
2011-09-14 01:48:55 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Only use selected check when non-active. */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (BKE_object_pose_context_check(ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-09-14 01:48:55 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2011-09-14 01:48:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:41:38 -02:00
|
|
|
Object *BKE_object_pose_armature_get_visible(Object *ob, ViewLayer *view_layer, View3D *v3d)
|
2018-02-09 02:31:09 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob_armature = BKE_object_pose_armature_get(ob);
|
|
|
|
if (ob_armature) {
|
|
|
|
Base *base = BKE_view_layer_base_find(view_layer, ob_armature);
|
|
|
|
if (base) {
|
|
|
|
if (BASE_VISIBLE(v3d, base)) {
|
|
|
|
return ob_armature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2018-02-09 02:31:09 +11:00
|
|
|
}
|
2018-04-17 10:13:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Access pose array with special check to get pose object when in weight paint mode.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
Object **BKE_object_pose_array_get_ex(ViewLayer *view_layer,
|
|
|
|
View3D *v3d,
|
|
|
|
uint *r_objects_len,
|
|
|
|
bool unique)
|
|
|
|
{
|
|
|
|
Object *ob_active = OBACT(view_layer);
|
|
|
|
Object *ob_pose = BKE_object_pose_armature_get(ob_active);
|
|
|
|
Object **objects = NULL;
|
|
|
|
if (ob_pose == ob_active) {
|
|
|
|
objects = BKE_view_layer_array_from_objects_in_mode(view_layer,
|
|
|
|
v3d,
|
|
|
|
r_objects_len,
|
|
|
|
{
|
|
|
|
.object_mode = OB_MODE_POSE,
|
|
|
|
.no_dup_data = unique,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (ob_pose != NULL) {
|
|
|
|
*r_objects_len = 1;
|
|
|
|
objects = MEM_mallocN(sizeof(*objects), __func__);
|
|
|
|
objects[0] = ob_pose;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*r_objects_len = 0;
|
|
|
|
objects = MEM_mallocN(0, __func__);
|
|
|
|
}
|
|
|
|
return objects;
|
2018-04-17 10:13:32 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
Object **BKE_object_pose_array_get_unique(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
|
2018-04-17 10:13:32 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_object_pose_array_get_ex(view_layer, v3d, r_objects_len, true);
|
2018-04-17 10:13:32 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
Object **BKE_object_pose_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
|
2018-04-17 10:13:32 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_object_pose_array_get_ex(view_layer, v3d, r_objects_len, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Base **BKE_object_pose_base_array_get_ex(ViewLayer *view_layer,
|
|
|
|
View3D *v3d,
|
|
|
|
uint *r_bases_len,
|
|
|
|
bool unique)
|
|
|
|
{
|
|
|
|
Base *base_active = BASACT(view_layer);
|
|
|
|
Object *ob_pose = base_active ? BKE_object_pose_armature_get(base_active->object) : NULL;
|
|
|
|
Base *base_pose = NULL;
|
|
|
|
Base **bases = NULL;
|
|
|
|
|
|
|
|
if (base_active) {
|
|
|
|
if (ob_pose == base_active->object) {
|
|
|
|
base_pose = base_active;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
base_pose = BKE_view_layer_base_find(view_layer, ob_pose);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base_active && (base_pose == base_active)) {
|
|
|
|
bases = BKE_view_layer_array_from_bases_in_mode(view_layer,
|
|
|
|
v3d,
|
|
|
|
r_bases_len,
|
|
|
|
{
|
|
|
|
.object_mode = OB_MODE_POSE,
|
|
|
|
.no_dup_data = unique,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (base_pose != NULL) {
|
|
|
|
*r_bases_len = 1;
|
|
|
|
bases = MEM_mallocN(sizeof(*bases), __func__);
|
|
|
|
bases[0] = base_pose;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*r_bases_len = 0;
|
|
|
|
bases = MEM_mallocN(0, __func__);
|
|
|
|
}
|
|
|
|
return bases;
|
2018-04-17 11:21:27 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
Base **BKE_object_pose_base_array_get_unique(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len)
|
2018-04-17 11:21:27 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_object_pose_base_array_get_ex(view_layer, v3d, r_bases_len, true);
|
2018-04-17 11:21:27 +02:00
|
|
|
}
|
2018-11-25 09:50:34 -02:00
|
|
|
Base **BKE_object_pose_base_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len)
|
2018-04-17 11:21:27 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_object_pose_base_array_get_ex(view_layer, v3d, r_bases_len, false);
|
2018-04-17 11:21:27 +02:00
|
|
|
}
|
|
|
|
|
2012-05-22 15:29:57 +00:00
|
|
|
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
|
2010-10-12 21:47:13 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v3_v3(ob_tar->loc, ob_src->loc);
|
|
|
|
copy_v3_v3(ob_tar->rot, ob_src->rot);
|
2020-01-07 12:42:37 -03:00
|
|
|
copy_v4_v4(ob_tar->quat, ob_src->quat);
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v3_v3(ob_tar->rotAxis, ob_src->rotAxis);
|
|
|
|
ob_tar->rotAngle = ob_src->rotAngle;
|
|
|
|
ob_tar->rotmode = ob_src->rotmode;
|
|
|
|
copy_v3_v3(ob_tar->scale, ob_src->scale);
|
2010-10-12 21:47:13 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 14:37:20 +00:00
|
|
|
/* copy objects, will re-initialize cached simulation data */
|
2017-06-14 22:36:30 +02:00
|
|
|
Object *BKE_object_copy(Main *bmain, const Object *ob)
|
2012-09-27 14:37:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob_copy;
|
|
|
|
BKE_id_copy(bmain, &ob->id, (ID **)&ob_copy);
|
2018-05-23 18:53:37 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* We increase object user count when linking to Collections. */
|
|
|
|
id_us_min(&ob_copy->id);
|
2018-05-23 18:53:37 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob_copy;
|
2012-09-27 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 01:14:39 +11:00
|
|
|
/**
|
|
|
|
* Perform deep-copy of object and its 'children' data-blocks (obdata, materials, actions, etc.).
|
2019-03-29 14:53:45 +01:00
|
|
|
*
|
2019-05-19 19:21:45 +10:00
|
|
|
* \param dupflag: Controls which sub-data are also duplicated
|
2019-04-27 12:07:07 +10:00
|
|
|
* (see #eDupli_ID_Flags in DNA_userdef_types.h).
|
2019-03-29 14:53:45 +01:00
|
|
|
*
|
2019-04-27 12:07:07 +10:00
|
|
|
* \note This function does not do any remapping to new IDs, caller must do it
|
|
|
|
* (\a #BKE_libblock_relink_to_newid()).
|
|
|
|
* \note Caller MUST free \a newid pointers itself (#BKE_main_id_clear_newpoins()) and call updates
|
|
|
|
* of DEG too (#DAG_relations_tag_update()).
|
2019-03-29 14:53:45 +01:00
|
|
|
*/
|
2020-06-17 15:02:04 +02:00
|
|
|
Object *BKE_object_duplicate(Main *bmain,
|
|
|
|
Object *ob,
|
|
|
|
const eDupli_ID_Flags dupflag,
|
|
|
|
const eLibIDDuplicateFlags duplicate_options)
|
2019-02-26 16:15:30 -03:00
|
|
|
{
|
2020-06-17 15:02:04 +02:00
|
|
|
const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
|
|
|
|
|
|
|
|
if (!is_subprocess) {
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
|
|
|
|
BKE_main_id_clear_newpoins(bmain);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Material ***matarar;
|
2020-06-10 16:43:25 +02:00
|
|
|
const bool is_object_liboverride = ID_IS_OVERRIDE_LIBRARY(ob);
|
|
|
|
|
2020-06-17 15:02:04 +02:00
|
|
|
Object *obn;
|
|
|
|
BKE_id_copy(bmain, &ob->id, (ID **)&obn);
|
|
|
|
id_us_min(&obn->id);
|
|
|
|
if (is_subprocess) {
|
|
|
|
ID_NEW_SET(ob, obn);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* 0 == full linked. */
|
|
|
|
if (dupflag == 0) {
|
|
|
|
return obn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* duplicates using userflags */
|
|
|
|
if (dupflag & USER_DUP_ACT) {
|
|
|
|
BKE_animdata_copy_id_action(bmain, &obn->id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dupflag & USER_DUP_MAT) {
|
2020-06-17 17:01:21 +02:00
|
|
|
for (int i = 0; i < obn->totcol; i++) {
|
|
|
|
BKE_id_copy_for_duplicate(bmain, (ID *)obn->mat[i], is_object_liboverride, dupflag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dupflag & USER_DUP_PSYS) {
|
|
|
|
ParticleSystem *psys;
|
|
|
|
for (psys = obn->particlesystem.first; psys; psys = psys->next) {
|
2020-06-17 17:01:21 +02:00
|
|
|
BKE_id_copy_for_duplicate(bmain, (ID *)psys->part, is_object_liboverride, dupflag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:01:21 +02:00
|
|
|
ID *id = obn->data;
|
|
|
|
ID *id_new = NULL;
|
2020-06-18 20:34:02 +02:00
|
|
|
const bool need_to_duplicate_obdata = (id != NULL) && (id->newid == NULL);
|
2020-06-17 15:02:04 +02:00
|
|
|
|
2020-06-17 17:01:21 +02:00
|
|
|
switch (obn->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
if (dupflag & USER_DUP_MESH) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
2020-06-17 15:02:04 +02:00
|
|
|
}
|
2020-06-17 17:01:21 +02:00
|
|
|
break;
|
|
|
|
case OB_CURVE:
|
|
|
|
if (dupflag & USER_DUP_CURVE) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-06-17 17:01:21 +02:00
|
|
|
break;
|
|
|
|
case OB_SURF:
|
|
|
|
if (dupflag & USER_DUP_SURF) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_FONT:
|
|
|
|
if (dupflag & USER_DUP_FONT) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_MBALL:
|
|
|
|
if (dupflag & USER_DUP_MBALL) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_LAMP:
|
|
|
|
if (dupflag & USER_DUP_LAMP) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_ARMATURE:
|
|
|
|
if (dupflag & USER_DUP_ARM) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_LATTICE:
|
|
|
|
if (dupflag != 0) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_CAMERA:
|
|
|
|
if (dupflag != 0) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_LIGHTPROBE:
|
|
|
|
if (dupflag & USER_DUP_LIGHTPROBE) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_SPEAKER:
|
|
|
|
if (dupflag != 0) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_GPENCIL:
|
|
|
|
if (dupflag & USER_DUP_GPENCIL) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_HAIR:
|
|
|
|
if (dupflag & USER_DUP_HAIR) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_POINTCLOUD:
|
|
|
|
if (dupflag & USER_DUP_POINTCLOUD) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OB_VOLUME:
|
|
|
|
if (dupflag & USER_DUP_VOLUME) {
|
|
|
|
id_new = BKE_id_copy_for_duplicate(bmain, id, is_object_liboverride, dupflag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-17 17:01:21 +02:00
|
|
|
/* If obdata has been copied, we may also have to duplicate the materials assigned to it. */
|
|
|
|
if (need_to_duplicate_obdata && id_new != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dupflag & USER_DUP_MAT) {
|
2020-03-05 08:08:23 +11:00
|
|
|
matarar = BKE_object_material_array_p(obn);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (matarar) {
|
2020-06-17 17:01:21 +02:00
|
|
|
for (int i = 0; i < obn->totcol; i++) {
|
|
|
|
BKE_id_copy_for_duplicate(bmain, (ID *)(*matarar)[i], is_object_liboverride, dupflag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 16:15:30 -03:00
|
|
|
|
2020-06-17 15:02:04 +02:00
|
|
|
if (!is_subprocess) {
|
|
|
|
/* This code will follow into all ID links using an ID tagged with LIB_TAG_NEW.*/
|
|
|
|
BKE_libblock_relink_to_newid(&obn->id);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
/* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
|
|
|
|
ID *id_iter;
|
|
|
|
FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
|
|
|
|
BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
|
|
|
|
}
|
|
|
|
FOREACH_MAIN_ID_END;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Cleanup. */
|
|
|
|
BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
|
|
|
|
BKE_main_id_clear_newpoins(bmain);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obn->type == OB_ARMATURE) {
|
|
|
|
DEG_id_tag_update(&obn->id, ID_RECALC_GEOMETRY);
|
|
|
|
if (obn->pose) {
|
|
|
|
BKE_pose_tag_recalc(bmain, obn->pose);
|
|
|
|
}
|
|
|
|
// BKE_pose_rebuild(bmain, obn, obn->data, true);
|
|
|
|
}
|
2019-02-26 16:15:30 -03:00
|
|
|
|
2020-06-17 15:02:04 +02:00
|
|
|
if (obn->data != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_id_tag_update_ex(bmain, (ID *)obn->data, ID_RECALC_EDITORS);
|
|
|
|
}
|
2019-02-26 16:15:30 -03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return obn;
|
2019-02-26 16:15:30 -03:00
|
|
|
}
|
|
|
|
|
2016-07-06 14:37:03 +02:00
|
|
|
/* Returns true if the Object is from an external blend file (libdata) */
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_is_libdata(const Object *ob)
|
2009-07-19 00:49:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ob && ID_IS_LINKED(ob));
|
2009-07-19 00:49:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 14:37:03 +02:00
|
|
|
/* Returns true if the Object data is from an external blend file (libdata) */
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_obdata_is_libdata(const Object *ob)
|
2009-05-21 15:34:09 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Linked objects with local obdata are forbidden! */
|
|
|
|
BLI_assert(!ob || !ob->data || (ID_IS_LINKED(ob) ? ID_IS_LINKED(ob->data) : true));
|
|
|
|
return (ob && ob->data && ID_IS_LINKED(ob->data));
|
2009-05-21 15:34:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Proxy API
|
|
|
|
* \{ */
|
2006-11-11 16:45:17 +00:00
|
|
|
|
2007-11-15 12:15:28 +00:00
|
|
|
/* when you make proxy, ensure the exposed layers are extern */
|
2009-09-14 16:52:06 +00:00
|
|
|
static void armature_set_id_extern(Object *ob)
|
2007-11-15 12:15:28 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bArmature *arm = ob->data;
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
unsigned int lay = arm->layer_protected;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!(pchan->bone->layer & lay)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_lib_extern((ID *)pchan->custom);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2007-11-15 12:15:28 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_copy_proxy_drivers(Object *ob, Object *target)
|
2010-01-20 14:28:49 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((target->adt) && (target->adt->drivers.first)) {
|
|
|
|
FCurve *fcu;
|
|
|
|
|
|
|
|
/* add new animdata block */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ob->adt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->adt = BKE_animdata_add_id(&ob->id);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* make a copy of all the drivers (for now), then correct any links that need fixing */
|
2020-06-05 09:30:15 +02:00
|
|
|
BKE_fcurves_free(&ob->adt->drivers);
|
|
|
|
BKE_fcurves_copy(&ob->adt->drivers, &target->adt->drivers);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (fcu = ob->adt->drivers.first; fcu; fcu = fcu->next) {
|
|
|
|
ChannelDriver *driver = fcu->driver;
|
|
|
|
DriverVar *dvar;
|
|
|
|
|
|
|
|
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
|
|
|
|
/* all drivers */
|
|
|
|
DRIVER_TARGETS_LOOPER_BEGIN (dvar) {
|
|
|
|
if (dtar->id) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((Object *)dtar->id == target) {
|
2019-04-17 06:17:24 +02:00
|
|
|
dtar->id = (ID *)ob;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else {
|
|
|
|
/* only on local objects because this causes indirect links
|
|
|
|
* 'a -> b -> c', blend to point directly to a.blend
|
2019-08-01 13:53:25 +10:00
|
|
|
* when a.blend has a proxy that's linked into c.blend */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ID_IS_LINKED(ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_lib_extern((ID *)dtar->id);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DRIVER_TARGETS_LOOPER_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-20 14:28:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/**
|
|
|
|
* Proxy rule:
|
|
|
|
* - lib_object->proxy_from == the one we borrow from, set temporally while object_update.
|
|
|
|
* - local_object->proxy == pointer to library object, saved in files and read.
|
|
|
|
* - local_object->proxy_group == pointer to collection dupli-object, saved in files and read.
|
|
|
|
*/
|
2018-07-19 16:48:21 +02:00
|
|
|
void BKE_object_make_proxy(Main *bmain, Object *ob, Object *target, Object *cob)
|
2006-11-11 16:45:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* paranoia checks */
|
|
|
|
if (ID_IS_LINKED(ob) || !ID_IS_LINKED(target)) {
|
|
|
|
CLOG_ERROR(&LOG, "cannot make proxy");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ob->proxy = target;
|
|
|
|
ob->proxy_group = cob;
|
|
|
|
id_lib_extern(&target->id);
|
|
|
|
|
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
|
|
|
|
DEG_id_tag_update(&target->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
|
|
|
|
|
|
|
|
/* copy transform
|
|
|
|
* - cob means this proxy comes from a collection, just apply the matrix
|
|
|
|
* so the object wont move from its dupli-transform.
|
|
|
|
*
|
|
|
|
* - no cob means this is being made from a linked object,
|
|
|
|
* this is closer to making a copy of the object - in-place. */
|
|
|
|
if (cob) {
|
|
|
|
ob->rotmode = target->rotmode;
|
|
|
|
mul_m4_m4m4(ob->obmat, cob->obmat, target->obmat);
|
|
|
|
if (cob->instance_collection) { /* should always be true */
|
|
|
|
float tvec[3];
|
|
|
|
mul_v3_mat3_m4v3(tvec, ob->obmat, cob->instance_collection->instance_offset);
|
|
|
|
sub_v3_v3(ob->obmat[3], tvec);
|
|
|
|
}
|
|
|
|
BKE_object_apply_mat4(ob, ob->obmat, false, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_object_transform_copy(ob, target);
|
|
|
|
ob->parent = target->parent; /* libdata */
|
|
|
|
copy_m4_m4(ob->parentinv, target->parentinv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy animdata stuff - drivers only for now... */
|
|
|
|
BKE_object_copy_proxy_drivers(ob, target);
|
|
|
|
|
|
|
|
/* skip constraints? */
|
|
|
|
/* FIXME: this is considered by many as a bug */
|
|
|
|
|
|
|
|
/* set object type and link to data */
|
|
|
|
ob->type = target->type;
|
|
|
|
ob->data = target->data;
|
|
|
|
id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_TAG_EXTERN */
|
|
|
|
|
|
|
|
/* copy vertex groups */
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_defgroup_copy_list(&ob->defbase, &target->defbase);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* copy material and index information */
|
|
|
|
ob->actcol = ob->totcol = 0;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->mat) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(ob->mat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (ob->matbits) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(ob->matbits);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->mat = NULL;
|
|
|
|
ob->matbits = NULL;
|
|
|
|
if ((target->totcol) && (target->mat) && OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ob->actcol = target->actcol;
|
|
|
|
ob->totcol = target->totcol;
|
|
|
|
|
|
|
|
ob->mat = MEM_dupallocN(target->mat);
|
|
|
|
ob->matbits = MEM_dupallocN(target->matbits);
|
|
|
|
for (i = 0; i < target->totcol; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
/* don't need to run BKE_object_materials_test
|
2019-04-17 06:17:24 +02:00
|
|
|
* since we know this object is new and not used elsewhere */
|
|
|
|
id_us_plus((ID *)ob->mat[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* type conversions */
|
|
|
|
if (target->type == OB_ARMATURE) {
|
|
|
|
copy_object_pose(ob, target, 0); /* data copy, object pointers in constraints */
|
|
|
|
BKE_pose_rest(ob->pose); /* clear all transforms in channels */
|
|
|
|
BKE_pose_rebuild(bmain, ob, ob->data, true); /* set all internal links */
|
|
|
|
|
|
|
|
armature_set_id_extern(ob);
|
|
|
|
}
|
|
|
|
else if (target->type == OB_EMPTY) {
|
|
|
|
ob->empty_drawtype = target->empty_drawtype;
|
|
|
|
ob->empty_drawsize = target->empty_drawsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy IDProperties */
|
|
|
|
if (ob->id.properties) {
|
|
|
|
IDP_FreeProperty(ob->id.properties);
|
|
|
|
ob->id.properties = NULL;
|
|
|
|
}
|
|
|
|
if (target->id.properties) {
|
|
|
|
ob->id.properties = IDP_CopyProperty(target->id.properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy drawtype info */
|
|
|
|
ob->dt = target->dt;
|
2006-11-11 16:45:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 20:09:31 +10:00
|
|
|
/**
|
|
|
|
* Use with newly created objects to set their size
|
|
|
|
* (used to apply scene-scale).
|
|
|
|
*/
|
|
|
|
void BKE_object_obdata_size_init(struct Object *ob, const float size)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* apply radius as a scale to types that support it */
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_EMPTY: {
|
|
|
|
ob->empty_drawsize *= size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_FONT: {
|
|
|
|
Curve *cu = ob->data;
|
|
|
|
cu->fsize *= size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_CAMERA: {
|
|
|
|
Camera *cam = ob->data;
|
|
|
|
cam->drawsize *= size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_LAMP: {
|
|
|
|
Light *lamp = ob->data;
|
|
|
|
lamp->dist *= size;
|
|
|
|
lamp->area_size *= size;
|
|
|
|
lamp->area_sizey *= size;
|
|
|
|
lamp->area_sizez *= size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Only lattice (not mesh, curve, mball...),
|
|
|
|
* because its got data when newly added */
|
|
|
|
case OB_LATTICE: {
|
|
|
|
struct Lattice *lt = ob->data;
|
|
|
|
float mat[4][4];
|
|
|
|
|
|
|
|
unit_m4(mat);
|
|
|
|
scale_m4_fl(mat, size);
|
|
|
|
|
|
|
|
BKE_lattice_transform(lt, (float(*)[4])mat, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
2006-11-11 16:45:17 +00:00
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Matrix Get/Set API
|
|
|
|
* \{ */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float vec[3];
|
|
|
|
mul_v3_v3v3(vec, ob->scale, ob->dscale);
|
|
|
|
size_to_mat3(mat, vec);
|
2008-09-29 20:13:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:15:44 +10:00
|
|
|
void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot)
|
2008-09-29 20:13:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float rmat[3][3], dmat[3][3];
|
|
|
|
|
|
|
|
/* 'dmat' is the delta-rotation matrix, which will get (pre)multiplied
|
|
|
|
* with the rotation matrix to yield the appropriate rotation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* rotations may either be quats, eulers (with various rotation orders), or axis-angle */
|
|
|
|
if (ob->rotmode > 0) {
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Euler rotations
|
|
|
|
* (will cause gimble lock, but this can be alleviated a bit with rotation orders). */
|
2019-04-17 06:17:24 +02:00
|
|
|
eulO_to_mat3(rmat, ob->rot, ob->rotmode);
|
|
|
|
eulO_to_mat3(dmat, ob->drot, ob->rotmode);
|
|
|
|
}
|
|
|
|
else if (ob->rotmode == ROT_MODE_AXISANGLE) {
|
|
|
|
/* axis-angle - not really that great for 3D-changing orientations */
|
|
|
|
axis_angle_to_mat3(rmat, ob->rotAxis, ob->rotAngle);
|
|
|
|
axis_angle_to_mat3(dmat, ob->drotAxis, ob->drotAngle);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* quats are normalized before use to eliminate scaling issues */
|
|
|
|
float tquat[4];
|
|
|
|
|
|
|
|
normalize_qt_qt(tquat, ob->quat);
|
|
|
|
quat_to_mat3(rmat, tquat);
|
|
|
|
|
|
|
|
normalize_qt_qt(tquat, ob->dquat);
|
|
|
|
quat_to_mat3(dmat, tquat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* combine these rotations */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (use_drot) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m3_m3m3(mat, dmat, rmat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m3_m3(mat, rmat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2008-09-29 20:13:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-24 12:13:13 +00:00
|
|
|
void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
|
2009-12-19 10:27:23 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ASSERT_UNIT_M3(mat);
|
|
|
|
|
|
|
|
switch (ob->rotmode) {
|
|
|
|
case ROT_MODE_QUAT: {
|
|
|
|
float dquat[4];
|
|
|
|
mat3_normalized_to_quat(ob->quat, mat);
|
|
|
|
normalize_qt_qt(dquat, ob->dquat);
|
|
|
|
invert_qt_normalized(dquat);
|
|
|
|
mul_qt_qtqt(ob->quat, dquat, ob->quat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ROT_MODE_AXISANGLE: {
|
|
|
|
float quat[4];
|
|
|
|
float dquat[4];
|
|
|
|
|
|
|
|
/* without drot we could apply 'mat' directly */
|
|
|
|
mat3_normalized_to_quat(quat, mat);
|
|
|
|
axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle);
|
|
|
|
invert_qt_normalized(dquat);
|
|
|
|
mul_qt_qtqt(quat, dquat, quat);
|
|
|
|
quat_to_axis_angle(ob->rotAxis, &ob->rotAngle, quat);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: /* euler */
|
|
|
|
{
|
|
|
|
float quat[4];
|
|
|
|
float dquat[4];
|
|
|
|
|
|
|
|
/* without drot we could apply 'mat' directly */
|
|
|
|
mat3_normalized_to_quat(quat, mat);
|
|
|
|
eulO_to_quat(dquat, ob->drot, ob->rotmode);
|
|
|
|
invert_qt_normalized(dquat);
|
|
|
|
mul_qt_qtqt(quat, dquat, quat);
|
|
|
|
/* end drot correction */
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (use_compat) {
|
2019-04-17 06:17:24 +02:00
|
|
|
quat_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, quat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
quat_to_eulO(ob->rot, ob->rotmode, quat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
|
2011-11-11 05:34:07 +00:00
|
|
|
{
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
#define TFMCPY(_v) (obtfm->_v = ob->_v)
|
|
|
|
#define TFMCPY3D(_v) copy_v3_v3(obtfm->_v, ob->_v)
|
|
|
|
#define TFMCPY4D(_v) copy_v4_v4(obtfm->_v, ob->_v)
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
TFMCPY3D(loc);
|
|
|
|
TFMCPY3D(dloc);
|
|
|
|
TFMCPY3D(scale);
|
|
|
|
TFMCPY3D(dscale);
|
|
|
|
TFMCPY3D(rot);
|
|
|
|
TFMCPY3D(drot);
|
|
|
|
TFMCPY4D(quat);
|
|
|
|
TFMCPY4D(dquat);
|
|
|
|
TFMCPY3D(rotAxis);
|
|
|
|
TFMCPY3D(drotAxis);
|
|
|
|
TFMCPY(rotAngle);
|
|
|
|
TFMCPY(drotAngle);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
|
|
|
#undef TFMCPY
|
|
|
|
#undef TFMCPY3D
|
|
|
|
#undef TFMCPY4D
|
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_tfm_protected_restore(Object *ob,
|
2012-05-06 15:15:33 +00:00
|
|
|
const ObjectTfmProtectedChannels *obtfm,
|
|
|
|
const short protectflag)
|
2011-11-11 05:34:07 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
unsigned int i;
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if (protectflag & (OB_LOCK_LOCX << i)) {
|
|
|
|
ob->loc[i] = obtfm->loc[i];
|
|
|
|
ob->dloc[i] = obtfm->dloc[i];
|
|
|
|
}
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (protectflag & (OB_LOCK_SCALEX << i)) {
|
|
|
|
ob->scale[i] = obtfm->scale[i];
|
|
|
|
ob->dscale[i] = obtfm->dscale[i];
|
|
|
|
}
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (protectflag & (OB_LOCK_ROTX << i)) {
|
|
|
|
ob->rot[i] = obtfm->rot[i];
|
|
|
|
ob->drot[i] = obtfm->drot[i];
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->quat[i + 1] = obtfm->quat[i + 1];
|
|
|
|
ob->dquat[i + 1] = obtfm->dquat[i + 1];
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->rotAxis[i] = obtfm->rotAxis[i];
|
|
|
|
ob->drotAxis[i] = obtfm->drotAxis[i];
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((protectflag & OB_LOCK_ROT4D) && (protectflag & OB_LOCK_ROTW)) {
|
|
|
|
ob->quat[0] = obtfm->quat[0];
|
|
|
|
ob->dquat[0] = obtfm->dquat[0];
|
2011-11-11 05:34:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->rotAngle = obtfm->rotAngle;
|
|
|
|
ob->drotAngle = obtfm->drotAngle;
|
|
|
|
}
|
2011-11-11 05:34:07 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 10:25:14 +01:00
|
|
|
void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
|
|
|
|
{
|
|
|
|
#define TFMCPY(_v) (object_dst->_v = object_src->_v)
|
|
|
|
#define TFMCPY3D(_v) copy_v3_v3(object_dst->_v, object_src->_v)
|
|
|
|
#define TFMCPY4D(_v) copy_v4_v4(object_dst->_v, object_src->_v)
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
TFMCPY3D(loc);
|
|
|
|
TFMCPY3D(dloc);
|
|
|
|
TFMCPY3D(scale);
|
|
|
|
TFMCPY3D(dscale);
|
|
|
|
TFMCPY3D(rot);
|
|
|
|
TFMCPY3D(drot);
|
|
|
|
TFMCPY4D(quat);
|
|
|
|
TFMCPY4D(dquat);
|
|
|
|
TFMCPY3D(rotAxis);
|
|
|
|
TFMCPY3D(drotAxis);
|
|
|
|
TFMCPY(rotAngle);
|
|
|
|
TFMCPY(drotAngle);
|
2019-03-01 10:25:14 +01:00
|
|
|
|
|
|
|
#undef TFMCPY
|
|
|
|
#undef TFMCPY3D
|
|
|
|
#undef TFMCPY4D
|
|
|
|
}
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
void BKE_object_to_mat3(Object *ob, float mat[3][3]) /* no parent */
|
2008-09-29 20:13:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float smat[3][3];
|
|
|
|
float rmat[3][3];
|
|
|
|
/*float q1[4];*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* scale */
|
|
|
|
BKE_object_scale_to_mat3(ob, smat);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* rot */
|
|
|
|
BKE_object_rot_to_mat3(ob, rmat, true);
|
|
|
|
mul_m3_m3m3(mat, rmat, smat);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
void BKE_object_to_mat4(Object *ob, float mat[4][4])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float tmat[3][3];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_to_mat3(ob, tmat);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m4_m3(mat, tmat);
|
2010-07-03 17:47:06 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
add_v3_v3v3(mat[3], ob->loc, ob->dloc);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 12:58:01 +00:00
|
|
|
void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4])
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->parent) {
|
|
|
|
float par_imat[4][4];
|
2014-12-29 15:23:12 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_get_parent_matrix(ob, ob->parent, par_imat);
|
|
|
|
invert_m4(par_imat);
|
|
|
|
mul_m4_m4m4(mat, par_imat, ob->obmat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_m4_m4(mat, ob->obmat);
|
|
|
|
}
|
2013-07-12 12:58:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 14:26:27 +10:00
|
|
|
/**
|
|
|
|
* \return success if \a mat is set.
|
|
|
|
*/
|
2019-01-28 17:52:46 +01:00
|
|
|
static bool ob_parcurve(Object *ob, Object *par, float mat[4][4])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Curve *cu = par->data;
|
|
|
|
float vec[4], dir[3], quat[4], radius, ctime;
|
|
|
|
|
|
|
|
/* NOTE: Curve cache is supposed to be evaluated here already, however there
|
|
|
|
* are cases where we can not guarantee that. This includes, for example,
|
|
|
|
* dependency cycles. We can't correct anything from here, since that would
|
|
|
|
* cause a threading conflicts.
|
|
|
|
*
|
2019-08-04 12:51:44 +10:00
|
|
|
* TODO(sergey): Some of the legit looking cases like T56619 need to be
|
2019-04-17 06:17:24 +02:00
|
|
|
* looked into, and maybe curve cache (and other dependencies) are to be
|
|
|
|
* evaluated prior to conversion. */
|
|
|
|
if (par->runtime.curve_cache == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (par->runtime.curve_cache->path == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* ctime is now a proper var setting of Curve which gets set by Animato like any other var
|
|
|
|
* that's animated, but this will only work if it actually is animated.
|
2019-04-17 06:17:24 +02:00
|
|
|
*
|
2019-04-27 12:07:07 +10:00
|
|
|
* We divide the curvetime calculated in the previous step by the length of the path,
|
|
|
|
* to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
if (cu->pathlen) {
|
|
|
|
ctime = cu->ctime / cu->pathlen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ctime = cu->ctime;
|
|
|
|
}
|
|
|
|
CLAMP(ctime, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
unit_m4(mat);
|
|
|
|
|
|
|
|
/* vec: 4 items! */
|
|
|
|
if (where_on_path(par, ctime, vec, dir, (cu->flag & CU_FOLLOW) ? quat : NULL, &radius, NULL)) {
|
|
|
|
if (cu->flag & CU_FOLLOW) {
|
|
|
|
quat_apply_track(quat, ob->trackflag, ob->upflag);
|
|
|
|
normalize_qt(quat);
|
|
|
|
quat_to_mat4(mat, quat);
|
|
|
|
}
|
|
|
|
if (cu->flag & CU_PATH_RADIUS) {
|
|
|
|
float tmat[4][4], rmat[4][4];
|
|
|
|
scale_m4_fl(tmat, radius);
|
|
|
|
mul_m4_m4m4(rmat, tmat, mat);
|
|
|
|
copy_m4_m4(mat, rmat);
|
|
|
|
}
|
|
|
|
copy_v3_v3(mat[3], vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
static void ob_parbone(Object *ob, Object *par, float mat[4][4])
|
2018-06-17 17:05:51 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bPoseChannel *pchan;
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
if (par->type != OB_ARMATURE) {
|
|
|
|
unit_m4(mat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the bone is still valid */
|
|
|
|
pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
|
|
|
|
if (!pchan || !pchan->bone) {
|
|
|
|
CLOG_ERROR(
|
|
|
|
&LOG, "Object %s with Bone parent: bone %s doesn't exist", ob->id.name + 2, ob->parsubstr);
|
|
|
|
unit_m4(mat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get bone transform */
|
|
|
|
if (pchan->bone->flag & BONE_RELATIVE_PARENTING) {
|
|
|
|
/* the new option uses the root - expected behavior, but differs from old... */
|
|
|
|
/* XXX check on version patching? */
|
|
|
|
copy_m4_m4(mat, pchan->chan_mat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_m4_m4(mat, pchan->pose_mat);
|
|
|
|
|
|
|
|
/* but for backwards compatibility, the child has to move to the tail */
|
|
|
|
copy_v3_v3(vec, mat[1]);
|
|
|
|
mul_v3_fl(vec, pchan->bone->length);
|
|
|
|
add_v3_v3(mat[3], vec);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void give_parvert(Object *par, int nr, float vec[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
zero_v3(vec);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (par->type == OB_MESH) {
|
|
|
|
Mesh *me = par->data;
|
|
|
|
BMEditMesh *em = me->edit_mesh;
|
2020-02-27 11:23:15 +01:00
|
|
|
Mesh *me_eval = (em) ? em->mesh_eval_final : BKE_object_get_evaluated_mesh(par);
|
2009-03-30 07:28:37 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (me_eval) {
|
|
|
|
int count = 0;
|
2020-07-02 19:11:51 +10:00
|
|
|
int numVerts = me_eval->totvert;
|
2012-09-23 18:50:56 +00:00
|
|
|
|
2020-07-02 19:11:51 +10:00
|
|
|
if (em && me_eval->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
|
|
|
|
numVerts = em->bm->totvert;
|
2020-01-21 17:52:44 +01:00
|
|
|
if (em->bm->elem_table_dirty & BM_VERT) {
|
2014-10-31 20:15:32 +01:00
|
|
|
#ifdef VPARENT_THREADING_HACK
|
2020-01-21 17:52:44 +01:00
|
|
|
BLI_mutex_lock(&vparent_lock);
|
|
|
|
if (em->bm->elem_table_dirty & BM_VERT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
|
|
|
|
}
|
2020-01-21 17:52:44 +01:00
|
|
|
BLI_mutex_unlock(&vparent_lock);
|
|
|
|
#else
|
|
|
|
BLI_assert(!"Not safe for threading");
|
|
|
|
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
|
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-02 19:11:51 +10:00
|
|
|
if (nr < numVerts) {
|
|
|
|
if (me_eval && me_eval->runtime.edit_data && me_eval->runtime.edit_data->vertexCos) {
|
|
|
|
add_v3_v3(vec, me_eval->runtime.edit_data->vertexCos[nr]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const BMVert *v = BM_vert_at_index(em->bm, nr);
|
|
|
|
add_v3_v3(vec, v->co);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
2020-01-21 17:52:44 +01:00
|
|
|
}
|
2020-07-02 19:11:51 +10:00
|
|
|
else if (CustomData_has_layer(&me_eval->vdata, CD_ORIGINDEX)) {
|
2020-01-21 17:52:44 +01:00
|
|
|
const int *index = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
|
|
|
|
/* Get the average of all verts with (original index == nr). */
|
|
|
|
for (int i = 0; i < numVerts; i++) {
|
|
|
|
if (index[i] == nr) {
|
|
|
|
add_v3_v3(vec, me_eval->mvert[i].co);
|
2019-04-17 06:17:24 +02:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 17:52:44 +01:00
|
|
|
else {
|
|
|
|
if (nr < numVerts) {
|
|
|
|
add_v3_v3(vec, me_eval->mvert[nr].co);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
/* keep as 0, 0, 0 */
|
|
|
|
}
|
|
|
|
else if (count > 0) {
|
|
|
|
mul_v3_fl(vec, 1.0f / count);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* use first index if its out of range */
|
|
|
|
if (me_eval->totvert) {
|
|
|
|
copy_v3_v3(vec, me_eval->mvert[0].co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CLOG_ERROR(&LOG,
|
|
|
|
"Evaluated mesh is needed to solve parenting, "
|
|
|
|
"object position can be wrong now");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ELEM(par->type, OB_CURVE, OB_SURF)) {
|
|
|
|
ListBase *nurb;
|
|
|
|
|
|
|
|
/* Unless there's some weird depsgraph failure the cache should exist. */
|
|
|
|
BLI_assert(par->runtime.curve_cache != NULL);
|
|
|
|
|
|
|
|
if (par->runtime.curve_cache->deformed_nurbs.first != NULL) {
|
|
|
|
nurb = &par->runtime.curve_cache->deformed_nurbs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Curve *cu = par->data;
|
|
|
|
nurb = BKE_curve_nurbs_get(cu);
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_nurbList_index_get_co(nurb, nr, vec);
|
|
|
|
}
|
|
|
|
else if (par->type == OB_LATTICE) {
|
|
|
|
Lattice *latt = par->data;
|
|
|
|
DispList *dl = par->runtime.curve_cache ?
|
|
|
|
BKE_displist_find(&par->runtime.curve_cache->disp, DL_VERTS) :
|
|
|
|
NULL;
|
|
|
|
float(*co)[3] = dl ? (float(*)[3])dl->verts : NULL;
|
|
|
|
int tot;
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (latt->editlatt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
latt = latt->editlatt->latt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
tot = latt->pntsu * latt->pntsv * latt->pntsw;
|
|
|
|
|
|
|
|
/* ensure dl is correct size */
|
|
|
|
BLI_assert(dl == NULL || dl->nr == tot);
|
|
|
|
|
|
|
|
if (nr < tot) {
|
|
|
|
if (co) {
|
|
|
|
copy_v3_v3(vec, co[nr]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(vec, latt->def[nr].vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 14:29:01 +00:00
|
|
|
static void ob_parvert3(Object *ob, Object *par, float mat[4][4])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* in local ob space */
|
|
|
|
if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
|
|
|
|
float cmat[3][3], v1[3], v2[3], v3[3], q[4];
|
2013-09-01 22:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
give_parvert(par, ob->par1, v1);
|
|
|
|
give_parvert(par, ob->par2, v2);
|
|
|
|
give_parvert(par, ob->par3, v3);
|
2013-09-01 22:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
tri_to_quat(q, v1, v2, v3);
|
|
|
|
quat_to_mat3(cmat, q);
|
|
|
|
copy_m4_m3(mat, cmat);
|
2013-09-01 22:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mid_v3_v3v3v3(mat[3], v1, v2, v3);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unit_m4(mat);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 17:52:46 +01:00
|
|
|
void BKE_object_get_parent_matrix(Object *ob, Object *par, float parentmat[4][4])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float tmat[4][4];
|
|
|
|
float vec[3];
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
switch (ob->partype & PARTYPE) {
|
|
|
|
case PAROBJECT:
|
|
|
|
ok = 0;
|
|
|
|
if (par->type == OB_CURVE) {
|
|
|
|
if ((((Curve *)par->data)->flag & CU_PATH) && (ob_parcurve(ob, par, tmat))) {
|
|
|
|
ok = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ok) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m4_m4m4(parentmat, par->obmat, tmat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m4_m4(parentmat, par->obmat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
case PARBONE:
|
|
|
|
ob_parbone(ob, par, tmat);
|
|
|
|
mul_m4_m4m4(parentmat, par->obmat, tmat);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PARVERT1:
|
|
|
|
unit_m4(parentmat);
|
|
|
|
give_parvert(par, ob->par1, vec);
|
|
|
|
mul_v3_m4v3(parentmat[3], par->obmat, vec);
|
|
|
|
break;
|
|
|
|
case PARVERT3:
|
|
|
|
ob_parvert3(ob, par, tmat);
|
|
|
|
|
|
|
|
mul_m4_m4m4(parentmat, par->obmat, tmat);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PARSKEL:
|
|
|
|
copy_m4_m4(parentmat, par->obmat);
|
|
|
|
break;
|
|
|
|
}
|
2018-12-19 11:20:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Matrix Evaluation API
|
|
|
|
* \{ */
|
|
|
|
|
2014-01-09 00:37:41 +01:00
|
|
|
/**
|
2019-04-27 12:07:07 +10:00
|
|
|
* \param r_originmat: Optional matrix that stores the space the object is in
|
|
|
|
* (without its own matrix applied)
|
2014-01-09 00:37:41 +01:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
static void solve_parenting(
|
|
|
|
Object *ob, Object *par, float obmat[4][4], float r_originmat[3][3], const bool set_origin)
|
2014-01-09 00:37:41 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float totmat[4][4];
|
|
|
|
float tmat[4][4];
|
|
|
|
float locmat[4][4];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_to_mat4(ob, locmat);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_get_parent_matrix(ob, par, totmat);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* total */
|
|
|
|
mul_m4_m4m4(tmat, totmat, ob->parentinv);
|
|
|
|
mul_m4_m4m4(obmat, tmat, locmat);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_originmat) {
|
|
|
|
/* usable originmat */
|
|
|
|
copy_m3_m4(r_originmat, tmat);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* origin, for help line */
|
|
|
|
if (set_origin) {
|
|
|
|
if ((ob->partype & PARTYPE) == PARSKEL) {
|
|
|
|
copy_v3_v3(ob->runtime.parent_display_origin, par->obmat[3]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(ob->runtime.parent_display_origin, totmat[3]);
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 05:39:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 16:17:45 +00:00
|
|
|
/* note, scene is the active scene while actual_scene is the scene the object resides in */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void object_where_is_calc_ex(Depsgraph *depsgraph,
|
|
|
|
Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
float ctime,
|
|
|
|
RigidBodyWorld *rbw,
|
|
|
|
float r_originmat[3][3])
|
|
|
|
{
|
|
|
|
if (ob->parent) {
|
|
|
|
Object *par = ob->parent;
|
|
|
|
|
|
|
|
/* calculate parent matrix */
|
|
|
|
solve_parenting(ob, par, ob->obmat, r_originmat, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_object_to_mat4(ob, ob->obmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to fall back to the scene rigid body world if none given */
|
|
|
|
rbw = rbw ? rbw : scene->rigidbody_world;
|
|
|
|
/* read values pushed into RBO from sim/cache... */
|
|
|
|
BKE_rigidbody_sync_transforms(rbw, ob, ctime);
|
|
|
|
|
|
|
|
/* solve constraints */
|
|
|
|
if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
|
|
|
|
bConstraintOb *cob;
|
|
|
|
cob = BKE_constraints_make_evalob(depsgraph, scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
|
|
|
|
BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
|
|
|
|
BKE_constraints_clear_evalob(cob);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set negative scale flag in object */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_negative_m4(ob->obmat)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->transflag |= OB_NEG_SCALE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->transflag &= ~OB_NEG_SCALE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
|
2013-02-16 16:17:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Execute drivers and animation. */
|
2019-07-31 14:56:17 +02:00
|
|
|
const bool flush_to_original = DEG_is_active(depsgraph);
|
2020-04-16 11:05:52 +10:00
|
|
|
BKE_animsys_evaluate_animdata(&ob->id, ob->adt, ctime, ADT_RECALC_ALL, flush_to_original);
|
2019-04-17 06:17:24 +02:00
|
|
|
object_where_is_calc_ex(depsgraph, scene, ob, ctime, NULL, NULL);
|
2018-12-19 11:20:32 +01:00
|
|
|
}
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* get object transformation matrix without recalculating dependencies and
|
2012-03-03 20:19:11 +00:00
|
|
|
* constraints -- assume dependencies are already solved by depsgraph.
|
|
|
|
* no changes to object and it's parent would be done.
|
|
|
|
* used for bundles orientation in 3d space relative to parented blender camera */
|
2018-12-19 11:20:32 +01:00
|
|
|
void BKE_object_where_is_calc_mat4(Object *ob, float obmat[4][4])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->parent) {
|
|
|
|
Object *par = ob->parent;
|
|
|
|
solve_parenting(ob, par, obmat, NULL, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_object_to_mat4(ob, obmat);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_object_where_is_calc_ex(
|
|
|
|
Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float ctime = DEG_get_ctime(depsgraph);
|
|
|
|
object_where_is_calc_ex(depsgraph, scene, ob, ctime, rbw, r_originmat);
|
2013-02-16 16:17:45 +00:00
|
|
|
}
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
2013-02-16 16:17:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float ctime = DEG_get_ctime(depsgraph);
|
|
|
|
object_where_is_calc_ex(depsgraph, scene, ob, ctime, NULL, NULL);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 14:00:36 +02:00
|
|
|
/**
|
|
|
|
* For calculation of the inverse parent transform, only used for editor.
|
|
|
|
*
|
|
|
|
* It assumes the object parent is already in the depsgraph.
|
|
|
|
* Otherwise, after changing ob->parent you need to call:
|
2018-09-02 18:28:27 +10:00
|
|
|
* - #DEG_relations_tag_update(bmain);
|
|
|
|
* - #BKE_scene_graph_update_tagged(depsgraph, bmain);
|
2018-05-29 14:00:36 +02:00
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_workob_clear(workob);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
unit_m4(workob->obmat);
|
|
|
|
unit_m4(workob->parentinv);
|
|
|
|
unit_m4(workob->constinv);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Since this is used while calculating parenting,
|
|
|
|
* at this moment ob_eval->parent is still NULL. */
|
2019-04-17 06:17:24 +02:00
|
|
|
workob->parent = DEG_get_evaluated_object(depsgraph, ob->parent);
|
2018-05-29 14:00:36 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
workob->trackflag = ob->trackflag;
|
|
|
|
workob->upflag = ob->upflag;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
workob->partype = ob->partype;
|
|
|
|
workob->par1 = ob->par1;
|
|
|
|
workob->par2 = ob->par2;
|
|
|
|
workob->par3 = ob->par3;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
workob->constraints = ob->constraints;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_where_is_calc(depsgraph, scene, workob);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
/**
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
* Applies the global transformation \a mat to the \a ob using a relative parent space if
|
|
|
|
* supplied.
|
2018-05-21 20:29:00 +02:00
|
|
|
*
|
2018-12-12 12:55:20 +11:00
|
|
|
* \param mat: the global transformation mat that the object should be set object to.
|
2019-04-27 12:07:07 +10:00
|
|
|
* \param parent: the parent space in which this object will be set relative to
|
|
|
|
* (should probably always be parent_eval).
|
|
|
|
* \param use_compat: true to ensure that rotations are set using the
|
|
|
|
* min difference between the old and new orientation.
|
2018-05-21 20:29:00 +02:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_object_apply_mat4_ex(
|
|
|
|
Object *ob, float mat[4][4], Object *parent, float parentinv[4][4], const bool use_compat)
|
2014-01-09 00:37:41 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
|
2018-05-21 20:29:00 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float rot[3][3];
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (parent != NULL) {
|
|
|
|
float rmat[4][4], diff_mat[4][4], imat[4][4], parent_mat[4][4];
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_get_parent_matrix(ob, parent, parent_mat);
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m4_m4m4(diff_mat, parent_mat, parentinv);
|
|
|
|
invert_m4_m4(imat, diff_mat);
|
|
|
|
mul_m4_m4m4(rmat, imat, mat); /* get the parent relative matrix */
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same as below, use rmat rather than mat */
|
|
|
|
mat4_to_loc_rot_size(ob->loc, rot, ob->scale, rmat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mat4_to_loc_rot_size(ob->loc, rot, ob->scale, mat);
|
|
|
|
}
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_mat3_to_rot(ob, rot, use_compat);
|
2014-12-29 13:04:46 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sub_v3_v3(ob->loc, ob->dloc);
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->dscale[0] != 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->scale[0] /= ob->dscale[0];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (ob->dscale[1] != 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->scale[1] /= ob->dscale[1];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (ob->dscale[2] != 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->scale[2] /= ob->dscale[2];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-01-09 00:37:41 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* BKE_object_mat3_to_rot handles delta rotations */
|
2014-01-09 00:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-05-21 20:29:00 +02:00
|
|
|
/* XXX: should be removed after COW operators port to use BKE_object_apply_mat4_ex directly */
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_object_apply_mat4(Object *ob,
|
|
|
|
float mat[4][4],
|
|
|
|
const bool use_compat,
|
|
|
|
const bool use_parent)
|
2018-05-21 20:29:00 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_apply_mat4_ex(ob, mat, use_parent ? ob->parent : NULL, ob->parentinv, use_compat);
|
2018-05-21 20:29:00 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Bounding Box API
|
|
|
|
* \{ */
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BoundBox *BKE_boundbox_alloc_unit(void)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb;
|
|
|
|
const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb = MEM_callocN(sizeof(BoundBox), "OB-BoundBox");
|
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return bb;
|
2005-07-18 17:33:51 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-06-09 21:25:27 +00:00
|
|
|
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
|
2005-07-18 17:33:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = min[0];
|
|
|
|
bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = max[0];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = min[1];
|
|
|
|
bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = max[1];
|
2005-07-18 17:33:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = min[2];
|
|
|
|
bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = max[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:25:25 +10:00
|
|
|
void BKE_boundbox_calc_center_aabb(const BoundBox *bb, float r_cent[3])
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
r_cent[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]);
|
|
|
|
r_cent[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]);
|
|
|
|
r_cent[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]);
|
2014-08-11 13:25:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_boundbox_calc_size_aabb(const BoundBox *bb, float r_size[3])
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
r_size[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]);
|
|
|
|
r_size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
|
|
|
|
r_size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
|
2014-08-11 13:25:25 +10:00
|
|
|
}
|
|
|
|
|
2015-09-04 04:18:49 +10:00
|
|
|
void BKE_boundbox_minmax(const BoundBox *bb, float obmat[4][4], float r_min[3], float r_max[3])
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
float vec[3];
|
|
|
|
mul_v3_m4v3(vec, obmat, bb->vec[i]);
|
|
|
|
minmax_v3v3_v3(r_min, r_max, vec);
|
|
|
|
}
|
2015-09-04 04:18:49 +10:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BoundBox *BKE_object_boundbox_get(Object *ob)
|
2006-06-14 08:50:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb = NULL;
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
bb = BKE_mesh_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
|
|
|
case OB_FONT:
|
|
|
|
bb = BKE_curve_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_MBALL:
|
|
|
|
bb = BKE_mball_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_LATTICE:
|
|
|
|
bb = BKE_lattice_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_ARMATURE:
|
|
|
|
bb = BKE_armature_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_GPENCIL:
|
|
|
|
bb = BKE_gpencil_boundbox_get(ob);
|
|
|
|
break;
|
2020-03-17 14:41:48 +01:00
|
|
|
case OB_HAIR:
|
|
|
|
bb = BKE_hair_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_POINTCLOUD:
|
|
|
|
bb = BKE_pointcloud_boundbox_get(ob);
|
|
|
|
break;
|
|
|
|
case OB_VOLUME:
|
|
|
|
bb = BKE_volume_boundbox_get(ob);
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return bb;
|
2006-06-14 08:50:41 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 12:44:48 +00:00
|
|
|
/* used to temporally disable/enable boundbox */
|
2014-08-11 13:25:25 +10:00
|
|
|
void BKE_object_boundbox_flag(Object *ob, int flag, const bool set)
|
2006-11-29 12:44:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb = BKE_object_boundbox_get(ob);
|
|
|
|
if (bb) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (set) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->flag |= flag;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->flag &= ~flag;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2006-11-29 12:44:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 17:14:05 +11:00
|
|
|
void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float min[3], max[3];
|
2018-10-15 17:14:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
INIT_MINMAX(min, max);
|
2018-10-15 17:14:05 +11:00
|
|
|
|
2020-05-25 20:16:42 +10:00
|
|
|
if (!BKE_mesh_wrapper_minmax(me_eval, min, max)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
zero_v3(min);
|
|
|
|
zero_v3(max);
|
|
|
|
}
|
2018-10-15 17:14:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->runtime.bb == NULL) {
|
|
|
|
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox");
|
|
|
|
}
|
2018-10-15 17:14:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
|
2018-10-15 17:14:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
|
2018-10-15 17:14:05 +11:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
2019-09-06 20:00:45 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Dimension Get/Set
|
|
|
|
*
|
|
|
|
* \warning Setting dimensions is prone to feedback loops in evaluation.
|
|
|
|
* \{ */
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_dimensions_get(Object *ob, float vec[3])
|
2010-03-25 06:27:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb = BKE_object_boundbox_get(ob);
|
|
|
|
if (bb) {
|
|
|
|
float scale[3];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mat4_to_size(scale, ob->obmat);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
vec[0] = fabsf(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
|
|
|
|
vec[1] = fabsf(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
|
|
|
|
vec[2] = fabsf(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zero_v3(vec);
|
|
|
|
}
|
2010-03-25 06:27:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 20:00:45 +10:00
|
|
|
/**
|
|
|
|
* The original scale and object matrix can be passed in so any difference
|
|
|
|
* of the objects matrix and the final matrix can be accounted for,
|
|
|
|
* typically this caused by parenting, constraints or delta-scale.
|
|
|
|
*
|
|
|
|
* Re-using these values from the object causes a feedback loop
|
|
|
|
* when multiple values are modified at once in some situations. see: T69536.
|
|
|
|
*/
|
|
|
|
void BKE_object_dimensions_set_ex(Object *ob,
|
|
|
|
const float value[3],
|
|
|
|
int axis_mask,
|
|
|
|
const float ob_scale_orig[3],
|
|
|
|
const float ob_obmat_orig[4][4])
|
2010-03-25 06:27:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb = BKE_object_boundbox_get(ob);
|
|
|
|
if (bb) {
|
|
|
|
float len[3];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
len[0] = bb->vec[4][0] - bb->vec[0][0];
|
|
|
|
len[1] = bb->vec[2][1] - bb->vec[0][1];
|
|
|
|
len[2] = bb->vec[1][2] - bb->vec[0][2];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (((1 << i) & axis_mask) == 0) {
|
2019-09-06 20:00:45 +10:00
|
|
|
|
|
|
|
if (ob_scale_orig != NULL) {
|
|
|
|
const float scale_delta = len_v3(ob_obmat_orig[i]) / ob_scale_orig[i];
|
|
|
|
if (isfinite(scale_delta)) {
|
|
|
|
len[i] *= scale_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (len[i] > 0.0f) {
|
2019-09-06 20:00:45 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->scale[i] = copysignf(value[i] / len[i], ob->scale[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 06:27:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 20:00:45 +10:00
|
|
|
void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
|
|
|
|
{
|
|
|
|
BKE_object_dimensions_set_ex(ob, value, axis_mask, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-24 12:13:13 +00:00
|
|
|
void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool use_hidden)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox bb;
|
|
|
|
float vec[3];
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_FONT:
|
|
|
|
case OB_SURF: {
|
|
|
|
bb = *BKE_curve_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_MESH: {
|
|
|
|
bb = *BKE_mesh_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_GPENCIL: {
|
|
|
|
bb = *BKE_gpencil_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_LATTICE: {
|
|
|
|
Lattice *lt = ob->data;
|
|
|
|
BPoint *bp = lt->def;
|
|
|
|
int u, v, w;
|
|
|
|
|
|
|
|
for (w = 0; w < lt->pntsw; w++) {
|
|
|
|
for (v = 0; v < lt->pntsv; v++) {
|
|
|
|
for (u = 0; u < lt->pntsu; u++, bp++) {
|
|
|
|
mul_v3_m4v3(vec, ob->obmat, bp->vec);
|
|
|
|
minmax_v3v3_v3(min_r, max_r, vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_ARMATURE: {
|
|
|
|
changed = BKE_pose_minmax(ob, min_r, max_r, use_hidden, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_MBALL: {
|
|
|
|
float ob_min[3], ob_max[3];
|
|
|
|
|
|
|
|
changed = BKE_mball_minmax_ex(ob->data, ob_min, ob_max, ob->obmat, 0);
|
|
|
|
if (changed) {
|
|
|
|
minmax_v3v3_v3(min_r, max_r, ob_min);
|
|
|
|
minmax_v3v3_v3(min_r, max_r, ob_max);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-03-17 14:41:48 +01:00
|
|
|
case OB_HAIR: {
|
|
|
|
bb = *BKE_hair_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OB_POINTCLOUD: {
|
|
|
|
bb = *BKE_pointcloud_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_VOLUME: {
|
|
|
|
bb = *BKE_volume_boundbox_get(ob);
|
|
|
|
BKE_boundbox_minmax(&bb, ob->obmat, min_r, max_r);
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (changed == false) {
|
|
|
|
float size[3];
|
|
|
|
|
|
|
|
copy_v3_v3(size, ob->scale);
|
|
|
|
if (ob->type == OB_EMPTY) {
|
|
|
|
mul_v3_fl(size, ob->empty_drawsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
minmax_v3v3_v3(min_r, max_r, ob->obmat[3]);
|
|
|
|
|
|
|
|
copy_v3_v3(vec, ob->obmat[3]);
|
|
|
|
add_v3_v3(vec, size);
|
|
|
|
minmax_v3v3_v3(min_r, max_r, vec);
|
|
|
|
|
|
|
|
copy_v3_v3(vec, ob->obmat[3]);
|
|
|
|
sub_v3_v3(vec, size);
|
|
|
|
minmax_v3v3_v3(min_r, max_r, vec);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-01-13 21:57:05 +01:00
|
|
|
void BKE_object_empty_draw_type_set(Object *ob, const int value)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->empty_drawtype = value;
|
|
|
|
|
|
|
|
if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
|
|
|
|
if (!ob->iuser) {
|
|
|
|
ob->iuser = MEM_callocN(sizeof(ImageUser), "image user");
|
|
|
|
ob->iuser->ok = 1;
|
|
|
|
ob->iuser->flag |= IMA_ANIM_ALWAYS;
|
|
|
|
ob->iuser->frames = 100;
|
|
|
|
ob->iuser->sfra = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ob->iuser) {
|
|
|
|
MEM_freeN(ob->iuser);
|
|
|
|
ob->iuser = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-01-13 21:57:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 11:26:28 +11:00
|
|
|
bool BKE_object_empty_image_frame_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
|
2018-12-11 15:08:18 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char visibility_flag = ob->empty_image_visibility_flag;
|
|
|
|
if (rv3d->is_persp) {
|
|
|
|
return (visibility_flag & OB_EMPTY_IMAGE_HIDE_PERSPECTIVE) == 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (visibility_flag & OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC) == 0;
|
|
|
|
}
|
2019-03-07 11:26:28 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Caller is expected to check this. */
|
|
|
|
BLI_assert(BKE_object_empty_image_frame_is_visible_in_view3d(ob, rv3d));
|
|
|
|
|
|
|
|
const char visibility_flag = ob->empty_image_visibility_flag;
|
|
|
|
|
|
|
|
if ((visibility_flag & (OB_EMPTY_IMAGE_HIDE_BACK | OB_EMPTY_IMAGE_HIDE_FRONT)) != 0) {
|
|
|
|
float eps, dot;
|
|
|
|
if (rv3d->is_persp) {
|
|
|
|
/* Note, we could normalize the 'view_dir' then use 'eps'
|
|
|
|
* however the issue with empty objects being visible when viewed from the side
|
|
|
|
* is only noticeable in orthographic views. */
|
|
|
|
float view_dir[3];
|
|
|
|
sub_v3_v3v3(view_dir, rv3d->viewinv[3], ob->obmat[3]);
|
|
|
|
dot = dot_v3v3(ob->obmat[2], view_dir);
|
|
|
|
eps = 0.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dot = dot_v3v3(ob->obmat[2], rv3d->viewinv[2]);
|
|
|
|
eps = 1e-5f;
|
|
|
|
}
|
|
|
|
if (visibility_flag & OB_EMPTY_IMAGE_HIDE_BACK) {
|
|
|
|
if (dot < eps) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (visibility_flag & OB_EMPTY_IMAGE_HIDE_FRONT) {
|
|
|
|
if (dot > -eps) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 18:55:26 +10:00
|
|
|
if (visibility_flag & OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED) {
|
|
|
|
float proj[3];
|
|
|
|
project_plane_v3_v3v3(proj, ob->obmat[2], rv3d->viewinv[2]);
|
|
|
|
const float proj_length_sq = len_squared_v3(proj);
|
|
|
|
if (proj_length_sq > 1e-5f) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_object_minmax_dupli(Depsgraph *depsgraph,
|
|
|
|
Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
float r_min[3],
|
|
|
|
float r_max[3],
|
|
|
|
const bool use_hidden)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
if ((ob->transflag & OB_DUPLI) == 0) {
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ListBase *lb;
|
|
|
|
DupliObject *dob;
|
|
|
|
lb = object_duplilist(depsgraph, scene, ob);
|
|
|
|
for (dob = lb->first; dob; dob = dob->next) {
|
|
|
|
if ((use_hidden == false) && (dob->no_draw != 0)) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BoundBox *bb = BKE_object_boundbox_get(dob->ob);
|
|
|
|
|
|
|
|
if (bb) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
float vec[3];
|
|
|
|
mul_v3_m4v3(vec, dob->mat, bb->vec[i]);
|
|
|
|
minmax_v3v3_v3(r_min, r_max, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_object_duplilist(lb); /* does restore */
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_object_foreach_display_point(Object *ob,
|
|
|
|
float obmat[4][4],
|
|
|
|
void (*func_cb)(const float[3], void *),
|
|
|
|
void *user_data)
|
|
|
|
{
|
2020-03-17 14:41:48 +01:00
|
|
|
/* TODO: pointcloud and hair objects support */
|
2020-02-27 11:23:15 +01:00
|
|
|
Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
float co[3];
|
|
|
|
|
2020-02-27 11:23:15 +01:00
|
|
|
if (mesh_eval != NULL) {
|
|
|
|
const MVert *mv = mesh_eval->mvert;
|
|
|
|
const int totvert = mesh_eval->totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
for (int i = 0; i < totvert; i++, mv++) {
|
|
|
|
mul_v3_m4v3(co, obmat, mv->co);
|
|
|
|
func_cb(co, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ob->runtime.curve_cache && ob->runtime.curve_cache->disp.first) {
|
|
|
|
DispList *dl;
|
|
|
|
|
|
|
|
for (dl = ob->runtime.curve_cache->disp.first; dl; dl = dl->next) {
|
|
|
|
const float *v3 = dl->verts;
|
|
|
|
int totvert = dl->nr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < totvert; i++, v3 += 3) {
|
|
|
|
mul_v3_m4v3(co, obmat, v3);
|
|
|
|
func_cb(co, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_scene_foreach_display_point(Depsgraph *depsgraph,
|
|
|
|
void (*func_cb)(const float[3], void *),
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
DEG_OBJECT_ITER_BEGIN (depsgraph,
|
|
|
|
ob,
|
|
|
|
DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
|
|
|
|
DEG_ITER_OBJECT_FLAG_DUPLI) {
|
|
|
|
if ((ob->base_flag & BASE_SELECTED) != 0) {
|
|
|
|
BKE_object_foreach_display_point(ob, ob->obmat, func_cb, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEG_OBJECT_ITER_END;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 08:47:20 +00:00
|
|
|
/* copied from DNA_object_types.h */
|
|
|
|
typedef struct ObTfmBack {
|
2019-04-17 06:17:24 +02:00
|
|
|
float loc[3], dloc[3];
|
|
|
|
/** scale and delta scale. */
|
|
|
|
float scale[3], dscale[3];
|
|
|
|
/** euler rotation. */
|
|
|
|
float rot[3], drot[3];
|
|
|
|
/** quaternion rotation. */
|
|
|
|
float quat[4], dquat[4];
|
|
|
|
/** axis angle rotation - axis part. */
|
|
|
|
float rotAxis[3], drotAxis[3];
|
|
|
|
/** axis angle rotation - angle part. */
|
|
|
|
float rotAngle, drotAngle;
|
|
|
|
/** final worldspace matrix with constraints & animsys applied. */
|
|
|
|
float obmat[4][4];
|
|
|
|
/** inverse result of parent, so that object doesn't 'stick' to parent. */
|
|
|
|
float parentinv[4][4];
|
VR: Initial Virtual Reality support - Milestone 1, Scene Inspection
NOTE: While most of the milestone 1 goals are there, a few smaller features and
improvements are still to be done.
Big picture of this milestone: Initial, OpenXR-based virtual reality support
for users and foundation for advanced use cases.
Maniphest Task: https://developer.blender.org/T71347
The tasks contains more information about this milestone.
To be clear: This is not a feature rich VR implementation, it's focused on the
initial scene inspection use case. We intentionally focused on that, further
features like controller support are part of the next milestone.
- How to use?
Instructions on how to use this are here:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/How_to_Test
These will be updated and moved to a more official place (likely the manual) soon.
Currently Windows Mixed Reality and Oculus devices are usable. Valve/HTC
headsets don't support the OpenXR standard yet and hence, do not work with this
implementation.
---------------
This is the C-side implementation of the features added for initial VR
support as per milestone 1. A "VR Scene Inspection" Add-on will be
committed separately, to expose the VR functionality in the UI. It also
adds some further features for milestone 1, namely a landmarking system
(stored view locations in the VR space)
Main additions/features:
* Support for rendering viewports to an HMD, with good performance.
* Option to sync the VR view perspective with a fully interactive,
regular 3D View (VR-Mirror).
* Option to disable positional tracking. Keeps the current position (calculated
based on the VR eye center pose) when enabled while a VR session is running.
* Some regular viewport settings for the VR view
* RNA/Python-API to query and set VR session state information.
* WM-XR: Layer tying Ghost-XR to the Blender specific APIs/data
* wmSurface API: drawable, non-window container (manages Ghost-OpenGL and GPU
context)
* DNA/RNA for management of VR session settings
* `--debug-xr` and `--debug-xr-time` commandline options
* Utility batch & config file for using the Oculus runtime on Windows.
* Most VR data is runtime only. The exception is user settings which are saved
to files (`XrSessionSettings`).
* VR support can be disabled through the `WITH_XR_OPENXR` compiler flag.
For architecture and code documentation, see
https://wiki.blender.org/wiki/Source/Interface/XR.
---------------
A few thank you's:
* A huge shoutout to Ray Molenkamp for his help during the project - it would
have not been that successful without him!
* Sebastian Koenig and Simeon Conzendorf for testing and feedback!
* The reviewers, especially Brecht Van Lommel!
* Dalai Felinto for pushing and managing me to get this done ;)
* The OpenXR working group for providing an open standard. I think we're the
first bigger application to adopt OpenXR. Congratulations to them and
ourselves :)
This project started as a Google Summer of Code 2019 project - "Core Support of
Virtual Reality Headsets through OpenXR" (see
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/).
Some further information, including ideas for further improvements can be found
in the final GSoC report:
https://wiki.blender.org/wiki/User:Severin/GSoC-2019/Final_Report
Differential Revisions: D6193, D7098
Reviewed by: Brecht Van Lommel, Jeroen Bakker
2020-03-17 20:20:55 +01:00
|
|
|
/** inverse result of constraints. doesn't include effect of parent or object local transform.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
float constinv[4][4];
|
|
|
|
/** inverse matrix of 'obmat' for during render, temporally: ipokeys of transform. */
|
|
|
|
float imat[4][4];
|
2010-02-26 08:47:20 +00:00
|
|
|
} ObTfmBack;
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void *BKE_object_tfm_backup(Object *ob)
|
2010-02-26 08:47:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ObTfmBack *obtfm = MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack");
|
|
|
|
copy_v3_v3(obtfm->loc, ob->loc);
|
|
|
|
copy_v3_v3(obtfm->dloc, ob->dloc);
|
|
|
|
copy_v3_v3(obtfm->scale, ob->scale);
|
|
|
|
copy_v3_v3(obtfm->dscale, ob->dscale);
|
|
|
|
copy_v3_v3(obtfm->rot, ob->rot);
|
|
|
|
copy_v3_v3(obtfm->drot, ob->drot);
|
|
|
|
copy_qt_qt(obtfm->quat, ob->quat);
|
|
|
|
copy_qt_qt(obtfm->dquat, ob->dquat);
|
|
|
|
copy_v3_v3(obtfm->rotAxis, ob->rotAxis);
|
|
|
|
copy_v3_v3(obtfm->drotAxis, ob->drotAxis);
|
|
|
|
obtfm->rotAngle = ob->rotAngle;
|
|
|
|
obtfm->drotAngle = ob->drotAngle;
|
|
|
|
copy_m4_m4(obtfm->obmat, ob->obmat);
|
|
|
|
copy_m4_m4(obtfm->parentinv, ob->parentinv);
|
|
|
|
copy_m4_m4(obtfm->constinv, ob->constinv);
|
|
|
|
copy_m4_m4(obtfm->imat, ob->imat);
|
|
|
|
|
|
|
|
return (void *)obtfm;
|
2010-02-26 08:47:20 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
|
2010-02-26 08:47:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ObTfmBack *obtfm = (ObTfmBack *)obtfm_pt;
|
|
|
|
copy_v3_v3(ob->loc, obtfm->loc);
|
|
|
|
copy_v3_v3(ob->dloc, obtfm->dloc);
|
|
|
|
copy_v3_v3(ob->scale, obtfm->scale);
|
|
|
|
copy_v3_v3(ob->dscale, obtfm->dscale);
|
|
|
|
copy_v3_v3(ob->rot, obtfm->rot);
|
|
|
|
copy_v3_v3(ob->drot, obtfm->drot);
|
|
|
|
copy_qt_qt(ob->quat, obtfm->quat);
|
|
|
|
copy_qt_qt(ob->dquat, obtfm->dquat);
|
|
|
|
copy_v3_v3(ob->rotAxis, obtfm->rotAxis);
|
|
|
|
copy_v3_v3(ob->drotAxis, obtfm->drotAxis);
|
|
|
|
ob->rotAngle = obtfm->rotAngle;
|
|
|
|
ob->drotAngle = obtfm->drotAngle;
|
|
|
|
copy_m4_m4(ob->obmat, obtfm->obmat);
|
|
|
|
copy_m4_m4(ob->parentinv, obtfm->parentinv);
|
|
|
|
copy_m4_m4(ob->constinv, obtfm->constinv);
|
|
|
|
copy_m4_m4(ob->imat, obtfm->imat);
|
2010-02-26 08:47:20 +00:00
|
|
|
}
|
2007-04-14 13:18:24 +00:00
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
|
2011-12-16 10:39:43 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* test if 'ob' is a parent somewhere in par's parents */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (par == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (ob == par) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_object_parent_loop_check(par->parent, ob);
|
2011-12-16 10:39:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
static void object_handle_update_proxy(Depsgraph *depsgraph,
|
2017-11-29 16:12:39 +01:00
|
|
|
Scene *scene,
|
|
|
|
Object *object,
|
|
|
|
const bool do_proxy_update)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* The case when this is a collection proxy, object_update is called in collection.c */
|
|
|
|
if (object->proxy == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* set pointer in library proxy target, for copying, but restore it */
|
|
|
|
object->proxy->proxy_from = object;
|
|
|
|
// printf("set proxy pointer for later collection stuff %s\n", ob->id.name);
|
2017-11-29 16:12:39 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* the no-group proxy case, we call update */
|
|
|
|
if (object->proxy_group == NULL) {
|
|
|
|
if (do_proxy_update) {
|
|
|
|
// printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name);
|
|
|
|
BKE_object_handle_update(depsgraph, scene, object->proxy);
|
|
|
|
}
|
|
|
|
}
|
2017-11-29 16:12:39 +01:00
|
|
|
}
|
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/**
|
|
|
|
* Proxy rule:
|
|
|
|
* - lib_object->proxy_from == the one we borrow from, only set temporal and cleared here.
|
|
|
|
* - local_object->proxy == pointer to library object, saved in files and read.
|
|
|
|
*
|
|
|
|
* Function below is polluted with proxy exceptions, cleanup will follow!
|
|
|
|
*
|
|
|
|
* The main object update call, for object matrix, constraints, keys and displist (modifiers)
|
|
|
|
* requires flags to be set!
|
|
|
|
*
|
|
|
|
* Ideally we shouldn't have to pass the rigid body world,
|
|
|
|
* but need bigger restructuring to avoid id.
|
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_object_handle_update_ex(Depsgraph *depsgraph,
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene,
|
|
|
|
Object *ob,
|
2014-03-24 15:10:16 +06:00
|
|
|
RigidBodyWorld *rbw,
|
|
|
|
const bool do_proxy_update)
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const ID *object_data = ob->data;
|
|
|
|
const bool recalc_object = (ob->id.recalc & ID_RECALC_ALL) != 0;
|
|
|
|
const bool recalc_data = (object_data != NULL) ? ((object_data->recalc & ID_RECALC_ALL) != 0) :
|
|
|
|
0;
|
|
|
|
if (!recalc_object && !recalc_data) {
|
|
|
|
object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Speed optimization for animation lookups. */
|
|
|
|
if (ob->pose != NULL) {
|
|
|
|
BKE_pose_channels_hash_make(ob->pose);
|
|
|
|
if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
|
|
|
|
BKE_pose_update_constraint_flags(ob->pose);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (recalc_data) {
|
|
|
|
if (ob->type == OB_ARMATURE) {
|
|
|
|
/* this happens for reading old files and to match library armatures
|
|
|
|
* with poses we do it ahead of BKE_object_where_is_calc to ensure animation
|
|
|
|
* is evaluated on the rebuilt pose, otherwise we get incorrect poses
|
|
|
|
* on file load */
|
|
|
|
if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) {
|
|
|
|
/* No need to pass bmain here, we assume we do not need to rebuild DEG from here... */
|
|
|
|
BKE_pose_rebuild(NULL, ob, ob->data, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* XXX new animsys warning: depsgraph tag ID_RECALC_GEOMETRY should not skip drivers,
|
|
|
|
* which is only in BKE_object_where_is_calc now */
|
|
|
|
/* XXX: should this case be ID_RECALC_TRANSFORM instead? */
|
|
|
|
if (recalc_object || recalc_data) {
|
|
|
|
if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
|
|
|
|
printf("recalcob %s\n", ob->id.name + 2);
|
|
|
|
}
|
|
|
|
/* Handle proxy copy for target. */
|
|
|
|
if (!BKE_object_eval_proxy_copy(depsgraph, ob)) {
|
|
|
|
BKE_object_where_is_calc_ex(depsgraph, scene, rbw, ob, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recalc_data) {
|
|
|
|
BKE_object_handle_data_update(depsgraph, scene, ob);
|
|
|
|
}
|
|
|
|
|
|
|
|
ob->id.recalc &= ID_RECALC_ALL;
|
|
|
|
|
|
|
|
object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update);
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
}
|
2017-11-29 16:12:39 +01:00
|
|
|
|
2019-04-14 10:48:42 +02:00
|
|
|
/**
|
|
|
|
* \warning "scene" here may not be the scene object actually resides in.
|
2013-02-16 16:17:45 +00:00
|
|
|
* When dealing with background-sets, "scene" is actually the active scene.
|
|
|
|
* e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n
|
2019-04-14 10:48:42 +02:00
|
|
|
* rigid bodies depend on their world so use #BKE_object_handle_update_ex()
|
|
|
|
* to also pass along the current rigid body world.
|
2013-02-16 16:17:45 +00:00
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
|
2013-02-16 16:17:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_handle_update_ex(depsgraph, scene, ob, NULL, true);
|
2013-02-16 16:17:45 +00:00
|
|
|
}
|
2008-01-19 16:32:29 +00:00
|
|
|
|
2019-01-09 10:16:51 +11:00
|
|
|
void BKE_object_sculpt_data_create(Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert((ob->sculpt == NULL) && (ob->mode & OB_MODE_ALL_SCULPT));
|
|
|
|
ob->sculpt = MEM_callocN(sizeof(SculptSession), __func__);
|
|
|
|
ob->sculpt->mode_type = ob->mode;
|
2019-01-09 10:16:51 +11:00
|
|
|
}
|
|
|
|
|
2019-09-23 15:54:21 +02:00
|
|
|
int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc, float **r_size)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->data == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
switch (GS(((ID *)ob->data)->name)) {
|
|
|
|
case ID_ME: {
|
2019-09-23 15:54:21 +02:00
|
|
|
BKE_mesh_texspace_get_reference((Mesh *)ob->data, r_texflag, r_loc, r_size);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_CU: {
|
|
|
|
Curve *cu = ob->data;
|
2019-09-23 15:31:11 +02:00
|
|
|
BKE_curve_texspace_ensure(cu);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_texflag) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_texflag = &cu->texflag;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (r_loc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_loc = cu->loc;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (r_size) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_size = cu->size;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_MB: {
|
|
|
|
MetaBall *mb = ob->data;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_texflag) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_texflag = &mb->texflag;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (r_loc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_loc = mb->loc;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (r_size) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_size = mb->size;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2008-04-01 11:14:34 +00:00
|
|
|
}
|
2008-06-09 17:50:21 +00:00
|
|
|
|
2020-02-27 11:23:15 +01:00
|
|
|
/** Get evaluated mesh for given object. */
|
|
|
|
Mesh *BKE_object_get_evaluated_mesh(Object *object)
|
2018-05-25 12:27:54 +02:00
|
|
|
{
|
2020-02-27 11:23:15 +01:00
|
|
|
ID *data_eval = object->runtime.data_eval;
|
|
|
|
return (data_eval && GS(data_eval->name) == ID_ME) ? (Mesh *)data_eval : NULL;
|
2018-06-04 15:48:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get mesh which is not affected by modifiers:
|
|
|
|
* - For original objects it will be same as object->data, and it is a mesh
|
|
|
|
* which is in the corresponding bmain.
|
|
|
|
* - For copied-on-write objects it will give pointer to a copied-on-write
|
|
|
|
* mesh which corresponds to original object's mesh.
|
|
|
|
*/
|
2018-06-04 16:20:39 +02:00
|
|
|
Mesh *BKE_object_get_pre_modified_mesh(Object *object)
|
2018-06-04 15:48:37 +02:00
|
|
|
{
|
2020-02-27 11:23:15 +01:00
|
|
|
if (object->type == OB_MESH && object->runtime.data_orig != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(object->id.tag & LIB_TAG_COPIED_ON_WRITE);
|
|
|
|
BLI_assert(object->id.orig_id != NULL);
|
2020-02-27 11:23:15 +01:00
|
|
|
BLI_assert(object->runtime.data_orig->orig_id == ((Object *)object->id.orig_id)->data);
|
|
|
|
Mesh *result = (Mesh *)object->runtime.data_orig;
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
|
|
|
|
BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
|
|
|
|
return object->data;
|
2018-06-04 15:48:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a mesh which corresponds to very very original mesh from bmain.
|
|
|
|
* - For original objects it will be object->data.
|
|
|
|
* - For evaluated objects it will be same mesh as corresponding original
|
|
|
|
* object uses as data.
|
|
|
|
*/
|
|
|
|
Mesh *BKE_object_get_original_mesh(Object *object)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *result = NULL;
|
|
|
|
if (object->id.orig_id == NULL) {
|
|
|
|
BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
|
|
|
|
result = object->data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
|
|
|
|
result = ((Object *)object->id.orig_id)->data;
|
|
|
|
}
|
|
|
|
BLI_assert(result != NULL);
|
|
|
|
BLI_assert((result->id.tag & (LIB_TAG_COPIED_ON_WRITE | LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT)) ==
|
|
|
|
0);
|
|
|
|
return result;
|
2018-06-04 15:48:37 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 01:28:46 +10:00
|
|
|
static int pc_cmp(const void *a, const void *b)
|
2009-08-25 18:41:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const LinkData *ad = a, *bd = b;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (POINTER_AS_INT(ad->data) > POINTER_AS_INT(bd->data)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-08-25 18:41:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
int BKE_object_insert_ptcache(Object *ob)
|
2009-08-25 18:41:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LinkData *link = NULL;
|
|
|
|
int i = 0;
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_listbase_sort(&ob->pc_ids, pc_cmp);
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ob->pc_ids.first, i = 0; link; link = link->next, i++) {
|
|
|
|
int index = POINTER_AS_INT(link->data);
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (i < index) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
link = MEM_callocN(sizeof(LinkData), "PCLink");
|
|
|
|
link->data = POINTER_FROM_INT(i);
|
|
|
|
BLI_addtail(&ob->pc_ids, link);
|
2009-08-25 18:41:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return i;
|
2009-08-25 18:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pc_findindex(ListBase *listbase, int index)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LinkData *link = NULL;
|
|
|
|
int number = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (listbase == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
link = listbase->first;
|
|
|
|
while (link) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (POINTER_AS_INT(link->data) == index) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return number;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
number++;
|
|
|
|
link = link->next;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2009-08-25 18:41:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 23:46:10 +06:00
|
|
|
void BKE_object_delete_ptcache(Object *ob, int index)
|
2009-08-25 18:41:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int list_index = pc_findindex(&ob->pc_ids, index);
|
|
|
|
LinkData *link = BLI_findlink(&ob->pc_ids, list_index);
|
|
|
|
BLI_freelinkN(&ob->pc_ids, link);
|
2009-08-25 18:41:36 +00:00
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Data Shape Key Insert
|
|
|
|
* \{ */
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/* Mesh */
|
2018-06-12 12:53:27 +02:00
|
|
|
static KeyBlock *insert_meshkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *me = ob->data;
|
|
|
|
Key *key = me->key;
|
|
|
|
KeyBlock *kb;
|
|
|
|
int newkey = 0;
|
|
|
|
|
|
|
|
if (key == NULL) {
|
|
|
|
key = me->key = BKE_key_add(bmain, (ID *)me);
|
|
|
|
key->type = KEY_RELATIVE;
|
|
|
|
newkey = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newkey || from_mix == false) {
|
|
|
|
/* create from mesh */
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
BKE_keyblock_convert_from_mesh(me, key, kb);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* copy from current values */
|
|
|
|
int totelem;
|
|
|
|
float *data = BKE_key_evaluate_object(ob, &totelem);
|
|
|
|
|
|
|
|
/* create new block with prepared data */
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
kb->data = data;
|
|
|
|
kb->totelem = totelem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kb;
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
2020-04-07 22:20:41 +10:00
|
|
|
/* Lattice */
|
2018-06-12 12:53:27 +02:00
|
|
|
static KeyBlock *insert_lattkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Lattice *lt = ob->data;
|
|
|
|
Key *key = lt->key;
|
|
|
|
KeyBlock *kb;
|
|
|
|
int newkey = 0;
|
|
|
|
|
|
|
|
if (key == NULL) {
|
|
|
|
key = lt->key = BKE_key_add(bmain, (ID *)lt);
|
|
|
|
key->type = KEY_RELATIVE;
|
|
|
|
newkey = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newkey || from_mix == false) {
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
if (!newkey) {
|
|
|
|
KeyBlock *basekb = (KeyBlock *)key->block.first;
|
|
|
|
kb->data = MEM_dupallocN(basekb->data);
|
|
|
|
kb->totelem = basekb->totelem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_keyblock_convert_from_lattice(lt, kb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* copy from current values */
|
|
|
|
int totelem;
|
|
|
|
float *data = BKE_key_evaluate_object(ob, &totelem);
|
|
|
|
|
|
|
|
/* create new block with prepared data */
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
kb->totelem = totelem;
|
|
|
|
kb->data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kb;
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
2020-04-07 22:20:41 +10:00
|
|
|
/* Curve */
|
2018-06-12 12:53:27 +02:00
|
|
|
static KeyBlock *insert_curvekey(Main *bmain, Object *ob, const char *name, const bool from_mix)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Curve *cu = ob->data;
|
|
|
|
Key *key = cu->key;
|
|
|
|
KeyBlock *kb;
|
|
|
|
ListBase *lb = BKE_curve_nurbs_get(cu);
|
|
|
|
int newkey = 0;
|
|
|
|
|
|
|
|
if (key == NULL) {
|
|
|
|
key = cu->key = BKE_key_add(bmain, (ID *)cu);
|
|
|
|
key->type = KEY_RELATIVE;
|
|
|
|
newkey = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newkey || from_mix == false) {
|
|
|
|
/* create from curve */
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
if (!newkey) {
|
|
|
|
KeyBlock *basekb = (KeyBlock *)key->block.first;
|
|
|
|
kb->data = MEM_dupallocN(basekb->data);
|
|
|
|
kb->totelem = basekb->totelem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_keyblock_convert_from_curve(cu, kb, lb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* copy from current values */
|
|
|
|
int totelem;
|
|
|
|
float *data = BKE_key_evaluate_object(ob, &totelem);
|
|
|
|
|
|
|
|
/* create new block with prepared data */
|
|
|
|
kb = BKE_keyblock_add_ctime(key, name, false);
|
|
|
|
kb->totelem = totelem;
|
|
|
|
kb->data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kb;
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Object Shape Key API
|
|
|
|
* \{ */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
KeyBlock *BKE_object_shapekey_insert(Main *bmain,
|
|
|
|
Object *ob,
|
|
|
|
const char *name,
|
|
|
|
const bool from_mix)
|
|
|
|
{
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
return insert_meshkey(bmain, ob, name, from_mix);
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
|
|
|
return insert_curvekey(bmain, ob, name, from_mix);
|
|
|
|
case OB_LATTICE:
|
|
|
|
return insert_lattkey(bmain, ob, name, from_mix);
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 19:49:01 +10:00
|
|
|
bool BKE_object_shapekey_free(Main *bmain, Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Key **key_p, *key;
|
2015-06-08 19:49:01 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
key_p = BKE_key_from_object_p(ob);
|
|
|
|
if (ELEM(NULL, key_p, *key_p)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-08 19:49:01 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
key = *key_p;
|
|
|
|
*key_p = NULL;
|
2015-06-08 19:49:01 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_id_free_us(bmain, key);
|
2015-06-08 19:49:01 +10:00
|
|
|
|
2019-08-16 12:52:40 +02:00
|
|
|
return true;
|
2015-06-08 19:49:01 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_object_shapekey_remove(Main *bmain, Object *ob, KeyBlock *kb)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
KeyBlock *rkb;
|
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
short kb_index;
|
|
|
|
|
|
|
|
if (key == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
kb_index = BLI_findindex(&key->block, kb);
|
|
|
|
BLI_assert(kb_index != -1);
|
|
|
|
|
|
|
|
for (rkb = key->block.first; rkb; rkb = rkb->next) {
|
|
|
|
if (rkb->relative == kb_index) {
|
|
|
|
/* remap to the 'Basis' */
|
|
|
|
rkb->relative = 0;
|
|
|
|
}
|
|
|
|
else if (rkb->relative >= kb_index) {
|
|
|
|
/* Fix positional shift of the keys when kb is deleted from the list */
|
|
|
|
rkb->relative -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_remlink(&key->block, kb);
|
|
|
|
key->totkey--;
|
|
|
|
if (key->refkey == kb) {
|
|
|
|
key->refkey = key->block.first;
|
|
|
|
|
|
|
|
if (key->refkey) {
|
|
|
|
/* apply new basis key on original data */
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
BKE_keyblock_convert_to_mesh(key->refkey, ob->data);
|
|
|
|
break;
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
|
|
|
BKE_keyblock_convert_to_curve(key->refkey, ob->data, BKE_curve_nurbs_get(ob->data));
|
|
|
|
break;
|
|
|
|
case OB_LATTICE:
|
|
|
|
BKE_keyblock_convert_to_lattice(key->refkey, ob->data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kb->data) {
|
|
|
|
MEM_freeN(kb->data);
|
|
|
|
}
|
|
|
|
MEM_freeN(kb);
|
|
|
|
|
|
|
|
if (ob->shapenr > 1) {
|
|
|
|
ob->shapenr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key->totkey == 0) {
|
|
|
|
BKE_object_shapekey_free(bmain, ob);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-06-08 19:49:01 +10:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:20:41 +10:00
|
|
|
/** \} */
|
|
|
|
|
2015-03-04 14:38:16 +11:00
|
|
|
bool BKE_object_flag_test_recursive(const Object *ob, short flag)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->flag & flag) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ob->parent) {
|
|
|
|
return BKE_object_flag_test_recursive(ob->parent, flag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-04 14:38:16 +11:00
|
|
|
}
|
|
|
|
|
2018-04-14 14:27:38 +02:00
|
|
|
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
|
2013-03-09 03:34:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
for (ob_child = ob_child->parent; ob_child; ob_child = ob_child->parent) {
|
|
|
|
if (ob_child == ob_parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-03-09 03:34:01 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 08:53:35 +00:00
|
|
|
/* most important if this is modified it should _always_ return True, in certain
|
2012-04-30 12:49:26 +00:00
|
|
|
* cases false positives are hard to avoid (shape keys for example) */
|
2012-05-05 14:03:12 +00:00
|
|
|
int BKE_object_is_modified(Scene *scene, Object *ob)
|
2011-03-16 08:53:35 +00:00
|
|
|
{
|
2020-05-20 17:54:47 +02:00
|
|
|
/* Always test on original object since evaluated object may no longer
|
|
|
|
* have shape keys or modifiers that were used to evaluate it. */
|
|
|
|
ob = DEG_get_original_object(ob);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int flag = 0;
|
2011-03-16 08:53:35 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_key_from_object(ob)) {
|
|
|
|
flag |= eModifierMode_Render | eModifierMode_Realtime;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ModifierData *md;
|
|
|
|
VirtualModifierData virtualModifierData;
|
|
|
|
/* cloth */
|
2020-05-08 10:14:02 +02:00
|
|
|
for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
|
|
|
|
md = md->next) {
|
|
|
|
if ((flag & eModifierMode_Render) == 0 &&
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_is_enabled(scene, md, eModifierMode_Render)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= eModifierMode_Render;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((flag & eModifierMode_Realtime) == 0 &&
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= eModifierMode_Realtime;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return flag;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
|
2015-01-13 15:38:43 +05:00
|
|
|
/* Check of objects moves in time. */
|
|
|
|
/* NOTE: This function is currently optimized for usage in combination
|
|
|
|
* with mti->canDeform, so modifiers can quickly check if their target
|
|
|
|
* objects moves (causing deformation motion blur) or not.
|
|
|
|
*
|
|
|
|
* This makes it possible to give some degree of false-positives here,
|
2015-01-14 23:53:03 +11:00
|
|
|
* but it's currently an acceptable tradeoff between complexity and check
|
2015-01-13 15:38:43 +05:00
|
|
|
* speed. In combination with checks of modifier stack and real life usage
|
2018-09-24 17:27:41 +02:00
|
|
|
* percentage of false-positives shouldn't be that height.
|
2015-01-13 15:38:43 +05:00
|
|
|
*/
|
2019-11-26 17:59:27 +01:00
|
|
|
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
|
2015-01-13 15:38:43 +05:00
|
|
|
{
|
2019-11-26 17:59:27 +01:00
|
|
|
/* If object has any sort of animation data assume it is moving. */
|
|
|
|
if (BKE_animdata_id_is_animated(&object->id)) {
|
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (!BLI_listbase_is_empty(&object->constraints)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-26 17:59:27 +01:00
|
|
|
if (recurse_parent && object->parent != NULL) {
|
|
|
|
return BKE_object_moves_in_time(object->parent, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return false;
|
2015-01-13 15:38:43 +05:00
|
|
|
}
|
|
|
|
|
2019-11-26 17:59:27 +01:00
|
|
|
static bool object_moves_in_time(const Object *object)
|
|
|
|
{
|
|
|
|
return BKE_object_moves_in_time(object, true);
|
|
|
|
}
|
|
|
|
|
2016-04-01 15:53:40 +02:00
|
|
|
static bool object_deforms_in_time(Object *object)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_key_from_object(object) != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!BLI_listbase_is_empty(&object->modifiers)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return object_moves_in_time(object);
|
2016-04-01 15:53:40 +02:00
|
|
|
}
|
|
|
|
|
2015-01-13 15:38:43 +05:00
|
|
|
static bool constructive_modifier_is_deform_modified(ModifierData *md)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO(sergey): Consider generalizing this a bit so all modifier logic
|
|
|
|
* is concentrated in MOD_{modifier}.c file,
|
|
|
|
*/
|
|
|
|
if (md->type == eModifierType_Array) {
|
|
|
|
ArrayModifierData *amd = (ArrayModifierData *)md;
|
|
|
|
/* TODO(sergey): Check if curve is deformed. */
|
|
|
|
return (amd->start_cap != NULL && object_moves_in_time(amd->start_cap)) ||
|
|
|
|
(amd->end_cap != NULL && object_moves_in_time(amd->end_cap)) ||
|
|
|
|
(amd->curve_ob != NULL && object_moves_in_time(amd->curve_ob)) ||
|
|
|
|
(amd->offset_ob != NULL && object_moves_in_time(amd->offset_ob));
|
|
|
|
}
|
|
|
|
else if (md->type == eModifierType_Mirror) {
|
|
|
|
MirrorModifierData *mmd = (MirrorModifierData *)md;
|
|
|
|
return mmd->mirror_ob != NULL && object_moves_in_time(mmd->mirror_ob);
|
|
|
|
}
|
|
|
|
else if (md->type == eModifierType_Screw) {
|
|
|
|
ScrewModifierData *smd = (ScrewModifierData *)md;
|
|
|
|
return smd->ob_axis != NULL && object_moves_in_time(smd->ob_axis);
|
|
|
|
}
|
|
|
|
else if (md->type == eModifierType_MeshSequenceCache) {
|
|
|
|
/* NOTE: Not ideal because it's unknown whether topology changes or not.
|
|
|
|
* This will be detected later, so by assuming it's only deformation
|
|
|
|
* going on here we allow to bake deform-only mesh to Alembic and have
|
|
|
|
* proper motion blur after that.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-01-13 15:38:43 +05:00
|
|
|
}
|
|
|
|
|
2019-11-26 15:13:52 +01:00
|
|
|
static bool modifiers_has_animation_check(const Object *ob)
|
2015-01-13 15:38:43 +05:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO(sergey): This is a bit code duplication with depsgraph, but
|
|
|
|
* would be nicer to solve this as a part of new dependency graph
|
|
|
|
* work, so we avoid conflicts and so.
|
|
|
|
*/
|
|
|
|
if (ob->adt != NULL) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
FCurve *fcu;
|
|
|
|
if (adt->action != NULL) {
|
|
|
|
for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) {
|
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, "modifiers[")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
|
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, "modifiers[")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-01-13 15:38:43 +05:00
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
/* test if object is affected by deforming modifiers (for motion blur). again
|
|
|
|
* most important is to avoid false positives, this is to skip computations
|
|
|
|
* and we can still if there was actual deformation afterwards */
|
2012-05-05 14:03:12 +00:00
|
|
|
int BKE_object_is_deform_modified(Scene *scene, Object *ob)
|
2012-04-30 12:49:26 +00:00
|
|
|
{
|
2020-05-20 17:54:47 +02:00
|
|
|
/* Always test on original object since evaluated object may no longer
|
|
|
|
* have shape keys or modifiers that were used to evaluate it. */
|
|
|
|
ob = DEG_get_original_object(ob);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ModifierData *md;
|
|
|
|
VirtualModifierData virtualModifierData;
|
|
|
|
int flag = 0;
|
|
|
|
const bool is_modifier_animated = modifiers_has_animation_check(ob);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_key_from_object(ob)) {
|
|
|
|
flag |= eModifierMode_Realtime | eModifierMode_Render;
|
|
|
|
}
|
2016-04-01 15:53:40 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->type == OB_CURVE) {
|
|
|
|
Curve *cu = (Curve *)ob->data;
|
|
|
|
if (cu->taperobj != NULL && object_deforms_in_time(cu->taperobj)) {
|
|
|
|
flag |= eModifierMode_Realtime | eModifierMode_Render;
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 14:23:56 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* cloth */
|
2020-05-08 10:14:02 +02:00
|
|
|
for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-04-17 06:17:24 +02:00
|
|
|
md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
|
|
|
|
md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
bool can_deform = mti->type == eModifierTypeType_OnlyDeform || is_modifier_animated;
|
2015-01-13 15:38:43 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!can_deform) {
|
|
|
|
can_deform = constructive_modifier_is_deform_modified(md);
|
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (can_deform) {
|
2020-05-08 19:02:03 +10:00
|
|
|
if (!(flag & eModifierMode_Render) &&
|
|
|
|
BKE_modifier_is_enabled(scene, md, eModifierMode_Render)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= eModifierMode_Render;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!(flag & eModifierMode_Realtime) &&
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
flag |= eModifierMode_Realtime;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-16 08:53:35 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return flag;
|
2011-03-16 08:53:35 +00:00
|
|
|
}
|
2011-03-27 23:11:22 +00:00
|
|
|
|
2019-02-09 13:18:22 +01:00
|
|
|
/** Return the number of scenes using (instantiating) that object in their collections. */
|
|
|
|
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int num_scenes = 0;
|
|
|
|
for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) {
|
2019-09-02 14:31:19 +02:00
|
|
|
if (BKE_collection_has_object_recursive(scene->master_collection, ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
num_scenes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_scenes;
|
2019-02-09 13:18:22 +01:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:37:37 +00:00
|
|
|
MovieClip *BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClip *clip = use_default ? scene->clip : NULL;
|
|
|
|
bConstraint *con = ob->constraints.first, *scon = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while (con) {
|
|
|
|
if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scon == NULL || (scon->flag & CONSTRAINT_OFF)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
scon = con;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
con = con->next;
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scon) {
|
|
|
|
bCameraSolverConstraint *solver = scon->data;
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((solver->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
clip = solver->clip;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
clip = scene->clip;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-06-12 21:23:51 +00:00
|
|
|
|
2018-05-30 19:45:03 +02:00
|
|
|
void BKE_object_runtime_reset(Object *object)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(&object->runtime, 0, sizeof(object->runtime));
|
2018-05-30 11:49:45 +02:00
|
|
|
}
|
2012-06-12 21:23:51 +00:00
|
|
|
|
2018-12-17 12:28:16 +01:00
|
|
|
/* Reset all pointers which we don't want to be shared when copying the object. */
|
2019-02-13 14:29:27 +01:00
|
|
|
void BKE_object_runtime_reset_on_copy(Object *object, const int UNUSED(flag))
|
2018-12-17 12:28:16 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object_Runtime *runtime = &object->runtime;
|
2020-02-27 11:23:15 +01:00
|
|
|
runtime->data_eval = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
runtime->mesh_deform_eval = NULL;
|
|
|
|
runtime->curve_cache = NULL;
|
2018-12-17 12:28:16 +01:00
|
|
|
}
|
|
|
|
|
2012-06-12 21:23:51 +00:00
|
|
|
/*
|
|
|
|
* Find an associated Armature object
|
|
|
|
*/
|
|
|
|
static Object *obrel_armature_find(Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob_arm = NULL;
|
2012-06-12 21:23:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) {
|
|
|
|
ob_arm = ob->parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ModifierData *mod;
|
|
|
|
for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
|
|
|
|
if (mod->type == eModifierType_Armature) {
|
|
|
|
ob_arm = ((ArmatureModifierData *)mod)->object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-12 21:23:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob_arm;
|
2012-06-12 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 02:48:11 +11:00
|
|
|
static bool obrel_list_test(Object *ob)
|
2012-06-12 21:23:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob && !(ob->id.tag & LIB_TAG_DOIT);
|
2012-06-12 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void obrel_list_add(LinkNode **links, Object *ob)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_linklist_prepend(links, ob);
|
|
|
|
ob->id.tag |= LIB_TAG_DOIT;
|
2012-06-12 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-03-29 21:55:04 +02:00
|
|
|
* Iterates over all objects of the given scene layer.
|
2012-06-12 21:23:51 +00:00
|
|
|
* Depending on the eObjectSet flag:
|
|
|
|
* collect either OB_SET_ALL, OB_SET_VISIBLE or OB_SET_SELECTED objects.
|
2018-06-01 18:19:39 +02:00
|
|
|
* If OB_SET_VISIBLE or OB_SET_SELECTED are collected,
|
2012-06-12 21:23:51 +00:00
|
|
|
* then also add related objects according to the given includeFilters.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
LinkNode *BKE_object_relational_superset(struct ViewLayer *view_layer,
|
|
|
|
eObjectSet objectSet,
|
|
|
|
eObRelationTypes includeFilter)
|
|
|
|
{
|
|
|
|
LinkNode *links = NULL;
|
|
|
|
|
|
|
|
Base *base;
|
|
|
|
|
|
|
|
/* Remove markers from all objects */
|
|
|
|
for (base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
base->object->id.tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over all selected and visible objects */
|
|
|
|
for (base = view_layer->object_bases.first; base; base = base->next) {
|
|
|
|
if (objectSet == OB_SET_ALL) {
|
|
|
|
/* as we get all anyways just add it */
|
|
|
|
Object *ob = base->object;
|
|
|
|
obrel_list_add(&links, ob);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((objectSet == OB_SET_SELECTED && BASE_SELECTED_EDITABLE(((View3D *)NULL), base)) ||
|
|
|
|
(objectSet == OB_SET_VISIBLE && BASE_EDITABLE(((View3D *)NULL), base))) {
|
|
|
|
Object *ob = base->object;
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (obrel_list_test(ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
obrel_list_add(&links, ob);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* parent relationship */
|
|
|
|
if (includeFilter & (OB_REL_PARENT | OB_REL_PARENT_RECURSIVE)) {
|
|
|
|
Object *parent = ob->parent;
|
|
|
|
if (obrel_list_test(parent)) {
|
|
|
|
|
|
|
|
obrel_list_add(&links, parent);
|
|
|
|
|
|
|
|
/* recursive parent relationship */
|
|
|
|
if (includeFilter & OB_REL_PARENT_RECURSIVE) {
|
|
|
|
parent = parent->parent;
|
|
|
|
while (obrel_list_test(parent)) {
|
|
|
|
|
|
|
|
obrel_list_add(&links, parent);
|
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* child relationship */
|
|
|
|
if (includeFilter & (OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE)) {
|
|
|
|
Base *local_base;
|
|
|
|
for (local_base = view_layer->object_bases.first; local_base;
|
|
|
|
local_base = local_base->next) {
|
|
|
|
if (BASE_EDITABLE(((View3D *)NULL), local_base)) {
|
|
|
|
|
|
|
|
Object *child = local_base->object;
|
|
|
|
if (obrel_list_test(child)) {
|
|
|
|
if ((includeFilter & OB_REL_CHILDREN_RECURSIVE &&
|
|
|
|
BKE_object_is_child_recursive(ob, child)) ||
|
|
|
|
(includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob)) {
|
|
|
|
obrel_list_add(&links, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* include related armatures */
|
|
|
|
if (includeFilter & OB_REL_MOD_ARMATURE) {
|
|
|
|
Object *arm = obrel_armature_find(ob);
|
|
|
|
if (obrel_list_test(arm)) {
|
|
|
|
obrel_list_add(&links, arm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return links;
|
2012-06-12 21:23:51 +00:00
|
|
|
}
|
2012-07-18 09:45:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* return all groups this object is apart of, caller must free.
|
|
|
|
*/
|
2019-03-12 19:55:33 -03:00
|
|
|
struct LinkNode *BKE_object_groups(Main *bmain, Scene *scene, Object *ob)
|
2012-07-18 09:45:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LinkNode *collection_linknode = NULL;
|
|
|
|
Collection *collection = NULL;
|
|
|
|
while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
|
|
|
|
BLI_linklist_prepend(&collection_linknode, collection);
|
|
|
|
}
|
2012-07-18 09:45:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return collection_linknode;
|
2012-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 19:55:33 -03:00
|
|
|
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *ob)
|
2012-07-18 09:45:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Collection *collection = NULL;
|
|
|
|
while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
|
|
|
|
BKE_collection_object_remove(bmain, collection, ob, false);
|
|
|
|
DEG_id_tag_update(&collection->id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
}
|
2012-07-18 09:45:50 +00:00
|
|
|
}
|
2013-09-01 22:01:21 +00:00
|
|
|
|
|
|
|
/**
|
2019-03-20 00:46:33 +11:00
|
|
|
* Return a KDTree_3d from the deformed object (in worldspace)
|
2013-09-01 22:01:21 +00:00
|
|
|
*
|
|
|
|
* \note Only mesh objects currently support deforming, others are TODO.
|
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param ob:
|
|
|
|
* \param r_tot:
|
2013-09-01 22:01:21 +00:00
|
|
|
* \return The kdtree or NULL if it can't be created.
|
|
|
|
*/
|
2019-03-20 00:46:33 +11:00
|
|
|
KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot)
|
2013-09-01 22:01:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
KDTree_3d *tree = NULL;
|
|
|
|
unsigned int tot = 0;
|
|
|
|
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_MESH: {
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
Mesh *me_eval = ob->runtime.mesh_deform_eval ? ob->runtime.mesh_deform_eval :
|
|
|
|
ob->runtime.mesh_deform_eval;
|
|
|
|
const int *index;
|
|
|
|
|
|
|
|
if (me_eval && (index = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX))) {
|
|
|
|
MVert *mvert = me_eval->mvert;
|
|
|
|
uint totvert = me_eval->totvert;
|
|
|
|
|
|
|
|
/* tree over-allocs in case where some verts have ORIGINDEX_NONE */
|
|
|
|
tot = 0;
|
|
|
|
tree = BLI_kdtree_3d_new(totvert);
|
|
|
|
|
|
|
|
/* we don't how how many verts from the DM we can use */
|
|
|
|
for (i = 0; i < totvert; i++) {
|
|
|
|
if (index[i] != ORIGINDEX_NONE) {
|
|
|
|
float co[3];
|
|
|
|
mul_v3_m4v3(co, ob->obmat, mvert[i].co);
|
|
|
|
BLI_kdtree_3d_insert(tree, index[i], co);
|
|
|
|
tot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MVert *mvert = me->mvert;
|
|
|
|
|
|
|
|
tot = me->totvert;
|
|
|
|
tree = BLI_kdtree_3d_new(tot);
|
|
|
|
|
|
|
|
for (i = 0; i < tot; i++) {
|
|
|
|
float co[3];
|
|
|
|
mul_v3_m4v3(co, ob->obmat, mvert[i].co);
|
|
|
|
BLI_kdtree_3d_insert(tree, i, co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_3d_balance(tree);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF: {
|
|
|
|
/* TODO: take deformation into account */
|
|
|
|
Curve *cu = ob->data;
|
|
|
|
unsigned int i, a;
|
|
|
|
|
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
tot = BKE_nurbList_verts_count_without_handles(&cu->nurb);
|
|
|
|
tree = BLI_kdtree_3d_new(tot);
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
nu = cu->nurb.first;
|
|
|
|
while (nu) {
|
|
|
|
if (nu->bezt) {
|
|
|
|
BezTriple *bezt;
|
|
|
|
|
|
|
|
bezt = nu->bezt;
|
|
|
|
a = nu->pntsu;
|
|
|
|
while (a--) {
|
|
|
|
float co[3];
|
|
|
|
mul_v3_m4v3(co, ob->obmat, bezt->vec[1]);
|
|
|
|
BLI_kdtree_3d_insert(tree, i++, co);
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp;
|
|
|
|
|
|
|
|
bp = nu->bp;
|
|
|
|
a = nu->pntsu * nu->pntsv;
|
|
|
|
while (a--) {
|
|
|
|
float co[3];
|
|
|
|
mul_v3_m4v3(co, ob->obmat, bp->vec);
|
|
|
|
BLI_kdtree_3d_insert(tree, i++, co);
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nu = nu->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_3d_balance(tree);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_LATTICE: {
|
|
|
|
/* TODO: take deformation into account */
|
|
|
|
Lattice *lt = ob->data;
|
|
|
|
BPoint *bp;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
tree = BLI_kdtree_3d_new(tot);
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
for (bp = lt->def; i < tot; bp++) {
|
|
|
|
float co[3];
|
|
|
|
mul_v3_m4v3(co, ob->obmat, bp->vec);
|
|
|
|
BLI_kdtree_3d_insert(tree, i++, co);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_kdtree_3d_balance(tree);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_tot = tot;
|
|
|
|
return tree;
|
2013-09-01 22:01:21 +00:00
|
|
|
}
|
2015-05-12 13:38:55 +05:00
|
|
|
|
|
|
|
bool BKE_object_modifier_use_time(Object *ob, ModifierData *md)
|
|
|
|
{
|
2020-05-08 10:14:02 +02:00
|
|
|
if (BKE_modifier_depends_ontime(md)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether modifier is animated. */
|
|
|
|
/* TODO: this should be handled as part of build_animdata() -- Aligorith */
|
|
|
|
if (ob->adt) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
FCurve *fcu;
|
|
|
|
|
|
|
|
char pattern[MAX_NAME + 16];
|
|
|
|
BLI_snprintf(pattern, sizeof(pattern), "modifiers[\"%s\"]", md->name);
|
|
|
|
|
|
|
|
/* action - check for F-Curves with paths containing 'modifiers[' */
|
|
|
|
if (adt->action) {
|
|
|
|
for (fcu = (FCurve *)adt->action->curves.first; fcu != NULL; fcu = (FCurve *)fcu->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This here allows modifier properties to get driven and still update properly
|
|
|
|
*
|
|
|
|
* Workaround to get [#26764] (e.g. subsurf levels not updating when animated/driven)
|
|
|
|
* working, without the updating problems ([#28525] [#28690] [#28774] [#28777]) caused
|
|
|
|
* by the RNA updates cache introduced in r.38649
|
|
|
|
*/
|
|
|
|
for (fcu = (FCurve *)adt->drivers.first; fcu != NULL; fcu = (FCurve *)fcu->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: also, should check NLA strips, though for now assume that nobody uses
|
|
|
|
* that and we can omit that for performance reasons... */
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-05-12 13:38:55 +05:00
|
|
|
}
|
2016-01-09 04:37:53 +01:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
bool BKE_object_modifier_gpencil_use_time(Object *ob, GpencilModifierData *md)
|
|
|
|
{
|
2020-05-08 10:32:30 +02:00
|
|
|
if (BKE_gpencil_modifier_depends_ontime(md)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Check whether modifier is animated. */
|
|
|
|
/* TODO (Aligorith): this should be handled as part of build_animdata() */
|
|
|
|
if (ob->adt) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
FCurve *fcu;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
char pattern[MAX_NAME + 32];
|
|
|
|
BLI_snprintf(pattern, sizeof(pattern), "grease_pencil_modifiers[\"%s\"]", md->name);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* action - check for F-Curves with paths containing 'grease_pencil_modifiers[' */
|
|
|
|
if (adt->action) {
|
|
|
|
for (fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
|
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* This here allows modifier properties to get driven and still update properly */
|
|
|
|
for (fcu = adt->drivers.first; fcu != NULL; fcu = fcu->next) {
|
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_object_shaderfx_use_time(Object *ob, ShaderFxData *fx)
|
|
|
|
{
|
2020-05-08 10:32:30 +02:00
|
|
|
if (BKE_shaderfx_depends_ontime(fx)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Check whether effect is animated. */
|
|
|
|
/* TODO (Aligorith): this should be handled as part of build_animdata() */
|
|
|
|
if (ob->adt) {
|
|
|
|
AnimData *adt = ob->adt;
|
|
|
|
FCurve *fcu;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
char pattern[MAX_NAME + 32];
|
|
|
|
BLI_snprintf(pattern, sizeof(pattern), "shader_effects[\"%s\"]", fx->name);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* action - check for F-Curves with paths containing string[' */
|
|
|
|
if (adt->action) {
|
|
|
|
for (fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* This here allows properties to get driven and still update properly */
|
|
|
|
for (fcu = adt->drivers.first; fcu != NULL; fcu = fcu->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fcu->rna_path && strstr(fcu->rna_path, pattern)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 04:37:53 +01:00
|
|
|
/* set "ignore cache" flag for all caches on this object */
|
|
|
|
static void object_cacheIgnoreClear(Object *ob, int state)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase pidlist;
|
|
|
|
PTCacheID *pid;
|
|
|
|
BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
|
2016-01-09 04:37:53 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (pid = pidlist.first; pid; pid = pid->next) {
|
|
|
|
if (pid->cache) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (state) {
|
2019-04-17 06:17:24 +02:00
|
|
|
pid->cache->flag |= PTCACHE_IGNORE_CLEAR;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
pid->cache->flag &= ~PTCACHE_IGNORE_CLEAR;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-09 04:37:53 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelistN(&pidlist);
|
2016-01-09 04:37:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: this function should eventually be replaced by depsgraph functionality.
|
|
|
|
* Avoid calling this in new code unless there is a very good reason for it!
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph,
|
|
|
|
Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
bool update_mesh,
|
|
|
|
int parent_recursion,
|
|
|
|
float frame,
|
|
|
|
int type)
|
|
|
|
{
|
2019-07-31 14:56:17 +02:00
|
|
|
const bool flush_to_original = DEG_is_active(depsgraph);
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_findby_type(ob, (ModifierType)type);
|
2019-04-17 06:17:24 +02:00
|
|
|
bConstraint *con;
|
|
|
|
|
|
|
|
if (type == eModifierType_DynamicPaint) {
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
|
|
|
|
|
|
|
|
/* if other is dynamic paint canvas, don't update */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (pmd && pmd->canvas) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-12-16 15:50:14 +01:00
|
|
|
else if (type == eModifierType_Fluid) {
|
|
|
|
FluidModifierData *mmd = (FluidModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-16 15:50:14 +01:00
|
|
|
if (mmd && (mmd->type & MOD_FLUID_TYPE_DOMAIN) != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if object has parents, update them too */
|
|
|
|
if (parent_recursion) {
|
|
|
|
int recursion = parent_recursion - 1;
|
|
|
|
bool no_update = false;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->parent) {
|
2019-04-17 06:17:24 +02:00
|
|
|
no_update |= BKE_object_modifier_update_subframe(
|
|
|
|
depsgraph, scene, ob->parent, 0, recursion, frame, type);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (ob->track) {
|
2019-04-17 06:17:24 +02:00
|
|
|
no_update |= BKE_object_modifier_update_subframe(
|
|
|
|
depsgraph, scene, ob->track, 0, recursion, frame, type);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* skip subframe if object is parented
|
|
|
|
* to vertex of a dynamic paint canvas */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (no_update && (ob->partype == PARVERT1 || ob->partype == PARVERT3)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* also update constraint targets */
|
|
|
|
for (con = ob->constraints.first; con; con = con->next) {
|
|
|
|
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
|
|
|
|
ListBase targets = {NULL, NULL};
|
|
|
|
|
|
|
|
if (cti && cti->get_constraint_targets) {
|
|
|
|
bConstraintTarget *ct;
|
|
|
|
cti->get_constraint_targets(con, &targets);
|
|
|
|
for (ct = targets.first; ct; ct = ct->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ct->tar) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_object_modifier_update_subframe(
|
|
|
|
depsgraph, scene, ct->tar, 0, recursion, frame, type);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
/* free temp targets */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cti->flush_constraint_targets) {
|
2019-04-17 06:17:24 +02:00
|
|
|
cti->flush_constraint_targets(con, &targets, 0);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* was originally ID_RECALC_ALL - TODO - which flags are really needed??? */
|
|
|
|
/* TODO(sergey): What about animation? */
|
|
|
|
ob->id.recalc |= ID_RECALC_ALL;
|
|
|
|
if (update_mesh) {
|
2020-04-16 11:05:52 +10:00
|
|
|
BKE_animsys_evaluate_animdata(&ob->id, ob->adt, frame, ADT_RECALC_ANIM, flush_to_original);
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ignore cache clear during subframe updates
|
|
|
|
* to not mess up cache validity */
|
|
|
|
object_cacheIgnoreClear(ob, 1);
|
|
|
|
BKE_object_handle_update(depsgraph, scene, ob);
|
|
|
|
object_cacheIgnoreClear(ob, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_object_where_is_calc_time(depsgraph, scene, ob, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for curve following objects, parented curve has to be updated too */
|
|
|
|
if (ob->type == OB_CURVE) {
|
|
|
|
Curve *cu = ob->data;
|
2020-04-16 11:05:52 +10:00
|
|
|
BKE_animsys_evaluate_animdata(&cu->id, cu->adt, frame, ADT_RECALC_ANIM, flush_to_original);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
/* and armatures... */
|
|
|
|
if (ob->type == OB_ARMATURE) {
|
|
|
|
bArmature *arm = ob->data;
|
2020-04-16 11:05:52 +10:00
|
|
|
BKE_animsys_evaluate_animdata(&arm->id, arm->adt, frame, ADT_RECALC_ANIM, flush_to_original);
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_pose_where_is(depsgraph, scene, ob);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-01-09 04:37:53 +01:00
|
|
|
}
|
2018-11-19 19:33:09 +01:00
|
|
|
|
2019-05-08 09:45:20 +02:00
|
|
|
/* Updates select_id of all objects in the given bmain. */
|
|
|
|
void BKE_object_update_select_id(struct Main *bmain)
|
|
|
|
{
|
|
|
|
Object *ob = bmain->objects.first;
|
|
|
|
int select_id = 1;
|
|
|
|
while (ob) {
|
|
|
|
ob->runtime.select_id = select_id++;
|
|
|
|
ob = ob->id.next;
|
|
|
|
}
|
2019-05-16 14:11:11 +02:00
|
|
|
}
|
2019-05-16 13:49:21 +02:00
|
|
|
|
2019-05-24 14:37:47 +02:00
|
|
|
Mesh *BKE_object_to_mesh(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
|
2019-05-16 13:49:21 +02:00
|
|
|
{
|
|
|
|
BKE_object_to_mesh_clear(object);
|
|
|
|
|
2019-05-24 14:37:47 +02:00
|
|
|
Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers);
|
2019-05-16 13:49:21 +02:00
|
|
|
object->runtime.object_as_temp_mesh = mesh;
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_object_to_mesh_clear(Object *object)
|
|
|
|
{
|
|
|
|
if (object->runtime.object_as_temp_mesh == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BKE_id_free(NULL, object->runtime.object_as_temp_mesh);
|
|
|
|
object->runtime.object_as_temp_mesh = NULL;
|
|
|
|
}
|