depsgraph.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2004 Blender Foundation.
  19. * All rights reserved.
  20. *
  21. * Contributor(s): none yet.
  22. *
  23. * ***** END GPL LICENSE BLOCK *****
  24. */
  25. /** \file blender/blenkernel/intern/depsgraph.c
  26. * \ingroup bke
  27. */
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <math.h>
  32. #include "MEM_guardedalloc.h"
  33. #ifdef WIN32
  34. # include "BLI_winstuff.h"
  35. #endif
  36. #include "BLI_utildefines.h"
  37. #include "BLI_listbase.h"
  38. #include "BLI_ghash.h"
  39. #include "BLI_threads.h"
  40. #include "DNA_anim_types.h"
  41. #include "DNA_camera_types.h"
  42. #include "DNA_cachefile_types.h"
  43. #include "DNA_group_types.h"
  44. #include "DNA_lamp_types.h"
  45. #include "DNA_lattice_types.h"
  46. #include "DNA_key_types.h"
  47. #include "DNA_material_types.h"
  48. #include "DNA_mesh_types.h"
  49. #include "DNA_node_types.h"
  50. #include "DNA_scene_types.h"
  51. #include "DNA_screen_types.h"
  52. #include "DNA_windowmanager_types.h"
  53. #include "DNA_movieclip_types.h"
  54. #include "DNA_mask_types.h"
  55. #include "DNA_modifier_types.h"
  56. #include "DNA_rigidbody_types.h"
  57. #include "BKE_anim.h"
  58. #include "BKE_animsys.h"
  59. #include "BKE_action.h"
  60. #include "BKE_DerivedMesh.h"
  61. #include "BKE_collision.h"
  62. #include "BKE_curve.h"
  63. #include "BKE_effect.h"
  64. #include "BKE_fcurve.h"
  65. #include "BKE_global.h"
  66. #include "BKE_idcode.h"
  67. #include "BKE_image.h"
  68. #include "BKE_key.h"
  69. #include "BKE_library.h"
  70. #include "BKE_main.h"
  71. #include "BKE_node.h"
  72. #include "BKE_material.h"
  73. #include "BKE_mball.h"
  74. #include "BKE_modifier.h"
  75. #include "BKE_object.h"
  76. #include "BKE_paint.h"
  77. #include "BKE_particle.h"
  78. #include "BKE_pointcache.h"
  79. #include "BKE_scene.h"
  80. #include "BKE_screen.h"
  81. #include "BKE_tracking.h"
  82. #include "GPU_buffers.h"
  83. #include "atomic_ops.h"
  84. #include "depsgraph_private.h"
  85. #include "DEG_depsgraph.h"
  86. #include "DEG_depsgraph_build.h"
  87. #include "DEG_depsgraph_debug.h"
  88. #include "DEG_depsgraph_query.h"
  89. #ifdef WITH_LEGACY_DEPSGRAPH
  90. static SpinLock threaded_update_lock;
  91. void DAG_init(void)
  92. {
  93. BLI_spin_init(&threaded_update_lock);
  94. DEG_register_node_types();
  95. }
  96. void DAG_exit(void)
  97. {
  98. BLI_spin_end(&threaded_update_lock);
  99. DEG_free_node_types();
  100. }
  101. /* Queue and stack operations for dag traversal
  102. *
  103. * the queue store a list of freenodes to avoid successive alloc/dealloc
  104. */
  105. DagNodeQueue *queue_create(int slots)
  106. {
  107. DagNodeQueue *queue;
  108. DagNodeQueueElem *elem;
  109. int i;
  110. queue = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
  111. queue->freenodes = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
  112. queue->count = 0;
  113. queue->maxlevel = 0;
  114. queue->first = queue->last = NULL;
  115. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem3");
  116. elem->node = NULL;
  117. elem->next = NULL;
  118. queue->freenodes->first = queue->freenodes->last = elem;
  119. for (i = 1; i < slots; i++) {
  120. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem4");
  121. elem->node = NULL;
  122. elem->next = NULL;
  123. queue->freenodes->last->next = elem;
  124. queue->freenodes->last = elem;
  125. }
  126. queue->freenodes->count = slots;
  127. return queue;
  128. }
  129. void queue_raz(DagNodeQueue *queue)
  130. {
  131. DagNodeQueueElem *elem;
  132. elem = queue->first;
  133. if (queue->freenodes->last)
  134. queue->freenodes->last->next = elem;
  135. else
  136. queue->freenodes->first = queue->freenodes->last = elem;
  137. elem->node = NULL;
  138. queue->freenodes->count++;
  139. while (elem->next) {
  140. elem = elem->next;
  141. elem->node = NULL;
  142. queue->freenodes->count++;
  143. }
  144. queue->freenodes->last = elem;
  145. queue->count = 0;
  146. }
  147. void queue_delete(DagNodeQueue *queue)
  148. {
  149. DagNodeQueueElem *elem;
  150. DagNodeQueueElem *temp;
  151. elem = queue->first;
  152. while (elem) {
  153. temp = elem;
  154. elem = elem->next;
  155. MEM_freeN(temp);
  156. }
  157. elem = queue->freenodes->first;
  158. while (elem) {
  159. temp = elem;
  160. elem = elem->next;
  161. MEM_freeN(temp);
  162. }
  163. MEM_freeN(queue->freenodes);
  164. MEM_freeN(queue);
  165. }
  166. /* insert in queue, remove in front */
  167. void push_queue(DagNodeQueue *queue, DagNode *node)
  168. {
  169. DagNodeQueueElem *elem;
  170. int i;
  171. if (node == NULL) {
  172. fprintf(stderr, "pushing null node\n");
  173. return;
  174. }
  175. /*fprintf(stderr, "BFS push : %s %d\n", ((ID *) node->ob)->name, queue->count);*/
  176. elem = queue->freenodes->first;
  177. if (elem != NULL) {
  178. queue->freenodes->first = elem->next;
  179. if (queue->freenodes->last == elem) {
  180. queue->freenodes->last = NULL;
  181. queue->freenodes->first = NULL;
  182. }
  183. queue->freenodes->count--;
  184. }
  185. else { /* alllocating more */
  186. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
  187. elem->node = NULL;
  188. elem->next = NULL;
  189. queue->freenodes->first = queue->freenodes->last = elem;
  190. for (i = 1; i < DAGQUEUEALLOC; i++) {
  191. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
  192. elem->node = NULL;
  193. elem->next = NULL;
  194. queue->freenodes->last->next = elem;
  195. queue->freenodes->last = elem;
  196. }
  197. queue->freenodes->count = DAGQUEUEALLOC;
  198. elem = queue->freenodes->first;
  199. queue->freenodes->first = elem->next;
  200. }
  201. elem->next = NULL;
  202. elem->node = node;
  203. if (queue->last != NULL)
  204. queue->last->next = elem;
  205. queue->last = elem;
  206. if (queue->first == NULL) {
  207. queue->first = elem;
  208. }
  209. queue->count++;
  210. }
  211. /* insert in front, remove in front */
  212. void push_stack(DagNodeQueue *queue, DagNode *node)
  213. {
  214. DagNodeQueueElem *elem;
  215. int i;
  216. elem = queue->freenodes->first;
  217. if (elem != NULL) {
  218. queue->freenodes->first = elem->next;
  219. if (queue->freenodes->last == elem) {
  220. queue->freenodes->last = NULL;
  221. queue->freenodes->first = NULL;
  222. }
  223. queue->freenodes->count--;
  224. }
  225. else { /* alllocating more */
  226. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
  227. elem->node = NULL;
  228. elem->next = NULL;
  229. queue->freenodes->first = queue->freenodes->last = elem;
  230. for (i = 1; i < DAGQUEUEALLOC; i++) {
  231. elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
  232. elem->node = NULL;
  233. elem->next = NULL;
  234. queue->freenodes->last->next = elem;
  235. queue->freenodes->last = elem;
  236. }
  237. queue->freenodes->count = DAGQUEUEALLOC;
  238. elem = queue->freenodes->first;
  239. queue->freenodes->first = elem->next;
  240. }
  241. elem->next = queue->first;
  242. elem->node = node;
  243. queue->first = elem;
  244. if (queue->last == NULL)
  245. queue->last = elem;
  246. queue->count++;
  247. }
  248. DagNode *pop_queue(DagNodeQueue *queue)
  249. {
  250. DagNodeQueueElem *elem;
  251. DagNode *node;
  252. elem = queue->first;
  253. if (elem) {
  254. queue->first = elem->next;
  255. if (queue->last == elem) {
  256. queue->last = NULL;
  257. queue->first = NULL;
  258. }
  259. queue->count--;
  260. if (queue->freenodes->last)
  261. queue->freenodes->last->next = elem;
  262. queue->freenodes->last = elem;
  263. if (queue->freenodes->first == NULL)
  264. queue->freenodes->first = elem;
  265. node = elem->node;
  266. elem->node = NULL;
  267. elem->next = NULL;
  268. queue->freenodes->count++;
  269. return node;
  270. }
  271. else {
  272. fprintf(stderr, "return null\n");
  273. return NULL;
  274. }
  275. }
  276. DagNode *get_top_node_queue(DagNodeQueue *queue)
  277. {
  278. return queue->first->node;
  279. }
  280. DagForest *dag_init(void)
  281. {
  282. DagForest *forest;
  283. /* use callocN to init all zero */
  284. forest = MEM_callocN(sizeof(DagForest), "DAG root");
  285. forest->ugly_hack_sorry = true;
  286. return forest;
  287. }
  288. /* isdata = object data... */
  289. /* XXX this needs to be extended to be more flexible (so that not only objects are evaluated via depsgraph)... */
  290. static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node, int isdata)
  291. {
  292. FCurve *fcu;
  293. DagNode *node1;
  294. for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
  295. ChannelDriver *driver = fcu->driver;
  296. DriverVar *dvar;
  297. int isdata_fcu = (isdata) || (fcu->rna_path && strstr(fcu->rna_path, "modifiers["));
  298. /* loop over variables to get the target relationships */
  299. for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
  300. /* only used targets */
  301. DRIVER_TARGETS_USED_LOOPER(dvar)
  302. {
  303. if (dtar->id) {
  304. /* FIXME: other data types need to be added here so that they can work! */
  305. if (GS(dtar->id->name) == ID_OB) {
  306. Object *ob = (Object *)dtar->id;
  307. /* normal channel-drives-channel */
  308. node1 = dag_get_node(dag, dtar->id);
  309. /* check if bone... */
  310. if ((ob->type == OB_ARMATURE) &&
  311. ( ((dtar->rna_path) && strstr(dtar->rna_path, "pose.bones[")) ||
  312. ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) ))
  313. {
  314. dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
  315. }
  316. /* check if ob data */
  317. else if (dtar->rna_path && strstr(dtar->rna_path, "data."))
  318. dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
  319. /* normal */
  320. else
  321. dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_OB_DATA : DAG_RL_OB_OB, "Driver");
  322. }
  323. }
  324. }
  325. DRIVER_TARGETS_LOOPER_END
  326. }
  327. }
  328. }
  329. /* XXX: forward def for material driver handling... */
  330. static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma);
  331. /* recursive handling for shader nodetree drivers */
  332. static void dag_add_shader_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree)
  333. {
  334. bNode *n;
  335. /* nodetree itself */
  336. if (ntree->adt) {
  337. dag_add_driver_relation(ntree->adt, dag, node, 1);
  338. }
  339. /* nodetree's nodes... */
  340. for (n = ntree->nodes.first; n; n = n->next) {
  341. if (n->id) {
  342. if (GS(n->id->name) == ID_MA) {
  343. dag_add_material_driver_relations(dag, node, (Material *)n->id);
  344. }
  345. else if (n->type == NODE_GROUP) {
  346. dag_add_shader_nodetree_driver_relations(dag, node, (bNodeTree *)n->id);
  347. }
  348. }
  349. }
  350. }
  351. /* recursive handling for material drivers */
  352. static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma)
  353. {
  354. /* Prevent infinite recursion by checking (and tagging the material) as having been visited
  355. * already (see build_dag()). This assumes ma->id.tag & LIB_TAG_DOIT isn't set by anything else
  356. * in the meantime... [#32017]
  357. */
  358. if (ma->id.tag & LIB_TAG_DOIT)
  359. return;
  360. ma->id.tag |= LIB_TAG_DOIT;
  361. /* material itself */
  362. if (ma->adt)
  363. dag_add_driver_relation(ma->adt, dag, node, 1);
  364. /* textures */
  365. // TODO...
  366. //dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
  367. /* material's nodetree */
  368. if (ma->nodetree)
  369. dag_add_shader_nodetree_driver_relations(dag, node, ma->nodetree);
  370. ma->id.tag &= ~LIB_TAG_DOIT;
  371. }
  372. /* recursive handling for lamp drivers */
  373. static void dag_add_lamp_driver_relations(DagForest *dag, DagNode *node, Lamp *la)
  374. {
  375. /* Prevent infinite recursion by checking (and tagging the lamp) as having been visited
  376. * already (see build_dag()). This assumes la->id.tag & LIB_TAG_DOIT isn't set by anything else
  377. * in the meantime... [#32017]
  378. */
  379. if (la->id.tag & LIB_TAG_DOIT)
  380. return;
  381. la->id.tag |= LIB_TAG_DOIT;
  382. /* lamp itself */
  383. if (la->adt)
  384. dag_add_driver_relation(la->adt, dag, node, 1);
  385. /* textures */
  386. // TODO...
  387. //dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
  388. /* lamp's nodetree */
  389. if (la->nodetree)
  390. dag_add_shader_nodetree_driver_relations(dag, node, la->nodetree);
  391. la->id.tag &= ~LIB_TAG_DOIT;
  392. }
  393. static void create_collision_relation(DagForest *dag, DagNode *node, Object *ob1, const char *name)
  394. {
  395. DagNode *node2 = dag_get_node(dag, ob1);
  396. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, name);
  397. }
  398. void dag_add_collision_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, Group *group, int layer, unsigned int modifier_type, DagCollobjFilterFunction fn, bool dupli, const char *name)
  399. {
  400. unsigned int numcollobj;
  401. Object **collobjs = get_collisionobjects_ext(scene, ob, group, layer, &numcollobj, modifier_type, dupli);
  402. for (unsigned int i = 0; i < numcollobj; i++) {
  403. Object *ob1 = collobjs[i];
  404. if (!fn || fn(ob1, modifiers_findByType(ob1, modifier_type))) {
  405. create_collision_relation(dag, node, ob1, name);
  406. }
  407. }
  408. if (collobjs)
  409. MEM_freeN(collobjs);
  410. }
  411. void dag_add_forcefield_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, EffectorWeights *effector_weights, bool add_absorption, int skip_forcefield, const char *name)
  412. {
  413. ListBase *effectors = pdInitEffectors(scene, ob, NULL, effector_weights, false);
  414. if (effectors) {
  415. for (EffectorCache *eff = effectors->first; eff; eff = eff->next) {
  416. if (eff->ob != ob && eff->pd->forcefield != skip_forcefield) {
  417. create_collision_relation(dag, node, eff->ob, name);
  418. if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
  419. create_collision_relation(dag, node, eff->pd->f_source, "Smoke Force Domain");
  420. }
  421. if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
  422. /* Actual code uses get_collider_cache */
  423. dag_add_collision_relations(dag, scene, ob, node, NULL, eff->ob->lay, eModifierType_Collision, NULL, true, "Force Absorption");
  424. }
  425. }
  426. }
  427. }
  428. pdEndEffectors(&effectors);
  429. }
  430. static void build_dag_object(DagForest *dag, DagNode *scenenode, Main *bmain, Scene *scene, Object *ob, int mask)
  431. {
  432. bConstraint *con;
  433. DagNode *node;
  434. DagNode *node2;
  435. DagNode *node3;
  436. Key *key;
  437. ParticleSystem *psys;
  438. int addtoroot = 1;
  439. node = dag_get_node(dag, ob);
  440. if ((ob->data) && (mask & DAG_RL_DATA)) {
  441. node2 = dag_get_node(dag, ob->data);
  442. dag_add_relation(dag, node, node2, DAG_RL_DATA, "Object-Data Relation");
  443. node2->first_ancestor = ob;
  444. node2->ancestor_count += 1;
  445. }
  446. /* also build a custom data mask for dependencies that need certain layers */
  447. if (ob->type == OB_ARMATURE) {
  448. if (ob->pose) {
  449. bPoseChannel *pchan;
  450. for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
  451. for (con = pchan->constraints.first; con; con = con->next) {
  452. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
  453. ListBase targets = {NULL, NULL};
  454. bConstraintTarget *ct;
  455. if (cti && cti->get_constraint_targets) {
  456. cti->get_constraint_targets(con, &targets);
  457. for (ct = targets.first; ct; ct = ct->next) {
  458. if (ct->tar && ct->tar != ob) {
  459. // fprintf(stderr, "armature %s target :%s\n", ob->id.name, target->id.name);
  460. node3 = dag_get_node(dag, ct->tar);
  461. if (ct->subtarget[0]) {
  462. dag_add_relation(dag, node3, node, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, cti->name);
  463. if (ct->tar->type == OB_MESH)
  464. node3->customdata_mask |= CD_MASK_MDEFORMVERT;
  465. }
  466. else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH,
  467. CONSTRAINT_TYPE_CLAMPTO,
  468. CONSTRAINT_TYPE_SPLINEIK,
  469. CONSTRAINT_TYPE_SHRINKWRAP))
  470. {
  471. dag_add_relation(dag, node3, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name);
  472. }
  473. else {
  474. dag_add_relation(dag, node3, node, DAG_RL_OB_DATA, cti->name);
  475. }
  476. }
  477. }
  478. if (cti->flush_constraint_targets)
  479. cti->flush_constraint_targets(con, &targets, 1);
  480. }
  481. }
  482. }
  483. }
  484. }
  485. /* driver dependencies, nla modifiers */
  486. #if 0 // XXX old animation system
  487. if (ob->nlastrips.first) {
  488. bActionStrip *strip;
  489. bActionChannel *chan;
  490. for (strip = ob->nlastrips.first; strip; strip = strip->next) {
  491. if (strip->modifiers.first) {
  492. bActionModifier *amod;
  493. for (amod = strip->modifiers.first; amod; amod = amod->next) {
  494. if (amod->ob) {
  495. node2 = dag_get_node(dag, amod->ob);
  496. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "NLA Strip Modifier");
  497. }
  498. }
  499. }
  500. }
  501. }
  502. #endif // XXX old animation system
  503. if (ob->adt)
  504. dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation
  505. key = BKE_key_from_object(ob);
  506. if (key && key->adt)
  507. dag_add_driver_relation(key->adt, dag, node, 1);
  508. if (ob->modifiers.first) {
  509. ModifierData *md;
  510. for (md = ob->modifiers.first; md; md = md->next) {
  511. const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
  512. if (mti->updateDepgraph) mti->updateDepgraph(md, dag, bmain, scene, ob, node);
  513. }
  514. }
  515. if (ob->parent) {
  516. node2 = dag_get_node(dag, ob->parent);
  517. switch (ob->partype) {
  518. case PARSKEL:
  519. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Parent");
  520. break;
  521. case PARVERT1: case PARVERT3:
  522. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Vertex Parent");
  523. node2->customdata_mask |= CD_MASK_ORIGINDEX;
  524. break;
  525. case PARBONE:
  526. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Bone Parent");
  527. break;
  528. default:
  529. if (ob->parent->type == OB_LATTICE)
  530. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Lattice Parent");
  531. else if (ob->parent->type == OB_CURVE) {
  532. Curve *cu = ob->parent->data;
  533. if (cu->flag & CU_PATH)
  534. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Curve Parent");
  535. else
  536. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Curve Parent");
  537. }
  538. else
  539. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Parent");
  540. break;
  541. }
  542. /* exception case: parent is duplivert */
  543. if (ob->type == OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) {
  544. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
  545. }
  546. addtoroot = 0;
  547. }
  548. if (ob->proxy) {
  549. node2 = dag_get_node(dag, ob->proxy);
  550. dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Proxy");
  551. /* inverted relation, so addtoroot shouldn't be set to zero */
  552. }
  553. if (ob->transflag & OB_DUPLI) {
  554. if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
  555. GroupObject *go;
  556. for (go = ob->dup_group->gobject.first; go; go = go->next) {
  557. if (go->ob) {
  558. node2 = dag_get_node(dag, go->ob);
  559. /* node2 changes node1, this keeps animations updated in groups?? not logical? */
  560. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Dupligroup");
  561. }
  562. }
  563. }
  564. }
  565. /* rigidbody force fields */
  566. if ((ob->type == OB_MESH) || (ob->type == OB_CURVE) || (ob->type == OB_LATTICE)) {
  567. if (ob->rigidbody_object && scene->rigidbody_world) {
  568. dag_add_forcefield_relations(dag, scene, ob, node, scene->rigidbody_world->effector_weights, true, 0, "Force Field");
  569. }
  570. }
  571. /* object data drivers */
  572. if (ob->data) {
  573. AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
  574. if (adt)
  575. dag_add_driver_relation(adt, dag, node, 1);
  576. }
  577. /* object type/data relationships */
  578. switch (ob->type) {
  579. case OB_CAMERA:
  580. {
  581. Camera *cam = (Camera *)ob->data;
  582. if (cam->dof_ob) {
  583. node2 = dag_get_node(dag, cam->dof_ob);
  584. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Camera DoF");
  585. }
  586. break;
  587. }
  588. case OB_MBALL:
  589. {
  590. Object *mom = BKE_mball_basis_find(scene, ob);
  591. if (mom != ob) {
  592. node2 = dag_get_node(dag, mom);
  593. dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Metaball"); /* mom depends on children! */
  594. }
  595. break;
  596. }
  597. case OB_CURVE:
  598. case OB_FONT:
  599. {
  600. Curve *cu = ob->data;
  601. if (cu->bevobj) {
  602. node2 = dag_get_node(dag, cu->bevobj);
  603. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Bevel");
  604. }
  605. if (cu->taperobj) {
  606. node2 = dag_get_node(dag, cu->taperobj);
  607. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Taper");
  608. }
  609. if (ob->type == OB_FONT) {
  610. /* Really rather dirty hack. needs to support font family to work
  611. * reliably on render export.
  612. *
  613. * This totally mimics behavior of regular verts duplication with
  614. * parenting. The only tricky thing here is to get list of objects
  615. * used for the custom "font".
  616. *
  617. * This shouldn't harm so much because this code only runs on DAG
  618. * rebuild and this feature is not that commonly used.
  619. *
  620. * - sergey -
  621. */
  622. if (cu->family[0] != '\n') {
  623. ListBase *duplilist;
  624. DupliObject *dob;
  625. duplilist = object_duplilist(G.main->eval_ctx, scene, ob);
  626. for (dob = duplilist->first; dob; dob = dob->next) {
  627. node2 = dag_get_node(dag, dob->ob);
  628. dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Object Font");
  629. }
  630. free_object_duplilist(duplilist);
  631. }
  632. if (cu->textoncurve) {
  633. node2 = dag_get_node(dag, cu->textoncurve);
  634. /* Text on curve requires path to be evaluated for the target curve. */
  635. node2->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
  636. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Texture On Curve");
  637. }
  638. }
  639. break;
  640. }
  641. }
  642. /* material drivers */
  643. if (ob->totcol) {
  644. int a;
  645. for (a = 1; a <= ob->totcol; a++) {
  646. Material *ma = give_current_material(ob, a);
  647. if (ma) {
  648. /* recursively figure out if there are drivers, and hook these up to this object */
  649. dag_add_material_driver_relations(dag, node, ma);
  650. }
  651. }
  652. }
  653. else if (ob->type == OB_LAMP) {
  654. dag_add_lamp_driver_relations(dag, node, ob->data);
  655. }
  656. /* particles */
  657. psys = ob->particlesystem.first;
  658. if (psys) {
  659. GroupObject *go;
  660. for (; psys; psys = psys->next) {
  661. BoidRule *rule = NULL;
  662. BoidState *state = NULL;
  663. ParticleSettings *part = psys->part;
  664. if (part->adt) {
  665. dag_add_driver_relation(part->adt, dag, node, 1);
  666. }
  667. dag_add_relation(dag, node, node, DAG_RL_OB_DATA, "Particle-Object Relation");
  668. if (!psys_check_enabled(ob, psys, G.is_rendering))
  669. continue;
  670. if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) {
  671. ParticleTarget *pt = psys->targets.first;
  672. for (; pt; pt = pt->next) {
  673. if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) {
  674. node2 = dag_get_node(dag, pt->ob);
  675. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets");
  676. }
  677. }
  678. }
  679. if (part->ren_as == PART_DRAW_OB && part->dup_ob) {
  680. node2 = dag_get_node(dag, part->dup_ob);
  681. /* note that this relation actually runs in the wrong direction, the problem
  682. * is that dupli system all have this (due to parenting), and the render
  683. * engine instancing assumes particular ordering of objects in list */
  684. dag_add_relation(dag, node, node2, DAG_RL_OB_OB, "Particle Object Visualization");
  685. if (part->dup_ob->type == OB_MBALL)
  686. dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA, "Particle Object Visualization");
  687. }
  688. if (part->ren_as == PART_DRAW_GR && part->dup_group) {
  689. for (go = part->dup_group->gobject.first; go; go = go->next) {
  690. node2 = dag_get_node(dag, go->ob);
  691. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization");
  692. }
  693. }
  694. if (part->type != PART_HAIR) {
  695. /* Actual code uses get_collider_cache */
  696. dag_add_collision_relations(dag, scene, ob, node, part->collision_group, ob->lay, eModifierType_Collision, NULL, true, "Particle Collision");
  697. }
  698. else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) {
  699. /* Hair uses cloth simulation, i.e. get_collision_objects */
  700. dag_add_collision_relations(dag, scene, ob, node, psys->clmd->coll_parms->group, ob->lay | scene->lay, eModifierType_Collision, NULL, true, "Hair Collision");
  701. }
  702. dag_add_forcefield_relations(dag, scene, ob, node, part->effector_weights, part->type == PART_HAIR, 0, "Particle Force Field");
  703. if (part->boids) {
  704. for (state = part->boids->states.first; state; state = state->next) {
  705. for (rule = state->rules.first; rule; rule = rule->next) {
  706. Object *ruleob = NULL;
  707. if (rule->type == eBoidRuleType_Avoid)
  708. ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
  709. else if (rule->type == eBoidRuleType_FollowLeader)
  710. ruleob = ((BoidRuleFollowLeader *)rule)->ob;
  711. if (ruleob) {
  712. node2 = dag_get_node(dag, ruleob);
  713. dag_add_relation(dag, node2, node, DAG_RL_OB_DATA, "Boid Rule");
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }
  720. /* object constraints */
  721. for (con = ob->constraints.first; con; con = con->next) {
  722. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
  723. ListBase targets = {NULL, NULL};
  724. bConstraintTarget *ct;
  725. if (!cti)
  726. continue;
  727. /* special case for camera tracking -- it doesn't use targets to define relations */
  728. if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) {
  729. int depends_on_camera = 0;
  730. if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
  731. bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
  732. if ((data->clip || data->flag & FOLLOWTRACK_ACTIVECLIP) && data->track[0])
  733. depends_on_camera = 1;
  734. if (data->depth_ob) {
  735. node2 = dag_get_node(dag, data->depth_ob);
  736. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
  737. }
  738. }
  739. else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER)
  740. depends_on_camera = 1;
  741. if (depends_on_camera && scene->camera) {
  742. node2 = dag_get_node(dag, scene->camera);
  743. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
  744. }
  745. dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
  746. addtoroot = 0;
  747. }
  748. else if (cti->get_constraint_targets) {
  749. cti->get_constraint_targets(con, &targets);
  750. for (ct = targets.first; ct; ct = ct->next) {
  751. Object *obt;
  752. if (ct->tar)
  753. obt = ct->tar;
  754. else
  755. continue;
  756. node2 = dag_get_node(dag, obt);
  757. if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO))
  758. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
  759. else {
  760. if (ELEM(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
  761. dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
  762. if (obt->type == OB_MESH)
  763. node2->customdata_mask |= CD_MASK_MDEFORMVERT;
  764. }
  765. else if (cti->type == CONSTRAINT_TYPE_SHRINKWRAP) {
  766. dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name);
  767. }
  768. else {
  769. dag_add_relation(dag, node2, node, DAG_RL_OB_OB, cti->name);
  770. }
  771. }
  772. addtoroot = 0;
  773. }
  774. if (cti->flush_constraint_targets)
  775. cti->flush_constraint_targets(con, &targets, 1);
  776. }
  777. }
  778. if (addtoroot == 1)
  779. dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
  780. }
  781. static void build_dag_group(DagForest *dag, DagNode *scenenode, Main *bmain, Scene *scene, Group *group, short mask)
  782. {
  783. GroupObject *go;
  784. if (group->id.tag & LIB_TAG_DOIT)
  785. return;
  786. group->id.tag |= LIB_TAG_DOIT;
  787. for (go = group->gobject.first; go; go = go->next) {
  788. build_dag_object(dag, scenenode, bmain, scene, go->ob, mask);
  789. if (go->ob->dup_group)
  790. build_dag_group(dag, scenenode, bmain, scene, go->ob->dup_group, mask);
  791. }
  792. }
  793. DagForest *build_dag(Main *bmain, Scene *sce, short mask)
  794. {
  795. Base *base;
  796. Object *ob;
  797. DagNode *node;
  798. DagNode *scenenode;
  799. DagForest *dag;
  800. DagAdjList *itA;
  801. dag = sce->theDag;
  802. if (dag)
  803. free_forest(dag);
  804. else {
  805. dag = dag_init();
  806. sce->theDag = dag;
  807. }
  808. dag->need_update = false;
  809. BKE_main_id_tag_idcode(bmain, ID_OB, LIB_TAG_DOIT, false);
  810. /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */
  811. BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
  812. BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
  813. BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
  814. /* add base node for scene. scene is always the first node in DAG */
  815. scenenode = dag_add_node(dag, sce);
  816. /* add current scene objects */
  817. for (base = sce->base.first; base; base = base->next) {
  818. ob = base->object;
  819. ob->id.tag |= LIB_TAG_DOIT;
  820. build_dag_object(dag, scenenode, bmain, sce, ob, mask);
  821. if (ob->proxy)
  822. build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
  823. if (ob->dup_group)
  824. build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
  825. }
  826. /* There might be situations when object from current scene depends on
  827. * objects form other scene AND objects from other scene has own
  828. * dependencies on objects from other scene.
  829. *
  830. * This is really important to include such indirect dependencies in order
  831. * to keep threaded update safe but since we don't really know if object is
  832. * coming from current scene or another scene we do rather stupid tag-based
  833. * check here: all the objects for which build_dag_object() was called are
  834. * getting tagged with LIB_TAG_DOIT. This way if some node has untagged
  835. * object we know it's an object from other scene.
  836. *
  837. * It should be enough to to it once, because if there's longer chain of
  838. * indirect dependencies, all the new nodes will be added to the end of the
  839. * list, meaning we'll keep covering them in this for loop.
  840. */
  841. for (node = sce->theDag->DagNode.first; node != NULL; node = node->next) {
  842. if (node->type == ID_OB) {
  843. ob = node->ob;
  844. if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
  845. ob->id.tag |= LIB_TAG_DOIT;
  846. build_dag_object(dag, scenenode, bmain, sce, ob, mask);
  847. if (ob->proxy)
  848. build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
  849. if (ob->dup_group)
  850. build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
  851. }
  852. }
  853. }
  854. BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
  855. /* Now all relations were built, but we need to solve 1 exceptional case;
  856. * When objects have multiple "parents" (for example parent + constraint working on same object)
  857. * the relation type has to be synced. One of the parents can change, and should give same event to child */
  858. /* nodes were callocced, so we can use node->color for temporal storage */
  859. for (node = sce->theDag->DagNode.first; node; node = node->next) {
  860. if (node->type == ID_OB) {
  861. for (itA = node->child; itA; itA = itA->next) {
  862. if (itA->node->type == ID_OB) {
  863. itA->node->color |= itA->type;
  864. }
  865. }
  866. /* also flush custom data mask */
  867. ((Object *)node->ob)->customdata_mask = node->customdata_mask;
  868. if (node->parent == NULL) {
  869. dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
  870. }
  871. }
  872. }
  873. /* now set relations equal, so that when only one parent changes, the correct recalcs are found */
  874. for (node = sce->theDag->DagNode.first; node; node = node->next) {
  875. if (node->type == ID_OB) {
  876. for (itA = node->child; itA; itA = itA->next) {
  877. if (itA->node->type == ID_OB) {
  878. itA->type |= itA->node->color;
  879. }
  880. }
  881. }
  882. }
  883. /* cycle detection and solving */
  884. // solve_cycles(dag);
  885. return dag;
  886. }
  887. void free_forest(DagForest *Dag)
  888. { /* remove all nodes and deps */
  889. DagNode *tempN;
  890. DagAdjList *tempA;
  891. DagAdjList *itA;
  892. DagNode *itN = Dag->DagNode.first;
  893. while (itN) {
  894. itA = itN->child;
  895. while (itA) {
  896. tempA = itA;
  897. itA = itA->next;
  898. MEM_freeN(tempA);
  899. }
  900. itA = itN->parent;
  901. while (itA) {
  902. tempA = itA;
  903. itA = itA->next;
  904. MEM_freeN(tempA);
  905. }
  906. tempN = itN;
  907. itN = itN->next;
  908. MEM_freeN(tempN);
  909. }
  910. BLI_ghash_free(Dag->nodeHash, NULL, NULL);
  911. Dag->nodeHash = NULL;
  912. Dag->DagNode.first = NULL;
  913. Dag->DagNode.last = NULL;
  914. Dag->numNodes = 0;
  915. }
  916. DagNode *dag_find_node(DagForest *forest, void *fob)
  917. {
  918. if (forest->nodeHash)
  919. return BLI_ghash_lookup(forest->nodeHash, fob);
  920. return NULL;
  921. }
  922. static int dag_print_dependencies = 0; /* debugging */
  923. /* no checking of existence, use dag_find_node first or dag_get_node */
  924. DagNode *dag_add_node(DagForest *forest, void *fob)
  925. {
  926. DagNode *node;
  927. node = MEM_callocN(sizeof(DagNode), "DAG node");
  928. if (node) {
  929. node->ob = fob;
  930. node->color = DAG_WHITE;
  931. if (forest->ugly_hack_sorry) node->type = GS(((ID *) fob)->name); /* sorry, done for pose sorting */
  932. if (forest->numNodes) {
  933. ((DagNode *) forest->DagNode.last)->next = node;
  934. forest->DagNode.last = node;
  935. forest->numNodes++;
  936. }
  937. else {
  938. forest->DagNode.last = node;
  939. forest->DagNode.first = node;
  940. forest->numNodes = 1;
  941. }
  942. if (!forest->nodeHash)
  943. forest->nodeHash = BLI_ghash_ptr_new("dag_add_node gh");
  944. BLI_ghash_insert(forest->nodeHash, fob, node);
  945. }
  946. return node;
  947. }
  948. DagNode *dag_get_node(DagForest *forest, void *fob)
  949. {
  950. DagNode *node;
  951. node = dag_find_node(forest, fob);
  952. if (!node)
  953. node = dag_add_node(forest, fob);
  954. return node;
  955. }
  956. DagNode *dag_get_sub_node(DagForest *forest, void *fob)
  957. {
  958. DagNode *node;
  959. DagAdjList *mainchild, *prev = NULL;
  960. mainchild = ((DagNode *) forest->DagNode.first)->child;
  961. /* remove from first node (scene) adj list if present */
  962. while (mainchild) {
  963. if (mainchild->node == fob) {
  964. if (prev) {
  965. prev->next = mainchild->next;
  966. MEM_freeN(mainchild);
  967. break;
  968. }
  969. else {
  970. ((DagNode *) forest->DagNode.first)->child = mainchild->next;
  971. MEM_freeN(mainchild);
  972. break;
  973. }
  974. }
  975. prev = mainchild;
  976. mainchild = mainchild->next;
  977. }
  978. node = dag_find_node(forest, fob);
  979. if (!node)
  980. node = dag_add_node(forest, fob);
  981. return node;
  982. }
  983. static void dag_add_parent_relation(DagForest *UNUSED(forest), DagNode *fob1, DagNode *fob2, short rel, const char *name)
  984. {
  985. DagAdjList *itA = fob2->parent;
  986. while (itA) { /* search if relation exist already */
  987. if (itA->node == fob1) {
  988. itA->type |= rel;
  989. itA->count += 1;
  990. return;
  991. }
  992. itA = itA->next;
  993. }
  994. /* create new relation and insert at head. MALLOC alert! */
  995. itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
  996. itA->node = fob1;
  997. itA->type = rel;
  998. itA->count = 1;
  999. itA->next = fob2->parent;
  1000. itA->name = name;
  1001. fob2->parent = itA;
  1002. }
  1003. void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, const char *name)
  1004. {
  1005. DagAdjList *itA = fob1->child;
  1006. /* parent relation is for cycle checking */
  1007. dag_add_parent_relation(forest, fob1, fob2, rel, name);
  1008. /* TODO(sergey): Find a better place for this. */
  1009. #ifdef WITH_OPENSUBDIV
  1010. if ((rel & (DAG_RL_DATA_DATA | DAG_RL_DATA_OB)) != 0) {
  1011. if (fob1->type == ID_OB) {
  1012. if ((fob1->eval_flags & DAG_EVAL_NEED_CPU) == 0) {
  1013. Object *ob2 = fob2->ob;
  1014. if (ob2->recalc & OB_RECALC_ALL) {
  1015. /* Make sure object has all the data on CPU. */
  1016. Object *ob1 = fob1->ob;
  1017. ob1->recalc |= OB_RECALC_DATA;
  1018. }
  1019. fob1->eval_flags |= DAG_EVAL_NEED_CPU;
  1020. }
  1021. }
  1022. }
  1023. #endif
  1024. while (itA) { /* search if relation exist already */
  1025. if (itA->node == fob2) {
  1026. itA->type |= rel;
  1027. itA->count += 1;
  1028. return;
  1029. }
  1030. itA = itA->next;
  1031. }
  1032. /* create new relation and insert at head. MALLOC alert! */
  1033. itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
  1034. itA->node = fob2;
  1035. itA->type = rel;
  1036. itA->count = 1;
  1037. itA->next = fob1->child;
  1038. itA->name = name;
  1039. fob1->child = itA;
  1040. }
  1041. static const char *dag_node_name(DagForest *dag, DagNode *node)
  1042. {
  1043. if (node->ob == NULL)
  1044. return "null";
  1045. else if (dag->ugly_hack_sorry)
  1046. return ((ID *)(node->ob))->name + 2;
  1047. else
  1048. return ((bPoseChannel *)(node->ob))->name;
  1049. }
  1050. static void dag_node_print_dependencies(DagForest *dag, DagNode *node)
  1051. {
  1052. DagAdjList *itA;
  1053. printf("%s depends on:\n", dag_node_name(dag, node));
  1054. for (itA = node->parent; itA; itA = itA->next)
  1055. printf(" %s through %s\n", dag_node_name(dag, itA->node), itA->name);
  1056. printf("\n");
  1057. }
  1058. static int dag_node_print_dependency_recurs(DagForest *dag, DagNode *node, DagNode *endnode)
  1059. {
  1060. DagAdjList *itA;
  1061. if (node->color == DAG_BLACK)
  1062. return 0;
  1063. node->color = DAG_BLACK;
  1064. if (node == endnode)
  1065. return 1;
  1066. for (itA = node->parent; itA; itA = itA->next) {
  1067. if (dag_node_print_dependency_recurs(dag, itA->node, endnode)) {
  1068. printf(" %s depends on %s through %s.\n", dag_node_name(dag, node), dag_node_name(dag, itA->node), itA->name);
  1069. return 1;
  1070. }
  1071. }
  1072. return 0;
  1073. }
  1074. static void dag_node_print_dependency_cycle(DagForest *dag, DagNode *startnode, DagNode *endnode, const char *name)
  1075. {
  1076. DagNode *node;
  1077. for (node = dag->DagNode.first; node; node = node->next)
  1078. node->color = DAG_WHITE;
  1079. printf(" %s depends on %s through %s.\n", dag_node_name(dag, endnode), dag_node_name(dag, startnode), name);
  1080. dag_node_print_dependency_recurs(dag, startnode, endnode);
  1081. printf("\n");
  1082. }
  1083. static int dag_node_recurs_level(DagNode *node, int level)
  1084. {
  1085. DagAdjList *itA;
  1086. int newlevel;
  1087. node->color = DAG_BLACK; /* done */
  1088. newlevel = ++level;
  1089. for (itA = node->parent; itA; itA = itA->next) {
  1090. if (itA->node->color == DAG_WHITE) {
  1091. itA->node->ancestor_count = dag_node_recurs_level(itA->node, level);
  1092. newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
  1093. }
  1094. else
  1095. newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
  1096. }
  1097. return newlevel;
  1098. }
  1099. static void dag_check_cycle(DagForest *dag)
  1100. {
  1101. DagNode *node;
  1102. DagAdjList *itA;
  1103. dag->is_acyclic = true;
  1104. /* debugging print */
  1105. if (dag_print_dependencies)
  1106. for (node = dag->DagNode.first; node; node = node->next)
  1107. dag_node_print_dependencies(dag, node);
  1108. /* tag nodes unchecked */
  1109. for (node = dag->DagNode.first; node; node = node->next)
  1110. node->color = DAG_WHITE;
  1111. for (node = dag->DagNode.first; node; node = node->next) {
  1112. if (node->color == DAG_WHITE) {
  1113. node->ancestor_count = dag_node_recurs_level(node, 0);
  1114. }
  1115. }
  1116. /* check relations, and print errors */
  1117. for (node = dag->DagNode.first; node; node = node->next) {
  1118. for (itA = node->parent; itA; itA = itA->next) {
  1119. if (itA->node->ancestor_count > node->ancestor_count) {
  1120. if (node->ob && itA->node->ob) {
  1121. dag->is_acyclic = false;
  1122. printf("Dependency cycle detected:\n");
  1123. dag_node_print_dependency_cycle(dag, itA->node, node, itA->name);
  1124. }
  1125. }
  1126. }
  1127. }
  1128. /* parent relations are only needed for cycle checking, so free now */
  1129. for (node = dag->DagNode.first; node; node = node->next) {
  1130. while (node->parent) {
  1131. itA = node->parent->next;
  1132. MEM_freeN(node->parent);
  1133. node->parent = itA;
  1134. }
  1135. }
  1136. }
  1137. /* debug test functions */
  1138. void graph_print_queue(DagNodeQueue *nqueue)
  1139. {
  1140. DagNodeQueueElem *queueElem;
  1141. queueElem = nqueue->first;
  1142. while (queueElem) {
  1143. fprintf(stderr, "** %s %i %i-%i ", ((ID *) queueElem->node->ob)->name, queueElem->node->color, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
  1144. queueElem = queueElem->next;
  1145. }
  1146. fprintf(stderr, "\n");
  1147. }
  1148. void graph_print_queue_dist(DagNodeQueue *nqueue)
  1149. {
  1150. DagNodeQueueElem *queueElem;
  1151. int count;
  1152. queueElem = nqueue->first;
  1153. count = 0;
  1154. while (queueElem) {
  1155. fprintf(stderr, "** %25s %2.2i-%2.2i ", ((ID *) queueElem->node->ob)->name, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
  1156. while (count < queueElem->node->DFS_dvtm - 1) { fputc(' ', stderr); count++; }
  1157. fputc('|', stderr);
  1158. while (count < queueElem->node->DFS_fntm - 2) { fputc('-', stderr); count++; }
  1159. fputc('|', stderr);
  1160. fputc('\n', stderr);
  1161. count = 0;
  1162. queueElem = queueElem->next;
  1163. }
  1164. fprintf(stderr, "\n");
  1165. }
  1166. void graph_print_adj_list(DagForest *dag)
  1167. {
  1168. DagNode *node;
  1169. DagAdjList *itA;
  1170. node = dag->DagNode.first;
  1171. while (node) {
  1172. fprintf(stderr, "node : %s col: %i", ((ID *) node->ob)->name, node->color);
  1173. itA = node->child;
  1174. while (itA) {
  1175. fprintf(stderr, "-- %s ", ((ID *) itA->node->ob)->name);
  1176. itA = itA->next;
  1177. }
  1178. fprintf(stderr, "\n");
  1179. node = node->next;
  1180. }
  1181. }
  1182. /* ************************ API *********************** */
  1183. /* mechanism to allow editors to be informed of depsgraph updates,
  1184. * to do their own updates based on changes... */
  1185. static void (*EditorsUpdateIDCb)(Main *bmain, ID *id) = NULL;
  1186. static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated) = NULL;
  1187. static void (*EditorsUpdateScenePreCb)(Main *bmain, Scene *scene, bool time) = NULL;
  1188. void DAG_editors_update_cb(void (*id_func)(Main *bmain, ID *id),
  1189. void (*scene_func)(Main *bmain, Scene *scene, int updated),
  1190. void (*scene_pre_func)(Main *bmain, Scene *scene, bool time))
  1191. {
  1192. if (DEG_depsgraph_use_legacy()) {
  1193. EditorsUpdateIDCb = id_func;
  1194. EditorsUpdateSceneCb = scene_func;
  1195. EditorsUpdateScenePreCb = scene_pre_func;
  1196. }
  1197. else {
  1198. /* New dependency graph. */
  1199. DEG_editors_set_update_cb(id_func, scene_func, scene_pre_func);
  1200. }
  1201. }
  1202. void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
  1203. {
  1204. if (DEG_depsgraph_use_legacy()) {
  1205. if (EditorsUpdateScenePreCb != NULL) {
  1206. EditorsUpdateScenePreCb(bmain, scene, time);
  1207. }
  1208. }
  1209. else {
  1210. DEG_editors_update_pre(bmain, scene, time);
  1211. }
  1212. }
  1213. static void dag_editors_id_update(Main *bmain, ID *id)
  1214. {
  1215. if (EditorsUpdateIDCb)
  1216. EditorsUpdateIDCb(bmain, id);
  1217. }
  1218. static void dag_editors_scene_update(Main *bmain, Scene *scene, int updated)
  1219. {
  1220. if (EditorsUpdateSceneCb)
  1221. EditorsUpdateSceneCb(bmain, scene, updated);
  1222. }
  1223. /* groups with objects in this scene need to be put in the right order as well */
  1224. static void scene_sort_groups(Main *bmain, Scene *sce)
  1225. {
  1226. Base *base;
  1227. Group *group;
  1228. GroupObject *go;
  1229. Object *ob;
  1230. /* test; are group objects all in this scene? */
  1231. for (ob = bmain->object.first; ob; ob = ob->id.next) {
  1232. ob->id.tag &= ~LIB_TAG_DOIT;
  1233. }
  1234. for (base = sce->base.first; base; base = base->next)
  1235. base->object->id.tag |= LIB_TAG_DOIT;
  1236. for (group = bmain->group.first; group; group = group->id.next) {
  1237. for (go = group->gobject.first; go; go = go->next) {
  1238. if ((go->ob->id.tag & LIB_TAG_DOIT) == 0)
  1239. break;
  1240. }
  1241. /* this group is entirely in this scene */
  1242. if (go == NULL) {
  1243. ListBase listb = {NULL, NULL};
  1244. for (go = group->gobject.first; go; go = go->next)
  1245. go->ob->id.newid = (ID *)go;
  1246. /* in order of sorted bases we reinsert group objects */
  1247. for (base = sce->base.first; base; base = base->next) {
  1248. if (base->object->id.newid) {
  1249. go = (GroupObject *)base->object->id.newid;
  1250. base->object->id.newid = NULL;
  1251. BLI_remlink(&group->gobject, go);
  1252. BLI_addtail(&listb, go);
  1253. }
  1254. }
  1255. /* copy the newly sorted listbase */
  1256. group->gobject = listb;
  1257. }
  1258. }
  1259. /* newid abused for GroupObject, cleanup. */
  1260. for (ob = bmain->object.first; ob; ob = ob->id.next) {
  1261. ob->id.newid = NULL;
  1262. }
  1263. }
  1264. static void dag_scene_tag_rebuild(Scene *sce)
  1265. {
  1266. if (sce->theDag) {
  1267. sce->theDag->need_update = true;
  1268. }
  1269. }
  1270. /* free the depency graph */
  1271. static void dag_scene_free(Scene *sce)
  1272. {
  1273. if (sce->theDag) {
  1274. free_forest(sce->theDag);
  1275. MEM_freeN(sce->theDag);
  1276. sce->theDag = NULL;
  1277. }
  1278. }
  1279. /* Check whether object data needs to be evaluated before it
  1280. * might be used by others.
  1281. *
  1282. * Means that mesh object needs to have proper derivedFinal,
  1283. * curves-typed objects are to have proper curve cache.
  1284. *
  1285. * Other objects or objects which are tagged for data update are
  1286. * not considered to be in need of evaluation.
  1287. */
  1288. static bool check_object_needs_evaluation(Object *object)
  1289. {
  1290. if (object->recalc & OB_RECALC_ALL) {
  1291. /* Object is tagged for update anyway, no need to re-tag it. */
  1292. return false;
  1293. }
  1294. if (object->type == OB_MESH) {
  1295. return object->derivedFinal == NULL;
  1296. }
  1297. else if (ELEM(object->type, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
  1298. return object->curve_cache == NULL;
  1299. }
  1300. return false;
  1301. }
  1302. /* Check whether object data is tagged for update. */
  1303. static bool check_object_tagged_for_update(Object *object)
  1304. {
  1305. if (object->recalc & OB_RECALC_ALL) {
  1306. return true;
  1307. }
  1308. if (ELEM(object->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
  1309. ID *data_id = object->data;
  1310. return (data_id->tag & (LIB_TAG_ID_RECALC_DATA | LIB_TAG_ID_RECALC)) != 0;
  1311. }
  1312. return false;
  1313. }
  1314. /* Flush changes from tagged objects in the scene to their
  1315. * dependencies which are not evaluated yet.
  1316. *
  1317. * This is needed to ensure all the dependencies are met
  1318. * before objects gets handled by object_handle_update(),
  1319. *
  1320. * This is needed when visible layers are changed or changing
  1321. * scene graph layout which involved usage of objects which
  1322. * aren't in the scene or weren't visible yet.
  1323. */
  1324. static void dag_invisible_dependencies_flush(Scene *scene)
  1325. {
  1326. DagNode *root_node = scene->theDag->DagNode.first, *node;
  1327. DagNodeQueue *queue;
  1328. for (node = root_node; node != NULL; node = node->next) {
  1329. node->color = DAG_WHITE;
  1330. }
  1331. queue = queue_create(DAGQUEUEALLOC);
  1332. for (node = root_node; node != NULL; node = node->next) {
  1333. if (node->color == DAG_WHITE) {
  1334. push_stack(queue, node);
  1335. node->color = DAG_GRAY;
  1336. while (queue->count) {
  1337. DagNode *current_node = get_top_node_queue(queue);
  1338. DagAdjList *itA;
  1339. bool skip = false;
  1340. for (itA = current_node->child; itA; itA = itA->next) {
  1341. if (itA->node->color == DAG_WHITE) {
  1342. itA->node->color = DAG_GRAY;
  1343. push_stack(queue, itA->node);
  1344. skip = true;
  1345. break;
  1346. }
  1347. }
  1348. if (!skip) {
  1349. current_node = pop_queue(queue);
  1350. if (current_node->type == ID_OB) {
  1351. Object *current_object = current_node->ob;
  1352. if (check_object_needs_evaluation(current_object)) {
  1353. for (itA = current_node->child; itA; itA = itA->next) {
  1354. if (itA->node->type == ID_OB) {
  1355. Object *object = itA->node->ob;
  1356. if (check_object_tagged_for_update(object)) {
  1357. current_object->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. node->color = DAG_BLACK;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. queue_delete(queue);
  1369. }
  1370. static void dag_invisible_dependencies_check_flush(Main *bmain, Scene *scene)
  1371. {
  1372. if (DAG_id_type_tagged(bmain, ID_OB) ||
  1373. DAG_id_type_tagged(bmain, ID_ME) || /* Mesh */
  1374. DAG_id_type_tagged(bmain, ID_CU) || /* Curve */
  1375. DAG_id_type_tagged(bmain, ID_MB) || /* MetaBall */
  1376. DAG_id_type_tagged(bmain, ID_LT)) /* Lattice */
  1377. {
  1378. dag_invisible_dependencies_flush(scene);
  1379. }
  1380. }
  1381. /* sort the base list on dependency order */
  1382. static void dag_scene_build(Main *bmain, Scene *sce)
  1383. {
  1384. DagNode *node, *rootnode;
  1385. DagNodeQueue *nqueue;
  1386. DagAdjList *itA;
  1387. int time;
  1388. int skip = 0;
  1389. ListBase tempbase;
  1390. Base *base;
  1391. BLI_listbase_clear(&tempbase);
  1392. build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA);
  1393. dag_check_cycle(sce->theDag);
  1394. nqueue = queue_create(DAGQUEUEALLOC);
  1395. for (node = sce->theDag->DagNode.first; node; node = node->next) {
  1396. node->color = DAG_WHITE;
  1397. }
  1398. time = 1;
  1399. rootnode = sce->theDag->DagNode.first;
  1400. rootnode->color = DAG_GRAY;
  1401. time++;
  1402. push_stack(nqueue, rootnode);
  1403. while (nqueue->count) {
  1404. skip = 0;
  1405. node = get_top_node_queue(nqueue);
  1406. itA = node->child;
  1407. while (itA != NULL) {
  1408. if (itA->node->color == DAG_WHITE) {
  1409. itA->node->DFS_dvtm = time;
  1410. itA->node->color = DAG_GRAY;
  1411. time++;
  1412. push_stack(nqueue, itA->node);
  1413. skip = 1;
  1414. break;
  1415. }
  1416. itA = itA->next;
  1417. }
  1418. if (!skip) {
  1419. if (node) {
  1420. node = pop_queue(nqueue);
  1421. if (node->ob == sce) /* we are done */
  1422. break;
  1423. node->color = DAG_BLACK;
  1424. time++;
  1425. base = sce->base.first;
  1426. while (base && base->object != node->ob)
  1427. base = base->next;
  1428. if (base) {
  1429. BLI_remlink(&sce->base, base);
  1430. BLI_addhead(&tempbase, base);
  1431. }
  1432. }
  1433. }
  1434. }
  1435. /* temporal correction for circular dependencies */
  1436. base = sce->base.first;
  1437. while (base) {
  1438. BLI_remlink(&sce->base, base);
  1439. BLI_addhead(&tempbase, base);
  1440. //if (G.debug & G_DEBUG)
  1441. printf("cyclic %s\n", base->object->id.name);
  1442. base = sce->base.first;
  1443. }
  1444. sce->base = tempbase;
  1445. queue_delete(nqueue);
  1446. /* all groups with objects in this scene gets resorted too */
  1447. scene_sort_groups(bmain, sce);
  1448. if (G.debug & G_DEBUG) {
  1449. printf("\nordered\n");
  1450. for (base = sce->base.first; base; base = base->next) {
  1451. printf(" %s\n", base->object->id.name);
  1452. }
  1453. }
  1454. /* Make sure that new dependencies which came from invisible layers
  1455. * are tagged for update (if they're needed for objects which were
  1456. * tagged for update).
  1457. */
  1458. dag_invisible_dependencies_check_flush(bmain, sce);
  1459. }
  1460. /* clear all dependency graphs */
  1461. void DAG_relations_tag_update(Main *bmain)
  1462. {
  1463. if (DEG_depsgraph_use_legacy()) {
  1464. Scene *sce;
  1465. for (sce = bmain->scene.first; sce; sce = sce->id.next) {
  1466. dag_scene_tag_rebuild(sce);
  1467. }
  1468. }
  1469. else {
  1470. /* New dependency graph. */
  1471. DEG_relations_tag_update(bmain);
  1472. }
  1473. }
  1474. /* rebuild dependency graph only for a given scene */
  1475. void DAG_scene_relations_rebuild(Main *bmain, Scene *sce)
  1476. {
  1477. if (DEG_depsgraph_use_legacy()) {
  1478. dag_scene_free(sce);
  1479. DAG_scene_relations_update(bmain, sce);
  1480. }
  1481. else {
  1482. /* New dependency graph. */
  1483. DEG_scene_relations_rebuild(bmain, sce);
  1484. }
  1485. }
  1486. /* create dependency graph if it was cleared or didn't exist yet */
  1487. void DAG_scene_relations_update(Main *bmain, Scene *sce)
  1488. {
  1489. if (DEG_depsgraph_use_legacy()) {
  1490. if (!sce->theDag || sce->theDag->need_update)
  1491. dag_scene_build(bmain, sce);
  1492. }
  1493. else {
  1494. /* New dependency graph. */
  1495. DEG_scene_relations_update(bmain, sce);
  1496. }
  1497. }
  1498. void DAG_scene_relations_validate(Main *bmain, Scene *sce)
  1499. {
  1500. if (!DEG_depsgraph_use_legacy()) {
  1501. DEG_debug_scene_relations_validate(bmain, sce);
  1502. }
  1503. }
  1504. void DAG_scene_free(Scene *sce)
  1505. {
  1506. if (DEG_depsgraph_use_legacy()) {
  1507. if (sce->theDag) {
  1508. free_forest(sce->theDag);
  1509. MEM_freeN(sce->theDag);
  1510. sce->theDag = NULL;
  1511. }
  1512. }
  1513. else {
  1514. if (sce->depsgraph) {
  1515. DEG_graph_free(sce->depsgraph);
  1516. sce->depsgraph = NULL;
  1517. }
  1518. }
  1519. }
  1520. static void lib_id_recalc_tag(Main *bmain, ID *id)
  1521. {
  1522. id->tag |= LIB_TAG_ID_RECALC;
  1523. DAG_id_type_tag(bmain, GS(id->name));
  1524. }
  1525. static void lib_id_recalc_data_tag(Main *bmain, ID *id)
  1526. {
  1527. id->tag |= LIB_TAG_ID_RECALC_DATA;
  1528. DAG_id_type_tag(bmain, GS(id->name));
  1529. }
  1530. /* node was checked to have lasttime != curtime and is if type ID_OB */
  1531. static void flush_update_node(Main *bmain, DagNode *node, unsigned int layer, int curtime)
  1532. {
  1533. DagAdjList *itA;
  1534. Object *ob, *obc;
  1535. int oldflag;
  1536. bool changed = false;
  1537. unsigned int all_layer;
  1538. node->lasttime = curtime;
  1539. ob = node->ob;
  1540. if (ob && (ob->recalc & OB_RECALC_ALL)) {
  1541. all_layer = node->scelay;
  1542. /* got an object node that changes, now check relations */
  1543. for (itA = node->child; itA; itA = itA->next) {
  1544. all_layer |= itA->lay;
  1545. /* the relationship is visible */
  1546. if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
  1547. if (itA->node->type == ID_OB) {
  1548. obc = itA->node->ob;
  1549. oldflag = obc->recalc;
  1550. /* got a ob->obc relation, now check if flag needs flush */
  1551. if (ob->recalc & OB_RECALC_OB) {
  1552. if (itA->type & DAG_RL_OB_OB) {
  1553. //printf("ob %s changes ob %s\n", ob->id.name, obc->id.name);
  1554. obc->recalc |= OB_RECALC_OB;
  1555. lib_id_recalc_tag(bmain, &obc->id);
  1556. }
  1557. if (itA->type & DAG_RL_OB_DATA) {
  1558. //printf("ob %s changes obdata %s\n", ob->id.name, obc->id.name);
  1559. obc->recalc |= OB_RECALC_DATA;
  1560. lib_id_recalc_data_tag(bmain, &obc->id);
  1561. }
  1562. }
  1563. if (ob->recalc & OB_RECALC_DATA) {
  1564. if (itA->type & DAG_RL_DATA_OB) {
  1565. //printf("obdata %s changes ob %s\n", ob->id.name, obc->id.name);
  1566. obc->recalc |= OB_RECALC_OB;
  1567. lib_id_recalc_tag(bmain, &obc->id);
  1568. }
  1569. if (itA->type & DAG_RL_DATA_DATA) {
  1570. //printf("obdata %s changes obdata %s\n", ob->id.name, obc->id.name);
  1571. obc->recalc |= OB_RECALC_DATA;
  1572. lib_id_recalc_data_tag(bmain, &obc->id);
  1573. }
  1574. }
  1575. if (oldflag != obc->recalc) changed = 1;
  1576. }
  1577. }
  1578. }
  1579. /* even nicer, we can clear recalc flags... */
  1580. if ((all_layer & layer) == 0) { // XXX && (ob != obedit)) {
  1581. /* but existing displaylists or derivedmesh should be freed */
  1582. if (ob->recalc & OB_RECALC_DATA)
  1583. BKE_object_free_derived_caches(ob);
  1584. ob->recalc &= ~OB_RECALC_ALL;
  1585. }
  1586. }
  1587. /* check case where child changes and parent forcing obdata to change */
  1588. /* should be done regardless if this ob has recalc set */
  1589. /* could merge this in with loop above...? (ton) */
  1590. for (itA = node->child; itA; itA = itA->next) {
  1591. /* the relationship is visible */
  1592. if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
  1593. if (itA->node->type == ID_OB) {
  1594. obc = itA->node->ob;
  1595. /* child moves */
  1596. if ((obc->recalc & OB_RECALC_ALL) == OB_RECALC_OB) {
  1597. /* parent has deforming info */
  1598. if (itA->type & (DAG_RL_OB_DATA | DAG_RL_DATA_DATA)) {
  1599. // printf("parent %s changes ob %s\n", ob->id.name, obc->id.name);
  1600. obc->recalc |= OB_RECALC_DATA;
  1601. lib_id_recalc_data_tag(bmain, &obc->id);
  1602. }
  1603. }
  1604. }
  1605. }
  1606. }
  1607. /* we only go deeper if node not checked or something changed */
  1608. for (itA = node->child; itA; itA = itA->next) {
  1609. if (changed || itA->node->lasttime != curtime)
  1610. flush_update_node(bmain, itA->node, layer, curtime);
  1611. }
  1612. }
  1613. /* node was checked to have lasttime != curtime, and is of type ID_OB */
  1614. static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime)
  1615. {
  1616. DagAdjList *itA;
  1617. node->lasttime = curtime;
  1618. node->lay = node->scelay;
  1619. for (itA = node->child; itA; itA = itA->next) {
  1620. if (itA->node->type == ID_OB) {
  1621. if (itA->node->lasttime != curtime) {
  1622. itA->lay = flush_layer_node(sce, itA->node, curtime); /* lay is only set once for each relation */
  1623. }
  1624. else {
  1625. itA->lay = itA->node->lay;
  1626. }
  1627. node->lay |= itA->lay;
  1628. }
  1629. }
  1630. return node->lay;
  1631. }
  1632. /* node was checked to have lasttime != curtime, and is of type ID_OB */
  1633. static void flush_pointcache_reset(Main *bmain, Scene *scene, DagNode *node,
  1634. int curtime, unsigned int lay, bool reset)
  1635. {
  1636. DagAdjList *itA;
  1637. Object *ob;
  1638. node->lasttime = curtime;
  1639. for (itA = node->child; itA; itA = itA->next) {
  1640. if (itA->node->type == ID_OB) {
  1641. if (itA->node->lasttime != curtime) {
  1642. ob = (Object *)(itA->node->ob);
  1643. if (reset || (ob->recalc & OB_RECALC_ALL)) {
  1644. if (BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH)) {
  1645. /* Don't tag nodes which are on invisible layer. */
  1646. if (itA->node->lay & lay) {
  1647. ob->recalc |= OB_RECALC_DATA;
  1648. lib_id_recalc_data_tag(bmain, &ob->id);
  1649. }
  1650. }
  1651. flush_pointcache_reset(bmain, scene, itA->node, curtime, lay, true);
  1652. }
  1653. else
  1654. flush_pointcache_reset(bmain, scene, itA->node, curtime, lay, false);
  1655. }
  1656. }
  1657. }
  1658. }
  1659. /* flush layer flags to dependencies */
  1660. static void dag_scene_flush_layers(Scene *sce, int lay)
  1661. {
  1662. DagNode *node, *firstnode;
  1663. DagAdjList *itA;
  1664. Base *base;
  1665. int lasttime;
  1666. firstnode = sce->theDag->DagNode.first; /* always scene node */
  1667. for (itA = firstnode->child; itA; itA = itA->next)
  1668. itA->lay = 0;
  1669. sce->theDag->time++; /* so we know which nodes were accessed */
  1670. lasttime = sce->theDag->time;
  1671. /* update layer flags in nodes */
  1672. for (base = sce->base.first; base; base = base->next) {
  1673. node = dag_get_node(sce->theDag, base->object);
  1674. node->scelay = base->object->lay;
  1675. }
  1676. /* ensure cameras are set as if they are on a visible layer, because
  1677. * they ared still used for rendering or setting the camera view
  1678. *
  1679. * XXX, this wont work for local view / unlocked camera's */
  1680. if (sce->camera) {
  1681. node = dag_get_node(sce->theDag, sce->camera);
  1682. node->scelay |= lay;
  1683. }
  1684. #ifdef DURIAN_CAMERA_SWITCH
  1685. {
  1686. TimeMarker *m;
  1687. for (m = sce->markers.first; m; m = m->next) {
  1688. if (m->camera) {
  1689. node = dag_get_node(sce->theDag, m->camera);
  1690. node->scelay |= lay;
  1691. }
  1692. }
  1693. }
  1694. #endif
  1695. /* flush layer nodes to dependencies */
  1696. for (itA = firstnode->child; itA; itA = itA->next)
  1697. if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
  1698. flush_layer_node(sce, itA->node, lasttime);
  1699. }
  1700. static void dag_tag_renderlayers(Scene *sce, unsigned int lay)
  1701. {
  1702. if (sce->nodetree) {
  1703. bNode *node;
  1704. Base *base;
  1705. unsigned int lay_changed = 0;
  1706. for (base = sce->base.first; base; base = base->next)
  1707. if (base->lay & lay)
  1708. if (base->object->recalc)
  1709. lay_changed |= base->lay;
  1710. for (node = sce->nodetree->nodes.first; node; node = node->next) {
  1711. if (node->id == (ID *)sce) {
  1712. SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
  1713. if (srl && (srl->lay & lay_changed))
  1714. nodeUpdate(sce->nodetree, node);
  1715. }
  1716. }
  1717. }
  1718. }
  1719. /* flushes all recalc flags in objects down the dependency tree */
  1720. void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const short time)
  1721. {
  1722. DagNode *firstnode;
  1723. DagAdjList *itA;
  1724. Object *ob;
  1725. int lasttime;
  1726. if (!DEG_depsgraph_use_legacy()) {
  1727. DEG_scene_flush_update(bmain, sce);
  1728. return;
  1729. }
  1730. if (sce->theDag == NULL || sce->theDag->need_update) {
  1731. printf("DAG zero... not allowed to happen!\n");
  1732. DAG_scene_relations_update(bmain, sce);
  1733. }
  1734. firstnode = sce->theDag->DagNode.first; /* always scene node */
  1735. /* first we flush the layer flags */
  1736. dag_scene_flush_layers(sce, lay);
  1737. /* then we use the relationships + layer info to flush update events */
  1738. sce->theDag->time++; /* so we know which nodes were accessed */
  1739. lasttime = sce->theDag->time;
  1740. for (itA = firstnode->child; itA; itA = itA->next)
  1741. if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
  1742. flush_update_node(bmain, itA->node, lay, lasttime);
  1743. /* if update is not due to time change, do pointcache clears */
  1744. if (!time) {
  1745. sce->theDag->time++; /* so we know which nodes were accessed */
  1746. lasttime = sce->theDag->time;
  1747. for (itA = firstnode->child; itA; itA = itA->next) {
  1748. if (itA->node->lasttime != lasttime && itA->node->type == ID_OB) {
  1749. ob = (Object *)(itA->node->ob);
  1750. if (ob->recalc & OB_RECALC_ALL) {
  1751. if (BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH)) {
  1752. ob->recalc |= OB_RECALC_DATA;
  1753. lib_id_recalc_data_tag(bmain, &ob->id);
  1754. }
  1755. flush_pointcache_reset(bmain, sce, itA->node, lasttime,
  1756. lay, true);
  1757. }
  1758. else
  1759. flush_pointcache_reset(bmain, sce, itA->node, lasttime,
  1760. lay, false);
  1761. }
  1762. }
  1763. }
  1764. dag_tag_renderlayers(sce, lay);
  1765. }
  1766. static bool modifier_nlastrips_use_time(ListBase *strips)
  1767. {
  1768. NlaStrip *strip;
  1769. if (strips) {
  1770. for (strip = strips->first; strip; strip = strip->next) {
  1771. if (modifier_nlastrips_use_time(&strip->strips)) {
  1772. return true;
  1773. }
  1774. else if (strip->act) {
  1775. FCurve *fcu;
  1776. for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) {
  1777. if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
  1778. return true;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. return false;
  1784. }
  1785. static bool object_modifiers_use_time(Object *ob)
  1786. {
  1787. ModifierData *md;
  1788. /* check if a modifier in modifier stack needs time input */
  1789. for (md = ob->modifiers.first; md; md = md->next) {
  1790. if (modifier_dependsOnTime(md))
  1791. return true;
  1792. }
  1793. /* check whether any modifiers are animated */
  1794. if (ob->adt) {
  1795. AnimData *adt = ob->adt;
  1796. NlaTrack *nlt;
  1797. FCurve *fcu;
  1798. /* action - check for F-Curves with paths containing 'modifiers[' */
  1799. if (adt->action) {
  1800. for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) {
  1801. if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
  1802. return true;
  1803. }
  1804. }
  1805. /* This here allows modifier properties to get driven and still update properly
  1806. *
  1807. * Workaround to get [#26764] (e.g. subsurf levels not updating when animated/driven)
  1808. * working, without the updating problems ([#28525] [#28690] [#28774] [#28777]) caused
  1809. * by the RNA updates cache introduced in r.38649
  1810. */
  1811. for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
  1812. if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
  1813. return true;
  1814. }
  1815. /* Also check NLA Strips... [#T45938] */
  1816. for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
  1817. if (modifier_nlastrips_use_time(&nlt->strips))
  1818. return true;
  1819. }
  1820. }
  1821. return false;
  1822. }
  1823. static short animdata_use_time(AnimData *adt)
  1824. {
  1825. NlaTrack *nlt;
  1826. if (adt == NULL) return 0;
  1827. /* check action - only if assigned, and it has anim curves */
  1828. if (adt->action && adt->action->curves.first)
  1829. return 1;
  1830. /* check NLA tracks + strips */
  1831. for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
  1832. if (nlt->strips.first)
  1833. return 1;
  1834. }
  1835. /* If we have drivers, more likely than not, on a frame change
  1836. * they'll need updating because their owner changed
  1837. *
  1838. * This is kindof a hack to get around a whole host of problems
  1839. * involving drivers using non-object datablock data (which the
  1840. * depsgraph currently has no way of representing let alone correctly
  1841. * dependency sort+tagging). By doing this, at least we ensure that
  1842. * some commonly attempted drivers (such as scene -> current frame;
  1843. * see "Driver updates fail" thread on Bf-committers dated July 2)
  1844. * will work correctly, and that other non-object datablocks will have
  1845. * their drivers update at least on frame change.
  1846. *
  1847. * -- Aligorith, July 4 2011
  1848. */
  1849. if (adt->drivers.first)
  1850. return 1;
  1851. return 0;
  1852. }
  1853. static void dag_object_time_update_flags(Main *bmain, Scene *scene, Object *ob)
  1854. {
  1855. if (ob->constraints.first) {
  1856. bConstraint *con;
  1857. for (con = ob->constraints.first; con; con = con->next) {
  1858. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
  1859. ListBase targets = {NULL, NULL};
  1860. bConstraintTarget *ct;
  1861. if (cti) {
  1862. /* special case for camera tracking -- it doesn't use targets to define relations */
  1863. if (ELEM(cti->type,
  1864. CONSTRAINT_TYPE_FOLLOWTRACK,
  1865. CONSTRAINT_TYPE_CAMERASOLVER,
  1866. CONSTRAINT_TYPE_OBJECTSOLVER,
  1867. CONSTRAINT_TYPE_TRANSFORM_CACHE))
  1868. {
  1869. ob->recalc |= OB_RECALC_OB;
  1870. }
  1871. else if (cti->get_constraint_targets) {
  1872. cti->get_constraint_targets(con, &targets);
  1873. for (ct = targets.first; ct; ct = ct->next) {
  1874. if (ct->tar) {
  1875. ob->recalc |= OB_RECALC_OB;
  1876. break;
  1877. }
  1878. }
  1879. if (cti->flush_constraint_targets)
  1880. cti->flush_constraint_targets(con, &targets, 1);
  1881. }
  1882. }
  1883. }
  1884. }
  1885. if (ob->parent) {
  1886. /* motion path or bone child */
  1887. if (ob->parent->type == OB_CURVE || ob->parent->type == OB_ARMATURE) ob->recalc |= OB_RECALC_OB;
  1888. }
  1889. #if 0 // XXX old animation system
  1890. if (ob->nlastrips.first) {
  1891. if (ob->dup_group) {
  1892. bActionStrip *strip;
  1893. /* this case is for groups with nla, whilst nla target has no action or nla */
  1894. for (strip = ob->nlastrips.first; strip; strip = strip->next) {
  1895. if (strip->object)
  1896. strip->object->recalc |= OB_RECALC_ALL;
  1897. }
  1898. }
  1899. }
  1900. #endif // XXX old animation system
  1901. if (animdata_use_time(ob->adt)) {
  1902. ob->recalc |= OB_RECALC_OB;
  1903. ob->adt->recalc |= ADT_RECALC_ANIM;
  1904. }
  1905. if ((ob->adt) && (ob->type == OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA;
  1906. if (object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA;
  1907. if ((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA;
  1908. // XXX: scene here may not be the scene that contains the rigidbody world affecting this!
  1909. if (ob->rigidbody_object && BKE_scene_check_rigidbody_active(scene))
  1910. ob->recalc |= OB_RECALC_OB;
  1911. {
  1912. AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
  1913. Mesh *me;
  1914. Curve *cu;
  1915. Lattice *lt;
  1916. switch (ob->type) {
  1917. case OB_MESH:
  1918. me = ob->data;
  1919. if (me->key) {
  1920. if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
  1921. ob->recalc |= OB_RECALC_DATA;
  1922. }
  1923. }
  1924. if (ob->particlesystem.first)
  1925. ob->recalc |= OB_RECALC_DATA;
  1926. break;
  1927. case OB_CURVE:
  1928. case OB_SURF:
  1929. cu = ob->data;
  1930. if (cu->key) {
  1931. if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
  1932. ob->recalc |= OB_RECALC_DATA;
  1933. }
  1934. }
  1935. break;
  1936. case OB_FONT:
  1937. cu = ob->data;
  1938. if (cu->str && cu->vfont) {
  1939. /* Can be in the curve-cache or the curve. */
  1940. if (ob->curve_cache && !BLI_listbase_is_empty(&ob->curve_cache->disp)) {
  1941. /* pass */
  1942. }
  1943. else if (!BLI_listbase_is_empty(&cu->nurb)) {
  1944. /* pass */
  1945. }
  1946. else {
  1947. ob->recalc |= OB_RECALC_DATA;
  1948. }
  1949. }
  1950. break;
  1951. case OB_LATTICE:
  1952. lt = ob->data;
  1953. if (lt->key) {
  1954. if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
  1955. ob->recalc |= OB_RECALC_DATA;
  1956. }
  1957. }
  1958. break;
  1959. case OB_MBALL:
  1960. if (ob->transflag & OB_DUPLI) ob->recalc |= OB_RECALC_DATA;
  1961. break;
  1962. case OB_EMPTY:
  1963. /* update animated images */
  1964. if (ob->empty_drawtype == OB_EMPTY_IMAGE && ob->data)
  1965. if (BKE_image_is_animated(ob->data))
  1966. ob->recalc |= OB_RECALC_DATA;
  1967. break;
  1968. }
  1969. if (animdata_use_time(adt)) {
  1970. ob->recalc |= OB_RECALC_DATA;
  1971. adt->recalc |= ADT_RECALC_ANIM;
  1972. }
  1973. if (ob->particlesystem.first) {
  1974. ParticleSystem *psys = ob->particlesystem.first;
  1975. for (; psys; psys = psys->next) {
  1976. if (psys_check_enabled(ob, psys, G.is_rendering)) {
  1977. ob->recalc |= OB_RECALC_DATA;
  1978. break;
  1979. }
  1980. }
  1981. }
  1982. }
  1983. if (ob->recalc & OB_RECALC_OB)
  1984. lib_id_recalc_tag(bmain, &ob->id);
  1985. if (ob->recalc & OB_RECALC_DATA)
  1986. lib_id_recalc_data_tag(bmain, &ob->id);
  1987. }
  1988. /* recursively update objects in groups, each group is done at most once */
  1989. static void dag_group_update_flags(Main *bmain, Scene *scene, Group *group, const bool do_time)
  1990. {
  1991. GroupObject *go;
  1992. if (group->id.tag & LIB_TAG_DOIT)
  1993. return;
  1994. group->id.tag |= LIB_TAG_DOIT;
  1995. for (go = group->gobject.first; go; go = go->next) {
  1996. if (do_time)
  1997. dag_object_time_update_flags(bmain, scene, go->ob);
  1998. if (go->ob->dup_group)
  1999. dag_group_update_flags(bmain, scene, go->ob->dup_group, do_time);
  2000. }
  2001. }
  2002. /* flag all objects that need recalc, for changes in time for example */
  2003. /* do_time: make this optional because undo resets objects to their animated locations without this */
  2004. void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const bool do_time, const bool do_invisible_flush)
  2005. {
  2006. Base *base;
  2007. Object *ob;
  2008. Group *group;
  2009. GroupObject *go;
  2010. Scene *sce_iter;
  2011. BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
  2012. /* set ob flags where animated systems are */
  2013. for (SETLOOPER(scene, sce_iter, base)) {
  2014. ob = base->object;
  2015. if (do_time) {
  2016. /* now if DagNode were part of base, the node->lay could be checked... */
  2017. /* we do all now, since the scene_flush checks layers and clears recalc flags even */
  2018. /* NOTE: "sce_iter" not "scene" so that rigidbodies in background scenes work
  2019. * (i.e. muting + rbw availability can be checked and tagged properly) [#33970]
  2020. */
  2021. dag_object_time_update_flags(bmain, sce_iter, ob);
  2022. }
  2023. /* recursively tag groups with LIB_TAG_DOIT, and update flags for objects */
  2024. if (ob->dup_group)
  2025. dag_group_update_flags(bmain, scene, ob->dup_group, do_time);
  2026. }
  2027. for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
  2028. DAG_scene_flush_update(bmain, sce_iter, lay, 1);
  2029. if (do_time) {
  2030. /* test: set time flag, to disable baked systems to update */
  2031. for (SETLOOPER(scene, sce_iter, base)) {
  2032. ob = base->object;
  2033. if (ob->recalc & OB_RECALC_ALL)
  2034. ob->recalc |= OB_RECALC_TIME;
  2035. }
  2036. /* hrmf... an exception to look at once, for invisible camera object we do it over */
  2037. if (scene->camera)
  2038. dag_object_time_update_flags(bmain, scene, scene->camera);
  2039. }
  2040. /* and store the info in groupobject */
  2041. for (group = bmain->group.first; group; group = group->id.next) {
  2042. if (group->id.tag & LIB_TAG_DOIT) {
  2043. for (go = group->gobject.first; go; go = go->next) {
  2044. go->recalc = go->ob->recalc;
  2045. // printf("ob %s recalc %d\n", go->ob->id.name, go->recalc);
  2046. }
  2047. group->id.tag &= ~LIB_TAG_DOIT;
  2048. }
  2049. }
  2050. if (do_invisible_flush) {
  2051. dag_invisible_dependencies_check_flush(bmain, scene);
  2052. }
  2053. }
  2054. /* struct returned by DagSceneLayer */
  2055. typedef struct DagSceneLayer {
  2056. struct DagSceneLayer *next, *prev;
  2057. Scene *scene;
  2058. unsigned int layer;
  2059. } DagSceneLayer;
  2060. /* returns visible scenes with valid DAG */
  2061. static void dag_current_scene_layers(Main *bmain, ListBase *lb)
  2062. {
  2063. wmWindowManager *wm;
  2064. wmWindow *win;
  2065. BLI_listbase_clear(lb);
  2066. /* if we have a windowmanager, look into windows */
  2067. if ((wm = bmain->wm.first)) {
  2068. BKE_main_id_flag_listbase(&bmain->scene, LIB_TAG_DOIT, 1);
  2069. for (win = wm->windows.first; win; win = win->next) {
  2070. if (win->screen && win->screen->scene->theDag) {
  2071. Scene *scene = win->screen->scene;
  2072. DagSceneLayer *dsl;
  2073. if (scene->id.tag & LIB_TAG_DOIT) {
  2074. dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
  2075. BLI_addtail(lb, dsl);
  2076. dsl->scene = scene;
  2077. dsl->layer = BKE_screen_visible_layers(win->screen, scene);
  2078. scene->id.tag &= ~LIB_TAG_DOIT;
  2079. }
  2080. else {
  2081. /* It is possible that multiple windows shares the same scene
  2082. * and have different layers visible.
  2083. *
  2084. * Here we deal with such cases by squashing layers bits from
  2085. * multiple windoew to the DagSceneLayer.
  2086. *
  2087. * TODO(sergey): Such a lookup could be optimized perhaps,
  2088. * however should be fine for now since we usually have only
  2089. * few open windows.
  2090. */
  2091. for (dsl = lb->first; dsl; dsl = dsl->next) {
  2092. if (dsl->scene == scene) {
  2093. dsl->layer |= BKE_screen_visible_layers(win->screen, scene);
  2094. break;
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. else {
  2102. /* if not, use the first sce */
  2103. DagSceneLayer *dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
  2104. BLI_addtail(lb, dsl);
  2105. dsl->scene = bmain->scene.first;
  2106. dsl->layer = dsl->scene->lay;
  2107. /* XXX for background mode, we should get the scene
  2108. * from somewhere, for the -S option, but it's in
  2109. * the context, how to get it here? */
  2110. }
  2111. }
  2112. static void dag_group_on_visible_update(Scene *scene, Group *group)
  2113. {
  2114. GroupObject *go;
  2115. if (group->id.tag & LIB_TAG_DOIT)
  2116. return;
  2117. group->id.tag |= LIB_TAG_DOIT;
  2118. for (go = group->gobject.first; go; go = go->next) {
  2119. if (ELEM(go->ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
  2120. go->ob->recalc |= OB_RECALC_DATA;
  2121. go->ob->id.tag |= LIB_TAG_DOIT;
  2122. lib_id_recalc_tag(G.main, &go->ob->id);
  2123. }
  2124. if (go->ob->proxy_from) {
  2125. go->ob->recalc |= OB_RECALC_OB;
  2126. go->ob->id.tag |= LIB_TAG_DOIT;
  2127. lib_id_recalc_tag(G.main, &go->ob->id);
  2128. }
  2129. if (go->ob->dup_group)
  2130. dag_group_on_visible_update(scene, go->ob->dup_group);
  2131. }
  2132. }
  2133. void DAG_on_visible_update(Main *bmain, const bool do_time)
  2134. {
  2135. ListBase listbase;
  2136. DagSceneLayer *dsl;
  2137. if (!DEG_depsgraph_use_legacy()) {
  2138. /* Inform new dependnecy graphs about visibility changes. */
  2139. DEG_on_visible_update(bmain, do_time);
  2140. return;
  2141. }
  2142. /* get list of visible scenes and layers */
  2143. dag_current_scene_layers(bmain, &listbase);
  2144. for (dsl = listbase.first; dsl; dsl = dsl->next) {
  2145. Scene *scene = dsl->scene;
  2146. Scene *sce_iter;
  2147. Base *base;
  2148. Object *ob;
  2149. DagNode *node;
  2150. unsigned int lay = dsl->layer, oblay;
  2151. /* derivedmeshes and displists are not saved to file so need to be
  2152. * remade, tag them so they get remade in the scene update loop,
  2153. * note armature poses or object matrices are preserved and do not
  2154. * require updates, so we skip those */
  2155. for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
  2156. dag_scene_flush_layers(sce_iter, lay);
  2157. BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
  2158. for (SETLOOPER(scene, sce_iter, base)) {
  2159. ob = base->object;
  2160. node = (sce_iter->theDag) ? dag_get_node(sce_iter->theDag, ob) : NULL;
  2161. oblay = (node) ? node->lay : ob->lay;
  2162. if ((oblay & lay) & ~scene->lay_updated) {
  2163. /* TODO(sergey): Why do we need armature here now but didn't need before? */
  2164. if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE, OB_ARMATURE)) {
  2165. ob->recalc |= OB_RECALC_DATA;
  2166. lib_id_recalc_tag(bmain, &ob->id);
  2167. }
  2168. /* This should not be needed here, but in some cases, like after a redo, we can end up with
  2169. * a wrong final matrix (see T42472).
  2170. * Quoting Sergey, this comes from BKE_object_handle_update_ex, which is calling
  2171. * BKE_object_where_is_calc_ex when it shouldn't, but that issue is not easily fixable.
  2172. */
  2173. else {
  2174. ob->recalc |= OB_RECALC_OB;
  2175. lib_id_recalc_tag(bmain, &ob->id);
  2176. }
  2177. if (ob->proxy && (ob->proxy_group == NULL)) {
  2178. ob->proxy->recalc |= OB_RECALC_DATA;
  2179. lib_id_recalc_tag(bmain, &ob->id);
  2180. }
  2181. if (ob->dup_group)
  2182. dag_group_on_visible_update(scene, ob->dup_group);
  2183. }
  2184. }
  2185. BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
  2186. /* now tag update flags, to ensure deformers get calculated on redraw */
  2187. DAG_scene_update_flags(bmain, scene, lay, do_time, true);
  2188. scene->lay_updated |= lay;
  2189. }
  2190. BLI_freelistN(&listbase);
  2191. /* hack to get objects updating on layer changes */
  2192. DAG_id_type_tag(bmain, ID_OB);
  2193. /* so masks update on load */
  2194. if (bmain->mask.first) {
  2195. Mask *mask;
  2196. for (mask = bmain->mask.first; mask; mask = mask->id.next) {
  2197. DAG_id_tag_update(&mask->id, 0);
  2198. }
  2199. }
  2200. }
  2201. static void dag_id_flush_update__isDependentTexture(
  2202. void *userData, Object *UNUSED(ob), ID **idpoin, int UNUSED(cb_flag))
  2203. {
  2204. struct { ID *id; bool is_dependent; } *data = userData;
  2205. if (*idpoin && GS((*idpoin)->name) == ID_TE) {
  2206. if (data->id == (*idpoin))
  2207. data->is_dependent = 1;
  2208. }
  2209. }
  2210. static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
  2211. {
  2212. Object *obt, *ob = NULL;
  2213. short idtype;
  2214. /* here we flush a few things before actual scene wide flush, mostly
  2215. * due to only objects and not other datablocks being in the depsgraph */
  2216. /* set flags & pointcache for object */
  2217. if (GS(id->name) == ID_OB) {
  2218. ob = (Object *)id;
  2219. BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
  2220. /* So if someone tagged object recalc directly,
  2221. * id_tag_update bit-field stays relevant
  2222. */
  2223. if (ob->recalc & OB_RECALC_ALL) {
  2224. DAG_id_type_tag(bmain, GS(id->name));
  2225. }
  2226. if (ob->recalc & OB_RECALC_DATA) {
  2227. /* all users of this ob->data should be checked */
  2228. id = ob->data;
  2229. /* no point in trying in this cases */
  2230. if (id && id->us <= 1) {
  2231. dag_editors_id_update(bmain, id);
  2232. id = NULL;
  2233. }
  2234. }
  2235. }
  2236. /* set flags & pointcache for object data */
  2237. if (id) {
  2238. idtype = GS(id->name);
  2239. if (OB_DATA_SUPPORT_ID(idtype)) {
  2240. for (obt = bmain->object.first; obt; obt = obt->id.next) {
  2241. if (!(ob && obt == ob) && obt->data == id) {
  2242. obt->recalc |= OB_RECALC_DATA;
  2243. lib_id_recalc_data_tag(bmain, &obt->id);
  2244. BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
  2245. }
  2246. }
  2247. }
  2248. else if (idtype == ID_VF) {
  2249. for (obt = bmain->object.first; obt; obt = obt->id.next) {
  2250. if (obt->type == OB_FONT) {
  2251. Curve *cu = obt->data;
  2252. if (ELEM((struct VFont *)id, CURVE_VFONT_ANY(cu))) {
  2253. obt->recalc |= OB_RECALC_DATA;
  2254. lib_id_recalc_data_tag(bmain, &obt->id);
  2255. }
  2256. }
  2257. }
  2258. }
  2259. /* set flags based on textures - can influence depgraph via modifiers */
  2260. if (idtype == ID_TE) {
  2261. for (obt = bmain->object.first; obt; obt = obt->id.next) {
  2262. struct { ID *id; bool is_dependent; } data;
  2263. data.id = id;
  2264. data.is_dependent = 0;
  2265. modifiers_foreachIDLink(obt, dag_id_flush_update__isDependentTexture, &data);
  2266. if (data.is_dependent) {
  2267. obt->recalc |= OB_RECALC_DATA;
  2268. lib_id_recalc_data_tag(bmain, &obt->id);
  2269. }
  2270. /* particle settings can use the texture as well */
  2271. if (obt->particlesystem.first) {
  2272. ParticleSystem *psys = obt->particlesystem.first;
  2273. MTex **mtexp, *mtex;
  2274. int a;
  2275. for (; psys; psys = psys->next) {
  2276. mtexp = psys->part->mtex;
  2277. for (a = 0; a < MAX_MTEX; a++, mtexp++) {
  2278. mtex = *mtexp;
  2279. if (mtex && mtex->tex == (Tex *)id) {
  2280. obt->recalc |= OB_RECALC_DATA;
  2281. lib_id_recalc_data_tag(bmain, &obt->id);
  2282. if (mtex->mapto & PAMAP_INIT)
  2283. psys->recalc |= PSYS_RECALC_RESET;
  2284. if (mtex->mapto & PAMAP_CHILD)
  2285. psys->recalc |= PSYS_RECALC_CHILD;
  2286. BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. /* set flags based on ShapeKey */
  2294. if (idtype == ID_KE) {
  2295. for (obt = bmain->object.first; obt; obt = obt->id.next) {
  2296. Key *key = BKE_key_from_object(obt);
  2297. if (!(ob && obt == ob) && ((ID *)key == id)) {
  2298. obt->flag |= (OB_RECALC_OB | OB_RECALC_DATA);
  2299. lib_id_recalc_tag(bmain, &obt->id);
  2300. lib_id_recalc_data_tag(bmain, &obt->id);
  2301. BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
  2302. }
  2303. }
  2304. }
  2305. /* set flags based on particle settings */
  2306. if (idtype == ID_PA) {
  2307. ParticleSystem *psys;
  2308. for (obt = bmain->object.first; obt; obt = obt->id.next)
  2309. for (psys = obt->particlesystem.first; psys; psys = psys->next)
  2310. if (&psys->part->id == id)
  2311. BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
  2312. }
  2313. if (ELEM(idtype, ID_MA, ID_TE)) {
  2314. obt = sce->basact ? sce->basact->object : NULL;
  2315. if (obt && obt->mode & OB_MODE_TEXTURE_PAINT) {
  2316. BKE_texpaint_slots_refresh_object(sce, obt);
  2317. BKE_paint_proj_mesh_data_check(sce, obt, NULL, NULL, NULL, NULL);
  2318. GPU_drawobject_free(obt->derivedFinal);
  2319. }
  2320. }
  2321. if (idtype == ID_MC) {
  2322. MovieClip *clip = (MovieClip *) id;
  2323. BKE_tracking_dopesheet_tag_update(&clip->tracking);
  2324. for (obt = bmain->object.first; obt; obt = obt->id.next) {
  2325. bConstraint *con;
  2326. for (con = obt->constraints.first; con; con = con->next) {
  2327. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
  2328. if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER,
  2329. CONSTRAINT_TYPE_OBJECTSOLVER))
  2330. {
  2331. obt->recalc |= OB_RECALC_OB;
  2332. lib_id_recalc_tag(bmain, &obt->id);
  2333. break;
  2334. }
  2335. }
  2336. }
  2337. if (sce->nodetree) {
  2338. bNode *node;
  2339. for (node = sce->nodetree->nodes.first; node; node = node->next) {
  2340. if (node->id == id) {
  2341. nodeUpdate(sce->nodetree, node);
  2342. }
  2343. }
  2344. }
  2345. }
  2346. /* Not pretty to iterate all the nodes here, but it's as good as it
  2347. * could be with the current depsgraph design/
  2348. */
  2349. if (idtype == ID_IM) {
  2350. FOREACH_NODETREE(bmain, ntree, parent_id) {
  2351. if (ntree->type == NTREE_SHADER) {
  2352. bNode *node;
  2353. for (node = ntree->nodes.first; node; node = node->next) {
  2354. if (node->id == id) {
  2355. lib_id_recalc_tag(bmain, &ntree->id);
  2356. break;
  2357. }
  2358. }
  2359. }
  2360. } FOREACH_NODETREE_END
  2361. }
  2362. if (idtype == ID_MSK) {
  2363. if (sce->nodetree) {
  2364. bNode *node;
  2365. for (node = sce->nodetree->nodes.first; node; node = node->next) {
  2366. if (node->id == id) {
  2367. nodeUpdate(sce->nodetree, node);
  2368. }
  2369. }
  2370. }
  2371. }
  2372. /* camera's matrix is used to orient reconstructed stuff,
  2373. * so it should happen tracking-related constraints recalculation
  2374. * when camera is changing (sergey) */
  2375. if (sce->camera && &sce->camera->id == id) {
  2376. MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, true);
  2377. if (clip)
  2378. dag_id_flush_update(bmain, sce, &clip->id);
  2379. }
  2380. /* update editors */
  2381. dag_editors_id_update(bmain, id);
  2382. }
  2383. }
  2384. void DAG_ids_flush_tagged(Main *bmain)
  2385. {
  2386. ListBase listbase;
  2387. DagSceneLayer *dsl;
  2388. ListBase *lbarray[MAX_LIBARRAY];
  2389. int a;
  2390. bool do_flush = false;
  2391. if (!DEG_depsgraph_use_legacy()) {
  2392. DEG_ids_flush_tagged(bmain);
  2393. return;
  2394. }
  2395. /* get list of visible scenes and layers */
  2396. dag_current_scene_layers(bmain, &listbase);
  2397. if (BLI_listbase_is_empty(&listbase))
  2398. return;
  2399. /* loop over all ID types */
  2400. a = set_listbasepointers(bmain, lbarray);
  2401. while (a--) {
  2402. ListBase *lb = lbarray[a];
  2403. ID *id = lb->first;
  2404. if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
  2405. for (; id; id = id->next) {
  2406. if (id->tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA)) {
  2407. for (dsl = listbase.first; dsl; dsl = dsl->next)
  2408. dag_id_flush_update(bmain, dsl->scene, id);
  2409. do_flush = true;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. /* flush changes to other objects */
  2415. if (do_flush) {
  2416. for (dsl = listbase.first; dsl; dsl = dsl->next)
  2417. DAG_scene_flush_update(bmain, dsl->scene, dsl->layer, 0);
  2418. }
  2419. BLI_freelistN(&listbase);
  2420. }
  2421. void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
  2422. {
  2423. ListBase *lbarray[MAX_LIBARRAY];
  2424. int a;
  2425. bool updated = false;
  2426. if (!DEG_depsgraph_use_legacy()) {
  2427. DEG_ids_check_recalc(bmain, scene, time);
  2428. return;
  2429. }
  2430. /* loop over all ID types */
  2431. a = set_listbasepointers(bmain, lbarray);
  2432. while (a--) {
  2433. ListBase *lb = lbarray[a];
  2434. ID *id = lb->first;
  2435. if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
  2436. updated = true;
  2437. break;
  2438. }
  2439. }
  2440. dag_editors_scene_update(bmain, scene, (updated || time));
  2441. }
  2442. /* It is possible that scene_update_post and frame_update_post handlers
  2443. * will modify objects. The issue is that DAG_ids_clear_recalc is called
  2444. * just after callbacks, which leaves objects with recalc flags but no
  2445. * corresponding bit in ID recalc bitfield. This leads to some kind of
  2446. * regression when using ID type tag fields to check whether there objects
  2447. * to be updated internally comparing threaded DAG with legacy one.
  2448. *
  2449. * For now let's have a workaround which will preserve tag for ID_OB
  2450. * if there're objects with OB_RECALC_ALL bits. This keeps behavior
  2451. * unchanged comparing with 2.69 release.
  2452. *
  2453. * TODO(sergey): Need to get rid of such a workaround.
  2454. *
  2455. * - sergey -
  2456. */
  2457. #define POST_UPDATE_HANDLER_WORKAROUND
  2458. void DAG_ids_clear_recalc(Main *bmain)
  2459. {
  2460. ListBase *lbarray[MAX_LIBARRAY];
  2461. bNodeTree *ntree;
  2462. int a;
  2463. #ifdef POST_UPDATE_HANDLER_WORKAROUND
  2464. bool have_updated_objects = false;
  2465. if (DAG_id_type_tagged(bmain, ID_OB)) {
  2466. ListBase listbase;
  2467. DagSceneLayer *dsl;
  2468. /* We need to check all visible scenes, otherwise resetting
  2469. * OB_ID changed flag will only work fine for first scene of
  2470. * multiple visible and all the rest will skip update.
  2471. *
  2472. * This could also lead to wrong behavior scene update handlers
  2473. * because of missing ID datablock changed flags.
  2474. *
  2475. * This is a bit of a bummer to allocate list here, but likely
  2476. * it wouldn't become too much bad because it only happens when
  2477. * objects were actually changed.
  2478. */
  2479. dag_current_scene_layers(bmain, &listbase);
  2480. for (dsl = listbase.first; dsl; dsl = dsl->next) {
  2481. Scene *scene = dsl->scene;
  2482. DagNode *node;
  2483. for (node = scene->theDag->DagNode.first;
  2484. node != NULL && have_updated_objects == false;
  2485. node = node->next)
  2486. {
  2487. if (node->type == ID_OB) {
  2488. Object *object = (Object *) node->ob;
  2489. if (object->recalc & OB_RECALC_ALL) {
  2490. have_updated_objects = true;
  2491. break;
  2492. }
  2493. }
  2494. }
  2495. }
  2496. BLI_freelistN(&listbase);
  2497. }
  2498. #endif
  2499. /* loop over all ID types */
  2500. a = set_listbasepointers(bmain, lbarray);
  2501. while (a--) {
  2502. ListBase *lb = lbarray[a];
  2503. ID *id = lb->first;
  2504. if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
  2505. for (; id; id = id->next) {
  2506. if (id->tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA))
  2507. id->tag &= ~(LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA);
  2508. /* some ID's contain semi-datablock nodetree */
  2509. ntree = ntreeFromID(id);
  2510. if (ntree && (ntree->id.tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA)))
  2511. ntree->id.tag &= ~(LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA);
  2512. }
  2513. }
  2514. }
  2515. memset(bmain->id_tag_update, 0, sizeof(bmain->id_tag_update));
  2516. #ifdef POST_UPDATE_HANDLER_WORKAROUND
  2517. if (have_updated_objects) {
  2518. DAG_id_type_tag(bmain, ID_OB);
  2519. }
  2520. #endif
  2521. }
  2522. void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
  2523. {
  2524. if (!DEG_depsgraph_use_legacy()) {
  2525. DEG_id_tag_update_ex(bmain, id, flag);
  2526. return;
  2527. }
  2528. if (id == NULL) return;
  2529. if (G.debug & G_DEBUG_DEPSGRAPH) {
  2530. printf("%s: id=%s flag=%d\n", __func__, id->name, flag);
  2531. }
  2532. /* tag ID for update */
  2533. if (flag) {
  2534. if (flag & OB_RECALC_OB)
  2535. lib_id_recalc_tag(bmain, id);
  2536. if (flag & (OB_RECALC_DATA | PSYS_RECALC))
  2537. lib_id_recalc_data_tag(bmain, id);
  2538. }
  2539. else
  2540. lib_id_recalc_tag(bmain, id);
  2541. /* flag is for objects and particle systems */
  2542. if (flag) {
  2543. Object *ob;
  2544. short idtype = GS(id->name);
  2545. if (idtype == ID_OB) {
  2546. /* only quick tag */
  2547. ob = (Object *)id;
  2548. ob->recalc |= (flag & OB_RECALC_ALL);
  2549. }
  2550. else if (idtype == ID_PA) {
  2551. ParticleSystem *psys;
  2552. /* this is weak still, should be done delayed as well */
  2553. for (ob = bmain->object.first; ob; ob = ob->id.next) {
  2554. for (psys = ob->particlesystem.first; psys; psys = psys->next) {
  2555. if (&psys->part->id == id) {
  2556. ob->recalc |= (flag & OB_RECALC_ALL);
  2557. psys->recalc |= (flag & PSYS_RECALC);
  2558. lib_id_recalc_tag(bmain, &ob->id);
  2559. lib_id_recalc_data_tag(bmain, &ob->id);
  2560. }
  2561. }
  2562. }
  2563. }
  2564. else {
  2565. /* disable because this is called on various ID types automatically.
  2566. * where printing warning is not useful. for now just ignore */
  2567. /* BLI_assert(!"invalid flag for this 'idtype'"); */
  2568. }
  2569. }
  2570. else if (GS(id->name) == ID_CF) {
  2571. for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
  2572. ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache);
  2573. if (md) {
  2574. MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
  2575. if (mcmd->cache_file && (&mcmd->cache_file->id == id)) {
  2576. ob->recalc |= OB_RECALC_ALL;
  2577. continue;
  2578. }
  2579. }
  2580. for (bConstraint *con = ob->constraints.first; con; con = con->next) {
  2581. if (con->type != CONSTRAINT_TYPE_TRANSFORM_CACHE) {
  2582. continue;
  2583. }
  2584. bTransformCacheConstraint *data = con->data;
  2585. if (data->cache_file && (&data->cache_file->id == id)) {
  2586. ob->recalc |= OB_RECALC_ALL;
  2587. break;
  2588. }
  2589. }
  2590. }
  2591. }
  2592. }
  2593. void DAG_id_tag_update(ID *id, short flag)
  2594. {
  2595. DAG_id_tag_update_ex(G.main, id, flag);
  2596. }
  2597. void DAG_id_type_tag(Main *bmain, short idtype)
  2598. {
  2599. if (idtype == ID_NT) {
  2600. /* stupid workaround so parent datablocks of nested nodetree get looped
  2601. * over when we loop over tagged datablock types */
  2602. DAG_id_type_tag(bmain, ID_MA);
  2603. DAG_id_type_tag(bmain, ID_TE);
  2604. DAG_id_type_tag(bmain, ID_LA);
  2605. DAG_id_type_tag(bmain, ID_WO);
  2606. DAG_id_type_tag(bmain, ID_SCE);
  2607. }
  2608. atomic_fetch_and_or_uint8((uint8_t *)&bmain->id_tag_update[BKE_idcode_to_index(idtype)], 1);
  2609. }
  2610. int DAG_id_type_tagged(Main *bmain, short idtype)
  2611. {
  2612. return bmain->id_tag_update[BKE_idcode_to_index(idtype)];
  2613. }
  2614. #if 0 // UNUSED
  2615. /* recursively descends tree, each node only checked once */
  2616. /* node is checked to be of type object */
  2617. static int parent_check_node(DagNode *node, int curtime)
  2618. {
  2619. DagAdjList *itA;
  2620. node->lasttime = curtime;
  2621. if (node->color == DAG_GRAY)
  2622. return DAG_GRAY;
  2623. for (itA = node->child; itA; itA = itA->next) {
  2624. if (itA->node->type == ID_OB) {
  2625. if (itA->node->color == DAG_GRAY)
  2626. return DAG_GRAY;
  2627. /* descend if not done */
  2628. if (itA->node->lasttime != curtime) {
  2629. itA->node->color = parent_check_node(itA->node, curtime);
  2630. if (itA->node->color == DAG_GRAY)
  2631. return DAG_GRAY;
  2632. }
  2633. }
  2634. }
  2635. return DAG_WHITE;
  2636. }
  2637. #endif
  2638. /* ******************* DAG FOR ARMATURE POSE ***************** */
  2639. /* we assume its an armature with pose */
  2640. void DAG_pose_sort(Object *ob)
  2641. {
  2642. bPose *pose = ob->pose;
  2643. bPoseChannel *pchan;
  2644. bConstraint *con;
  2645. DagNode *node;
  2646. DagNode *node2, *node3;
  2647. DagNode *rootnode;
  2648. DagForest *dag;
  2649. DagNodeQueue *nqueue;
  2650. DagAdjList *itA;
  2651. ListBase tempbase;
  2652. int skip = 0;
  2653. dag = dag_init();
  2654. dag->ugly_hack_sorry = false; /* no ID structs */
  2655. rootnode = dag_add_node(dag, NULL); /* node->ob becomes NULL */
  2656. /* we add the hierarchy and the constraints */
  2657. for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
  2658. int addtoroot = 1;
  2659. node = dag_get_node(dag, pchan);
  2660. if (pchan->parent) {
  2661. node2 = dag_get_node(dag, pchan->parent);
  2662. dag_add_relation(dag, node2, node, 0, "Parent Relation");
  2663. addtoroot = 0;
  2664. }
  2665. for (con = pchan->constraints.first; con; con = con->next) {
  2666. const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
  2667. ListBase targets = {NULL, NULL};
  2668. bConstraintTarget *ct;
  2669. if (cti && cti->get_constraint_targets) {
  2670. cti->get_constraint_targets(con, &targets);
  2671. for (ct = targets.first; ct; ct = ct->next) {
  2672. if (ct->tar == ob && ct->subtarget[0]) {
  2673. bPoseChannel *target = BKE_pose_channel_find_name(ob->pose, ct->subtarget);
  2674. if (target) {
  2675. node2 = dag_get_node(dag, target);
  2676. dag_add_relation(dag, node2, node, 0, "Pose Constraint");
  2677. if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
  2678. bKinematicConstraint *data = (bKinematicConstraint *)con->data;
  2679. bPoseChannel *parchan;
  2680. int segcount = 0;
  2681. /* exclude tip from chain? */
  2682. if (!(data->flag & CONSTRAINT_IK_TIP))
  2683. parchan = pchan->parent;
  2684. else
  2685. parchan = pchan;
  2686. /* Walk to the chain's root */
  2687. while (parchan) {
  2688. node3 = dag_get_node(dag, parchan);
  2689. dag_add_relation(dag, node2, node3, 0, "IK Constraint");
  2690. segcount++;
  2691. if (segcount == data->rootbone || segcount > 255) break; /* 255 is weak */
  2692. parchan = parchan->parent;
  2693. }
  2694. }
  2695. }
  2696. }
  2697. }
  2698. if (cti->flush_constraint_targets)
  2699. cti->flush_constraint_targets(con, &targets, 1);
  2700. }
  2701. }
  2702. if (addtoroot == 1) {
  2703. dag_add_relation(dag, rootnode, node, 0, "Root Bone Relation");
  2704. }
  2705. }
  2706. dag_check_cycle(dag);
  2707. /* now we try to sort... */
  2708. BLI_listbase_clear(&tempbase);
  2709. nqueue = queue_create(DAGQUEUEALLOC);
  2710. /* tag nodes unchecked */
  2711. for (node = dag->DagNode.first; node; node = node->next)
  2712. node->color = DAG_WHITE;
  2713. rootnode->color = DAG_GRAY;
  2714. push_stack(nqueue, rootnode);
  2715. while (nqueue->count) {
  2716. skip = 0;
  2717. node = get_top_node_queue(nqueue);
  2718. itA = node->child;
  2719. while (itA != NULL) {
  2720. if (itA->node->color == DAG_WHITE) {
  2721. itA->node->color = DAG_GRAY;
  2722. push_stack(nqueue, itA->node);
  2723. skip = 1;
  2724. break;
  2725. }
  2726. itA = itA->next;
  2727. }
  2728. if (!skip) {
  2729. if (node) {
  2730. node = pop_queue(nqueue);
  2731. if (node->ob == NULL) /* we are done */
  2732. break;
  2733. node->color = DAG_BLACK;
  2734. /* put node in new list */
  2735. BLI_remlink(&pose->chanbase, node->ob);
  2736. BLI_addhead(&tempbase, node->ob);
  2737. }
  2738. }
  2739. }
  2740. /* temporal correction for circular dependencies */
  2741. while (pose->chanbase.first) {
  2742. pchan = pose->chanbase.first;
  2743. BLI_remlink(&pose->chanbase, pchan);
  2744. BLI_addhead(&tempbase, pchan);
  2745. printf("cyclic %s\n", pchan->name);
  2746. }
  2747. pose->chanbase = tempbase;
  2748. queue_delete(nqueue);
  2749. // printf("\nordered\n");
  2750. // for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
  2751. // printf(" %s\n", pchan->name);
  2752. // }
  2753. free_forest(dag);
  2754. MEM_freeN(dag);
  2755. }
  2756. /* ************************ DAG FOR THREADED UPDATE ********************* */
  2757. /* Initialize run-time data in the graph needed for traversing it
  2758. * from multiple threads and start threaded tree traversal by adding
  2759. * the root node to the queue.
  2760. *
  2761. * This will mark DAG nodes as object/non-object and will calculate
  2762. * num_pending_parents of nodes (which is how many non-updated parents node
  2763. * have, which helps a lot checking whether node could be scheduled
  2764. * already or not).
  2765. */
  2766. void DAG_threaded_update_begin(Scene *scene,
  2767. void (*func)(void *node, void *user_data),
  2768. void *user_data)
  2769. {
  2770. DagNode *node;
  2771. /* We reset num_pending_parents to zero first and tag node as not scheduled yet... */
  2772. for (node = scene->theDag->DagNode.first; node; node = node->next) {
  2773. node->num_pending_parents = 0;
  2774. node->scheduled = false;
  2775. }
  2776. /* ... and then iterate over all the nodes and
  2777. * increase num_pending_parents for node childs.
  2778. */
  2779. for (node = scene->theDag->DagNode.first; node; node = node->next) {
  2780. DagAdjList *itA;
  2781. for (itA = node->child; itA; itA = itA->next) {
  2782. if (itA->node != node) {
  2783. itA->node->num_pending_parents++;
  2784. }
  2785. }
  2786. }
  2787. /* Add root nodes to the queue. */
  2788. BLI_spin_lock(&threaded_update_lock);
  2789. for (node = scene->theDag->DagNode.first; node; node = node->next) {
  2790. if (node->num_pending_parents == 0) {
  2791. node->scheduled = true;
  2792. func(node, user_data);
  2793. }
  2794. }
  2795. BLI_spin_unlock(&threaded_update_lock);
  2796. }
  2797. /* This function is called when handling node is done.
  2798. *
  2799. * This function updates num_pending_parents for all childs and
  2800. * schedules them if they're ready.
  2801. */
  2802. void DAG_threaded_update_handle_node_updated(void *node_v,
  2803. void (*func)(void *node, void *user_data),
  2804. void *user_data)
  2805. {
  2806. DagNode *node = node_v;
  2807. DagAdjList *itA;
  2808. for (itA = node->child; itA; itA = itA->next) {
  2809. DagNode *child_node = itA->node;
  2810. if (child_node != node) {
  2811. atomic_sub_and_fetch_uint32(&child_node->num_pending_parents, 1);
  2812. if (child_node->num_pending_parents == 0) {
  2813. bool need_schedule;
  2814. BLI_spin_lock(&threaded_update_lock);
  2815. need_schedule = child_node->scheduled == false;
  2816. child_node->scheduled = true;
  2817. BLI_spin_unlock(&threaded_update_lock);
  2818. if (need_schedule) {
  2819. func(child_node, user_data);
  2820. }
  2821. }
  2822. }
  2823. }
  2824. }
  2825. /* ************************ DAG DEBUGGING ********************* */
  2826. void DAG_print_dependencies(Main *bmain, Scene *scene, Object *ob)
  2827. {
  2828. /* utility for debugging dependencies */
  2829. dag_print_dependencies = 1;
  2830. if (ob && (ob->mode & OB_MODE_POSE)) {
  2831. printf("\nDEPENDENCY RELATIONS for %s\n\n", ob->id.name + 2);
  2832. DAG_pose_sort(ob);
  2833. }
  2834. else {
  2835. printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name + 2);
  2836. DAG_scene_relations_rebuild(bmain, scene);
  2837. }
  2838. dag_print_dependencies = 0;
  2839. }
  2840. /* ************************ DAG querying ********************* */
  2841. /* Will return Object ID if node represents Object,
  2842. * and will return NULL otherwise.
  2843. */
  2844. Object *DAG_get_node_object(void *node_v)
  2845. {
  2846. DagNode *node = node_v;
  2847. if (node->type == ID_OB) {
  2848. return node->ob;
  2849. }
  2850. return NULL;
  2851. }
  2852. /* Returns node name, used for debug output only, atm. */
  2853. const char *DAG_get_node_name(Scene *scene, void *node_v)
  2854. {
  2855. DagNode *node = node_v;
  2856. return dag_node_name(scene->theDag, node);
  2857. }
  2858. short DAG_get_eval_flags_for_object(Scene *scene, void *object)
  2859. {
  2860. DagNode *node;
  2861. if (!DEG_depsgraph_use_legacy()) {
  2862. return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
  2863. }
  2864. if (scene->theDag == NULL) {
  2865. /* Happens when converting objects to mesh from a python script
  2866. * after modifying scene graph.
  2867. *
  2868. * Currently harmless because it's only called for temporary
  2869. * objects which are out of the DAG anyway.
  2870. */
  2871. return 0;
  2872. }
  2873. node = dag_find_node(scene->theDag, object);
  2874. if (node) {
  2875. return node->eval_flags;
  2876. }
  2877. else {
  2878. /* Happens when external render engine exports temporary objects
  2879. * which are not in the DAG.
  2880. */
  2881. /* TODO(sergey): Doublecheck objects with Curve Deform exports all fine. */
  2882. /* TODO(sergey): Weak but currently we can't really access proper DAG from
  2883. * the modifiers stack. This is because in most cases modifier is to use
  2884. * the foreground scene, but to access evaluation flags we need to know
  2885. * active background scene, which we don't know.
  2886. */
  2887. if (scene->set) {
  2888. return DAG_get_eval_flags_for_object(scene->set, object);
  2889. }
  2890. return 0;
  2891. }
  2892. }
  2893. bool DAG_is_acyclic(Scene *scene)
  2894. {
  2895. return scene->theDag->is_acyclic;
  2896. }
  2897. #else
  2898. /* *********************************************************************
  2899. * Stubs to avoid linking issues and make sure legacy crap is not used *
  2900. * *********************************************************************
  2901. */
  2902. DagNodeQueue *queue_create(int UNUSED(slots))
  2903. {
  2904. BLI_assert(!"Should not be used with new dependnecy graph");
  2905. return NULL;
  2906. }
  2907. void queue_raz(DagNodeQueue *UNUSED(queue))
  2908. {
  2909. BLI_assert(!"Should not be used with new dependnecy graph");
  2910. }
  2911. void queue_delete(DagNodeQueue *UNUSED(queue))
  2912. {
  2913. BLI_assert(!"Should not be used with new dependnecy graph");
  2914. }
  2915. void push_queue(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
  2916. {
  2917. BLI_assert(!"Should not be used with new dependnecy graph");
  2918. }
  2919. void push_stack(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
  2920. {
  2921. BLI_assert(!"Should not be used with new dependnecy graph");
  2922. }
  2923. DagNode *pop_queue(DagNodeQueue *UNUSED(queue))
  2924. {
  2925. BLI_assert(!"Should not be used with new dependnecy graph");
  2926. return NULL;
  2927. }
  2928. DagNode *get_top_node_queue(DagNodeQueue *UNUSED(queue))
  2929. {
  2930. BLI_assert(!"Should not be used with new dependnecy graph");
  2931. return NULL;
  2932. }
  2933. DagForest *dag_init(void)
  2934. {
  2935. BLI_assert(!"Should not be used with new dependnecy graph");
  2936. return NULL;
  2937. }
  2938. DagForest *build_dag(Main *UNUSED(bmain),
  2939. Scene *UNUSED(sce),
  2940. short UNUSED(mask))
  2941. {
  2942. BLI_assert(!"Should not be used with new dependnecy graph");
  2943. return NULL;
  2944. }
  2945. void free_forest(DagForest *UNUSED(Dag))
  2946. {
  2947. BLI_assert(!"Should not be used with new dependnecy graph");
  2948. }
  2949. DagNode *dag_find_node(DagForest *UNUSED(forest), void *UNUSED(fob))
  2950. {
  2951. BLI_assert(!"Should not be used with new dependnecy graph");
  2952. return NULL;
  2953. }
  2954. DagNode *dag_add_node(DagForest *UNUSED(forest), void *UNUSED(fob))
  2955. {
  2956. BLI_assert(!"Should not be used with new dependnecy graph");
  2957. return NULL;
  2958. }
  2959. DagNode *dag_get_node(DagForest *UNUSED(forest), void *UNUSED(fob))
  2960. {
  2961. BLI_assert(!"Should not be used with new dependnecy graph");
  2962. return NULL;
  2963. }
  2964. DagNode *dag_get_sub_node(DagForest *UNUSED(forest), void *UNUSED(fob))
  2965. {
  2966. BLI_assert(!"Should not be used with new dependnecy graph");
  2967. return NULL;
  2968. }
  2969. void dag_add_relation(DagForest *UNUSED(forest),
  2970. DagNode *UNUSED(fob1),
  2971. DagNode *UNUSED(fob2),
  2972. short UNUSED(rel),
  2973. const char *UNUSED(name))
  2974. {
  2975. BLI_assert(!"Should not be used with new dependnecy graph");
  2976. }
  2977. /* debug test functions */
  2978. void graph_print_queue(DagNodeQueue *UNUSED(nqueue))
  2979. {
  2980. BLI_assert(!"Should not be used with new dependnecy graph");
  2981. }
  2982. void graph_print_queue_dist(DagNodeQueue *UNUSED(nqueue))
  2983. {
  2984. BLI_assert(!"Should not be used with new dependnecy graph");
  2985. }
  2986. void graph_print_adj_list(DagForest *UNUSED(dag))
  2987. {
  2988. BLI_assert(!"Should not be used with new dependnecy graph");
  2989. }
  2990. void DAG_scene_flush_update(Main *UNUSED(bmain),
  2991. Scene *UNUSED(sce),
  2992. unsigned int UNUSED(lay),
  2993. const short UNUSED(time))
  2994. {
  2995. BLI_assert(!"Should not be used with new dependnecy graph");
  2996. }
  2997. void DAG_scene_update_flags(Main *UNUSED(bmain),
  2998. Scene *UNUSED(scene),
  2999. unsigned int UNUSED(lay),
  3000. const bool UNUSED(do_time),
  3001. const bool UNUSED(do_invisible_flush))
  3002. {
  3003. BLI_assert(!"Should not be used with new dependnecy graph");
  3004. }
  3005. /* ******************* DAG FOR ARMATURE POSE ***************** */
  3006. void DAG_pose_sort(Object *UNUSED(ob))
  3007. {
  3008. BLI_assert(!"Should not be used with new dependnecy graph");
  3009. }
  3010. /* ************************ DAG FOR THREADED UPDATE ********************* */
  3011. void DAG_threaded_update_begin(Scene *UNUSED(scene),
  3012. void (*func)(void *node, void *user_data),
  3013. void *UNUSED(user_data))
  3014. {
  3015. BLI_assert(!"Should not be used with new dependnecy graph");
  3016. (void)func;
  3017. }
  3018. void DAG_threaded_update_handle_node_updated(void *UNUSED(node_v),
  3019. void (*func)(void *node, void *user_data),
  3020. void *UNUSED(user_data))
  3021. {
  3022. BLI_assert(!"Should not be used with new dependnecy graph");
  3023. (void)func;
  3024. }
  3025. /* ************************ DAG querying ********************* */
  3026. Object *DAG_get_node_object(void *UNUSED(node_v))
  3027. {
  3028. BLI_assert(!"Should not be used with new dependnecy graph");
  3029. return NULL;
  3030. }
  3031. const char *DAG_get_node_name(Scene *UNUSED(scene), void *UNUSED(node_v))
  3032. {
  3033. BLI_assert(!"Should not be used with new dependnecy graph");
  3034. return "INVALID";
  3035. }
  3036. bool DAG_is_acyclic(Scene *UNUSED(scene))
  3037. {
  3038. BLI_assert(!"Should not be used with new dependnecy graph");
  3039. return false;
  3040. }
  3041. /* ************************************
  3042. * This functions are to be supported *
  3043. * ************************************
  3044. */
  3045. void DAG_init(void)
  3046. {
  3047. DEG_register_node_types();
  3048. }
  3049. void DAG_exit(void)
  3050. {
  3051. DEG_free_node_types();
  3052. }
  3053. /* ************************ API *********************** */
  3054. void DAG_editors_update_cb(DEG_EditorUpdateIDCb id_func,
  3055. DEG_EditorUpdateSceneCb scene_func,
  3056. DEG_EditorUpdateScenePreCb scene_func_pre)
  3057. {
  3058. DEG_editors_set_update_cb(id_func, scene_func, scene_func_pre);
  3059. }
  3060. void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
  3061. {
  3062. DEG_editors_update_pre(bmain, scene, time);
  3063. }
  3064. /* Tag all relations for update. */
  3065. void DAG_relations_tag_update(Main *bmain)
  3066. {
  3067. DEG_relations_tag_update(bmain);
  3068. }
  3069. /* Rebuild dependency graph only for a given scene. */
  3070. void DAG_scene_relations_rebuild(Main *bmain, Scene *scene)
  3071. {
  3072. DEG_scene_relations_rebuild(bmain, scene);
  3073. }
  3074. /* Create dependency graph if it was cleared or didn't exist yet. */
  3075. void DAG_scene_relations_update(Main *bmain, Scene *scene)
  3076. {
  3077. DEG_scene_relations_update(bmain, scene);
  3078. }
  3079. void DAG_scene_relations_validate(Main *bmain, Scene *scene)
  3080. {
  3081. DEG_debug_scene_relations_validate(bmain, scene);
  3082. }
  3083. void DAG_scene_free(Scene *scene)
  3084. {
  3085. DEG_scene_graph_free(scene);
  3086. }
  3087. void DAG_on_visible_update(Main *bmain, const bool do_time)
  3088. {
  3089. DEG_on_visible_update(bmain, do_time);
  3090. }
  3091. void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
  3092. {
  3093. DEG_ids_check_recalc(bmain, scene, time);
  3094. }
  3095. void DAG_id_tag_update(ID *id, short flag)
  3096. {
  3097. DEG_id_tag_update_ex(G.main, id, flag);
  3098. }
  3099. void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
  3100. {
  3101. DEG_id_tag_update_ex(bmain, id, flag);
  3102. }
  3103. void DAG_id_type_tag(Main *bmain, short idtype)
  3104. {
  3105. DEG_id_type_tag(bmain, idtype);
  3106. }
  3107. int DAG_id_type_tagged(Main *bmain, short idtype)
  3108. {
  3109. return DEG_id_type_tagged(bmain, idtype);
  3110. }
  3111. void DAG_ids_clear_recalc(Main *bmain)
  3112. {
  3113. DEG_ids_clear_recalc(bmain);
  3114. }
  3115. short DAG_get_eval_flags_for_object(Scene *scene, void *object)
  3116. {
  3117. return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
  3118. }
  3119. void DAG_ids_flush_tagged(Main *bmain)
  3120. {
  3121. DEG_ids_flush_tagged(bmain);
  3122. }
  3123. /* ************************ DAG DEBUGGING ********************* */
  3124. void DAG_print_dependencies(Main *UNUSED(bmain),
  3125. Scene *scene,
  3126. Object *UNUSED(ob))
  3127. {
  3128. DEG_debug_graphviz(scene->depsgraph, stdout, "Depsgraph", false);
  3129. }
  3130. #endif