GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_structoccurence.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_structoccurence.h"
26 #include "glc_3dviewcollection.h"
27 #include "glc_structreference.h"
28 #include "glc_worldhandle.h"
29 #include "../glc_errorlog.h"
30 
32 : m_Uid(glc::GLC_GenID())
33 , m_pWorldHandle(NULL)
34 , m_pNumberOfOccurence(new int(1))
35 , m_pStructInstance(new GLC_StructInstance())
36 , m_pParent(NULL)
37 , m_Childs()
38 , m_AbsoluteMatrix()
39 , m_OccurenceNumber(0)
40 , m_IsVisible(true)
41 , m_pRenderProperties(NULL)
42 , m_AutomaticCreationOf3DViewInstance(true)
43 , m_pRelativeMatrix(NULL)
44 {
45  // Update instance
47 }
48 
49 GLC_StructOccurence::GLC_StructOccurence(GLC_StructInstance* pStructInstance, GLC_WorldHandle* pWorldHandle, GLuint shaderId)
50 : m_Uid(glc::GLC_GenID())
51 , m_pWorldHandle(pWorldHandle)
52 , m_pNumberOfOccurence(NULL)
53 , m_pStructInstance(pStructInstance)
54 , m_pParent(NULL)
55 , m_Childs()
56 , m_AbsoluteMatrix()
57 , m_OccurenceNumber(0)
58 , m_IsVisible(true)
59 , m_pRenderProperties(NULL)
60 , m_AutomaticCreationOf3DViewInstance(true)
61 , m_pRelativeMatrix(NULL)
62 {
64 }
65 
66 GLC_StructOccurence::GLC_StructOccurence(GLC_StructInstance* pStructInstance, GLC_uint id, GLC_WorldHandle* pWorldHandle, GLuint shaderId)
67 : m_Uid(id)
68 , m_pWorldHandle(pWorldHandle)
69 , m_pNumberOfOccurence(NULL)
70 , m_pStructInstance(pStructInstance)
71 , m_pParent(NULL)
72 , m_Childs()
73 , m_AbsoluteMatrix()
74 , m_OccurenceNumber(0)
75 , m_IsVisible(true)
76 , m_pRenderProperties(NULL)
77 , m_AutomaticCreationOf3DViewInstance(true)
78 , m_pRelativeMatrix(NULL)
79 {
81 }
82 
84 : m_Uid(glc::GLC_GenID())
85 , m_pWorldHandle(NULL)
86 , m_pNumberOfOccurence(new int(1))
87 , m_pStructInstance(NULL)
88 , m_pParent(NULL)
89 , m_Childs()
90 , m_AbsoluteMatrix()
91 , m_OccurenceNumber(0)
92 , m_IsVisible(true)
93 , m_pRenderProperties(NULL)
94 , m_AutomaticCreationOf3DViewInstance(true)
95 , m_pRelativeMatrix(NULL)
96 {
98 
99  // Update instance
101 }
102 
104 : m_Uid(id)
105 , m_pWorldHandle(NULL)
106 , m_pNumberOfOccurence(new int(1))
107 , m_pStructInstance(NULL)
108 , m_pParent(NULL)
109 , m_Childs()
110 , m_AbsoluteMatrix()
111 , m_OccurenceNumber(0)
112 , m_IsVisible(true)
113 , m_pRenderProperties(NULL)
114 , m_AutomaticCreationOf3DViewInstance(true)
115 , m_pRelativeMatrix(NULL)
116 {
118 
119  // Update instance
121 }
122 
123 GLC_StructOccurence::GLC_StructOccurence(GLC_WorldHandle* pWorldHandle, const GLC_StructOccurence& structOccurence, bool shareInstance)
124 : m_Uid(glc::GLC_GenID())
125 , m_pWorldHandle(pWorldHandle)
126 , m_pNumberOfOccurence(NULL)
127 , m_pStructInstance(NULL)
128 , m_pParent(NULL)
129 , m_Childs()
130 , m_AbsoluteMatrix(structOccurence.m_AbsoluteMatrix)
131 , m_OccurenceNumber(0)
132 , m_IsVisible(structOccurence.m_IsVisible)
133 , m_pRenderProperties(NULL)
134 , m_AutomaticCreationOf3DViewInstance(structOccurence.m_AutomaticCreationOf3DViewInstance)
135 , m_pRelativeMatrix(NULL)
136 {
137  if (shareInstance)
138  {
139  m_pStructInstance= structOccurence.m_pStructInstance;
141  ++(*m_pNumberOfOccurence);
142  }
143  else
144  {
145  m_pNumberOfOccurence= new int(1);
147  }
148 
149 
150  // Test if structOccurence has representation and has a shader
151  GLuint shaderId= 0;
152  bool instanceIsSelected= false;
153  if ((NULL != m_pWorldHandle) && (NULL != structOccurence.m_pWorldHandle) && structOccurence.m_pWorldHandle->collection()->contains(structOccurence.id()))
154  {
155  GLC_3DViewInstance* p3DViewInstance= structOccurence.m_pWorldHandle->collection()->instanceHandle(structOccurence.id());
156 
157  if(structOccurence.m_pWorldHandle->collection()->isInAShadingGroup(structOccurence.id()))
158  {
159  shaderId= structOccurence.m_pWorldHandle->collection()->shadingGroup(structOccurence.id());
160  }
161 
162  instanceIsSelected= p3DViewInstance->isSelected();
163  // Test the rendering properties
164  if (! p3DViewInstance->renderPropertiesHandle()->isDefault())
165  {
167  }
168  }
169  else if (NULL != structOccurence.m_pRenderProperties)
170  {
172  }
173 
174  // Inform the world Handle
175  if (NULL != m_pWorldHandle)
176  {
177  m_pWorldHandle->addOccurence(this, instanceIsSelected, shaderId);
178  if (NULL != m_pRenderProperties && this->has3DViewInstance())
179  {
181  delete m_pRenderProperties;
182  m_pRenderProperties= NULL;
183  }
184  }
185 
186  // Check flexibility
187  if (NULL != structOccurence.m_pRelativeMatrix)
188  {
189  m_pRelativeMatrix= new GLC_Matrix4x4(*(structOccurence.m_pRelativeMatrix));
190  }
191 
192  // Update Absolute matrix
194 
195 
196  // Create childs
197  const int size= structOccurence.childCount();
198  for (int i= 0; i < size; ++i)
199  {
200  GLC_StructOccurence* pChild= structOccurence.child(i)->clone(m_pWorldHandle, true);
201  addChild(pChild);
202  }
204  // Update instance
206 }
207 
209 {
210  //qDebug() << "Delete " << id();
211  Q_ASSERT(m_pNumberOfOccurence != NULL);
212 
213  // Remove Childs
214  const int size= m_Childs.size();
215  for (int i= 0; i < size; ++i)
216  {
217  GLC_StructOccurence* pChild= m_Childs.first();
218  removeChild(pChild);
219  delete pChild;
220  }
221 
222  makeOrphan();
223 
224  // Update number of occurence and instance
225  if ((--(*m_pNumberOfOccurence)) == 0)
226  {
227  delete m_pStructInstance;
228  delete m_pNumberOfOccurence;
229  }
230  else
231  {
234  {
235 
236  QStringList errorList;
237  errorList << "StructOccurence count error";
238  errorList << ("ref name = " + m_pStructInstance->structReference()->name());
239  GLC_ErrorLog::addError(errorList);
240 
241  delete m_pStructInstance;
242  //delete m_pNumberOfOccurence;
243  }
244  }
245 
246  delete m_pRenderProperties;
247  delete m_pRelativeMatrix;
248 }
249 
251 // Get Functions
253 
255 {
256  GLC_Matrix4x4 matrix;
257  if (NULL != m_pRelativeMatrix)
258  {
259  matrix= *m_pRelativeMatrix;
260  }
261  return matrix;
262 }
263 
265 {
266  if ((NULL != m_pStructInstance) && (m_pStructInstance->structReference() != NULL))
267  {
268  return this->structReference()->hasRepresentation();
269  }
270  else return false;
271 }
272 
274 {
275  if ( NULL != m_pWorldHandle)
276  {
278  }
279  else return false;
280 }
281 
283 {
284  bool canBeAdded= false;
285  if ((NULL != m_pStructInstance) && (m_pStructInstance->hasStructOccurence()) && (NULL != pOccurence->m_pStructInstance) && (NULL != pOccurence->structReference()))
286  {
287  if (this->structReference() != pOccurence->structReference())
288  {
289  QSet<GLC_StructReference*> thisRefSet= GLC_StructOccurence::parentsReferences(this);
290  thisRefSet << this->structReference();
291  QSet<GLC_StructReference*> childRefSet= pOccurence->childrenReferences();
292 
293  canBeAdded= thisRefSet == (thisRefSet - childRefSet);
294  }
295  }
296  else
297  {
298  canBeAdded= true;
299  }
300  return canBeAdded;
301 }
302 
303 QList<GLC_StructOccurence *> GLC_StructOccurence::ancestorList() const
304 {
305  QList<GLC_StructOccurence *> subject;
306  if (NULL != m_pParent)
307  {
308  subject.append(m_pParent);
309  subject.append(m_pParent->ancestorList());
310  }
311 
312  return subject;
313 }
314 
315 QList<GLC_StructOccurence*> GLC_StructOccurence::subOccurenceList() const
316 {
317  QList<GLC_StructOccurence*> subOccurence;
318  const int childCount= m_Childs.size();
319  for (int i= 0; i < childCount; ++i)
320  {
321  GLC_StructOccurence* pCurrentChild= m_Childs.at(i);
322  subOccurence.append(pCurrentChild);
323  if (pCurrentChild->hasChild())
324  {
325  subOccurence.append(pCurrentChild->subOccurenceList());
326  }
327  }
328 
329  return subOccurence;
330 }
331 
333 {
334  unsigned int result= 0;
335  if (hasRepresentation())
336  {
338  }
339 
340  const int size= m_Childs.size();
341  for (int i= 0; i < size; ++i)
342  {
343  result+= m_Childs.at(i)->numberOfFaces();
344  }
345 
346  return result;
347 }
348 
350 {
351  unsigned int result= 0;
352  if (hasRepresentation())
353  {
355  }
356  const int size= m_Childs.size();
357  for (int i= 0; i < size; ++i)
358  {
359  result+= m_Childs.at(i)->numberOfVertex();
360  }
361 
362  return result;
363 }
364 
366 {
367  unsigned int result= 0;
368  QSet<GLC_Material*> materialSet;
369  if (hasRepresentation())
370  {
372  }
373 
374  const int size= m_Childs.size();
375  for (int i= 0; i < size; ++i)
376  {
377  materialSet.unite(m_Childs.at(i)->materialSet());
378  }
379  result= static_cast<unsigned int>(materialSet.size());
380 
381  return result;
382 }
383 
384 QSet<GLC_Material*> GLC_StructOccurence::materialSet() const
385 {
386  QSet<GLC_Material*> materialSet;
387  if (hasRepresentation())
388  {
389  materialSet= structInstance()->structReference()->materialSet();
390  }
391 
392  const int size= m_Childs.size();
393  for (int i= 0; i < size; ++i)
394  {
395  materialSet.unite(m_Childs.at(i)->materialSet());
396  }
397 
398  return materialSet;
399 }
400 
401 GLC_StructOccurence* GLC_StructOccurence::clone(GLC_WorldHandle* pWorldHandle, bool shareInstance) const
402 {
403  return new GLC_StructOccurence(pWorldHandle, *this, shareInstance);
404 }
405 
407 {
408  bool isHidden= true;
409 
410  if ((NULL != m_pWorldHandle) && m_pWorldHandle->collection()->contains(m_Uid))
411  {
413  }
414  else if (childCount() > 0)
415  {
416  const int size= childCount();
417  int i= 0;
418  while ((i < size) && isHidden)
419  {
420  isHidden= isHidden && !child(i)->isVisible();
421  ++i;
422  }
423  }
424  else
425  {
426  isHidden= !m_IsVisible;
427  }
428  return !isHidden;
429 }
430 
432 {
434 
435  if (NULL != m_pWorldHandle)
436  {
437  if (has3DViewInstance())
438  {
439  Q_ASSERT(m_pWorldHandle->collection()->contains(id()));
440  boundingBox= m_pWorldHandle->collection()->instanceHandle(id())->boundingBox();
441  }
442  else
443  {
444  if (hasChild())
445  {
446  QList<GLC_StructOccurence*> childrenList= children();
447  const int size= childrenList.size();
448 
449  for (int i= 0; i < size; ++i)
450  {
451  boundingBox.combine(childrenList.at(i)->boundingBox());
452  }
453  }
454  }
455  }
456 
457  return boundingBox;
458 }
459 
460 unsigned int GLC_StructOccurence::nodeCount() const
461 {
462  unsigned int result= 1;
463  const int size= m_Childs.size();
464  for (int i= 0; i < size; ++i)
465  {
466  result+= m_Childs.at(i)->nodeCount();
467  }
468  return result;
469 }
470 
471 QSet<GLC_StructReference*> GLC_StructOccurence::childrenReferences() const
472 {
473  QSet<GLC_StructReference*> refChildrenSet;
474  const int childCount= m_Childs.size();
475  for (int i= 0; i < childCount; ++i)
476  {
477  GLC_StructOccurence* pCurrentChild= m_Childs.at(i);
478  if ((NULL != pCurrentChild->structInstance()) && (NULL != pCurrentChild->structReference()))
479  {
480  refChildrenSet << pCurrentChild->structReference();
481  }
482  }
483 
484  return refChildrenSet;
485 }
486 
487 QSet<GLC_StructReference*> GLC_StructOccurence::parentsReferences(const GLC_StructOccurence* pOccurence)
488 {
489  QSet<GLC_StructReference*> parentSet;
490  GLC_StructOccurence* pParent= pOccurence->parent();
491  if (NULL != pParent)
492  {
493  if ((NULL != pParent->structInstance()) && (NULL != pParent->structReference()))
494  {
495  parentSet << pParent->structReference();
496  parentSet.unite(GLC_StructOccurence::parentsReferences(pParent));
497  }
498  }
499 
500  return parentSet;
501 }
502 
504 {
505  int subject= -1;
506  const int childCount= m_Childs.count();
507  bool containsOcc= false;
508  int i= 0;
509  while (!containsOcc && (i < childCount))
510  {
511  if (m_Childs.at(i) == pOcc)
512  {
513  containsOcc= true;
514  subject= i;
515  }
516  ++i;
517  }
518  return subject;
519 }
520 
522 {
523  return pOcc->parent() == this;
524 }
526 // Set Functions
528 
530 {
531  GLC_Matrix4x4 relativeMatrix;
532  if (NULL == m_pRelativeMatrix)
533  {
534  relativeMatrix= m_pStructInstance->relativeMatrix();
535  }
536  else
537  {
538  relativeMatrix= *m_pRelativeMatrix;
539  }
540 
541  if (NULL != m_pParent)
542  {
543  m_AbsoluteMatrix= m_pParent->absoluteMatrix() * relativeMatrix;
544  }
545  else
546  {
547  m_AbsoluteMatrix= relativeMatrix;
548  }
549  // If the occurence have a representation, update it.
550 
551  if ((NULL != m_pWorldHandle) && m_pWorldHandle->collection()->contains(m_Uid))
552  {
554  }
555  return this;
556 }
557 
559 {
561  const int size= m_Childs.size();
562  for (int i= 0; i < size; ++i)
563  {
564  m_Childs[i]->updateChildrenAbsoluteMatrix();
565  }
566  return this;
567 }
568 
570 {
571  Q_ASSERT(pChild->isOrphan());
572  Q_ASSERT((NULL == pChild->m_pWorldHandle) || (m_pWorldHandle == pChild->m_pWorldHandle));
573 
574  //qDebug() << "Add Child " << pChild->name() << "id=" << pChild->id() << " to " << name() << " id=" << id();
575  // Add the child to the list of child
576  // Get occurence reference
577  m_Childs.append(pChild);
578  pChild->m_pParent= this;
579  if (NULL == pChild->m_pWorldHandle)
580  {
582  }
584 }
585 
587 {
588  Q_ASSERT(pChild->isOrphan());
589  Q_ASSERT((NULL == pChild->m_pWorldHandle) || (m_pWorldHandle == pChild->m_pWorldHandle));
590  Q_ASSERT(m_Childs.count() >= index);
591 
592  //qDebug() << "Add Child " << pChild->name() << "id=" << pChild->id() << " to " << name() << " id=" << id();
593  // Add the child to the list of child
594  // Get occurence reference
595  m_Childs.insert(index, pChild);
596  pChild->m_pParent= this;
597  if (NULL == pChild->m_pWorldHandle)
598  {
600  }
602 }
603 
605 {
606  GLC_StructOccurence* pOccurence;
607  pOccurence= new GLC_StructOccurence(pInstance, m_pWorldHandle);
608 
609  addChild(pOccurence);
610 
611  return pOccurence;
612 }
613 
615 {
616  GLC_StructOccurence* pOccurence;
617  pOccurence= new GLC_StructOccurence(pInstance, m_pWorldHandle);
618 
619  insertChild(index, pOccurence);
620 
621  return pOccurence;
622 }
623 
625 {
626  if(!isOrphan())
627  {
628  m_pParent->removeChild(this);
629  }
630  else
631  {
632  detach();
633  }
634 }
635 
637 {
638  Q_ASSERT(pChild->m_pParent == this);
639  pChild->m_pParent= NULL;
640  pChild->detach();
641 
642  return m_Childs.removeOne(pChild);
643 }
644 
645 
647 {
648  if (has3DViewInstance())
649  {
651  }
652 }
653 
655 {
656  bool subject= false;
657  if (!has3DViewInstance() && (NULL != m_pWorldHandle) && hasRepresentation())
658  {
659  GLC_3DRep* p3DRep= dynamic_cast<GLC_3DRep*>(structReference()->representationHandle());
660  if (NULL != p3DRep)
661  {
662  GLC_3DViewInstance instance(*p3DRep, m_Uid);
663  instance.setName(name());
664 
665  if (NULL != m_pRenderProperties)
666  {
668  delete m_pRenderProperties;
669  m_pRenderProperties= NULL;
670  }
671 
672  if (0 != shaderId) m_pWorldHandle->collection()->bindShader(shaderId);
673  subject= m_pWorldHandle->collection()->add(instance, shaderId);
676  {
678  }
679  }
680  }
681  return subject;
682 }
683 
685 {
686  if (NULL != m_pWorldHandle)
687  {
689  }
690  else return false;
691 }
692 
693 // Set the occurence world Handle
695 {
696  // Check if world handles are equal
697  if (m_pWorldHandle == pWorldHandle) return;
698 
699  if (NULL != m_pWorldHandle)
700  {
702  }
703 
704  m_pWorldHandle= pWorldHandle;
705 
706  if (NULL != m_pWorldHandle)
707  {
710 
711  const int size= m_Childs.size();
712  for (int i= 0; i < size; ++i)
713  {
714  m_Childs[i]->setWorldHandle(m_pWorldHandle);
715  }
716  }
717 }
718 
719 // Load the representation and return true if success
721 {
722  Q_ASSERT(!this->has3DViewInstance());
723 
724  bool loadSuccess= false;
725  if (hasRepresentation())
726  {
727  GLC_StructReference* pReference= this->structReference();
728  if (pReference->representationIsLoaded())
729  {
730  loadSuccess= create3DViewInstance();
731  }
732  else
733  {
735  if (loadSuccess && !m_AutomaticCreationOf3DViewInstance)
736  {
737  loadSuccess= create3DViewInstance();
738  }
739  }
740  }
741 
742  return loadSuccess;
743 }
744 
745 // UnLoad the representation and return true if success
747 {
748  bool unloadResult= false;
749  if (hasRepresentation())
750  {
751  GLC_StructReference* pRef= this->structReference();
752  if (pRef->representationIsLoaded())
753  {
754  if (this->has3DViewInstance())
755  {
756  unloadResult= m_pWorldHandle->collection()->remove(m_Uid);
757  QSet<GLC_StructOccurence*> occurenceSet= pRef->setOfStructOccurence();
758  QSet<GLC_StructOccurence*>::const_iterator iOcc= occurenceSet.constBegin();
759  bool unloadReferenceRep= true;
760  while (occurenceSet.constEnd() != iOcc)
761  {
762  unloadReferenceRep= unloadReferenceRep && !(*iOcc)->has3DViewInstance();
763  ++iOcc;
764  }
765  if (unloadReferenceRep)
766  {
767  pRef->unloadRepresentation();
768  }
769  }
770  }
771  }
772  return unloadResult;
773 }
774 
775 unsigned int GLC_StructOccurence::updateOccurenceNumber(unsigned int n)
776 {
777  m_OccurenceNumber= n++;
778  const int childCount= m_Childs.size();
779  for (int i= 0; i < childCount; ++i)
780  {
781  n= m_Childs[i]->updateOccurenceNumber(n);
782  }
783  return n;
784 }
785 
787 {
788  m_IsVisible= visibility;
789  if (has3DViewInstance())
790  {
792  }
793  const int childCount= m_Childs.size();
794  for (int i= 0; i < childCount; ++i)
795  {
796  m_Childs[i]->setVisibility(m_IsVisible);
797  }
798 }
799 
801 {
802  qDebug() << "GLC_StructOccurence::setRenderProperties";
803  delete m_pRenderProperties;
804  m_pRenderProperties= NULL;
805  if (has3DViewInstance())
806  {
808  }
809 
810  if (hasChild())
811  {
812  const int childCount= m_Childs.size();
813  for (int i= 0; i < childCount; ++i)
814  {
815  m_Childs[i]->setRenderProperties(renderProperties);
816  }
817  }
818  else if (!has3DViewInstance())
819  {
820  m_pRenderProperties= new GLC_RenderProperties(renderProperties);
821  }
822 }
823 
825 {
826  QList<GLC_StructOccurence*>::iterator iChild= m_Childs.begin();
827  while (m_Childs.constEnd() != iChild)
828  {
829  if (!((*iChild)->hasChild()) && !((*iChild)->hasRepresentation()))
830  {
831  GLC_StructOccurence* pOcc= *iChild;
832  iChild= m_Childs.erase(iChild);
833  delete pOcc;
834  }
835  else
836  {
837  (*iChild)->removeEmptyChildren();
838  ++iChild;
839  }
840  }
841 }
842 
844 {
845  Q_ASSERT(m_pStructInstance->structReference() == NULL);
846  Q_ASSERT((*m_pNumberOfOccurence) == 1);
847 
848  if (pRef->hasStructInstance())
849  {
850  GLC_StructInstance* pExistingInstance= pRef->firstInstanceHandle();
851  if (pExistingInstance->hasStructOccurence())
852  {
853  GLC_StructOccurence* pFirstOccurence= pExistingInstance->firstOccurenceHandle();
854  QList<GLC_StructOccurence*> childs= pFirstOccurence->m_Childs;
855  const int size= childs.size();
856  for (int i= 0; i < size; ++i)
857  {
858  GLC_StructOccurence* pChild= childs.at(i)->clone(m_pWorldHandle, true);
859  addChild(pChild);
860  }
861 
862  QList<GLC_StructInstance*> instances= pRef->listOfStructInstances();
863  const int instanceCount= instances.size();
864  int i= 0;
865  bool continu= true;
866  while (continu && (i < instanceCount))
867  {
868  if (m_pStructInstance == instances.at(i))
869  {
870  continu= false;
871  delete m_pNumberOfOccurence;
872  m_pNumberOfOccurence= instances.at(i)->firstOccurenceHandle()->m_pNumberOfOccurence;
873  ++(*m_pNumberOfOccurence);
874  }
875  ++i;
876  }
877  }
878  }
879 
881 }
882 
884 {
885  delete m_pRelativeMatrix;
886  m_pRelativeMatrix= new GLC_Matrix4x4(relativeMatrix);
887 
889 }
890 
892 {
893  delete m_pRelativeMatrix;
894  m_pRelativeMatrix= NULL;
895 
897 }
898 
899 void GLC_StructOccurence::swap(int i, int j)
900 {
901  Q_ASSERT(i != j);
902 
903  GLC_StructReference* pRef= this->structReference();
904  QList<GLC_StructOccurence*> occurences= pRef->listOfStructOccurence();
905  const int count= occurences.count();
906  for (int i= 0; i < count; ++i)
907  {
908  GLC_StructOccurence* pOcc= occurences.at(i);
909  Q_ASSERT(i <= pOcc->m_Childs.count());
910  Q_ASSERT(j <= pOcc->m_Childs.count());
911  pOcc->m_Childs.swap(i, j);
912  }
913 
914 }
915 
917 // Private services function
919 
921 {
922  if (NULL != m_pWorldHandle)
923  {
924  // retrieve renderProperties if needed
926  {
928  if (!pInstance->renderPropertiesHandle()->isDefault())
929  {
930  Q_ASSERT(NULL == m_pRenderProperties);
932  }
933  }
935  m_pWorldHandle= NULL;
936  if (!m_Childs.isEmpty())
937  {
938  const int size= m_Childs.size();
939  for (int i= 0; i < size; ++i)
940  {
941  m_Childs[i]->detach();
942  }
943  }
944  }
945 }
946 
948 {
949  // Update the number of occurences
951  {
953  m_pNumberOfOccurence= pFirstOccurence->m_pNumberOfOccurence;
954  ++(*m_pNumberOfOccurence);
955  QList<GLC_StructOccurence*> childs= pFirstOccurence->m_Childs;
956  const int size= childs.size();
957  for (int i= 0; i < size; ++i)
958  {
959  GLC_StructOccurence* pChild= childs.at(i)->clone(m_pWorldHandle, true);
960  addChild(pChild);
961  }
962  }
963  else
964  {
965  m_pNumberOfOccurence= new int(1);
966  }
967 
968  // Inform the world Handle
969  if (NULL != m_pWorldHandle)
970  {
971  m_pWorldHandle->addOccurence(this, shaderId);
972  }
973 
974  // Update Absolute matrix
976 
977  // Update instance
979 }

©2005-2013 Laurent Ribon