]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/entity/doom3group.cpp
changed ase texture parsing to match DoomEdit
[xonotic/netradiant.git] / plugins / entity / doom3group.cpp
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant 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 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 ///\file
23 ///\brief Represents any Doom3 entity which does not have a fixed size specified in its entity-definition (e.g. func_static).
24 ///
25 /// This entity behaves as a group only when the "model" key is empty or is the same as the "name" key. Otherwise it behaves as a model.
26 /// When behaving as a group, the "origin" key is the translation to be applied to all brushes (not patches) grouped under this entity.
27 /// When behaving as a model, the "origin", "angle" and "rotation" keys directly control the entity's local-to-parent transform.
28 /// When either the "curve_Nurbs" or "curve_CatmullRomSpline" keys define a curve, the curve is rendered and can be edited.
29
30 #include "doom3group.h"
31
32 #include "cullable.h"
33 #include "renderable.h"
34 #include "editable.h"
35 #include "modelskin.h"
36
37 #include "selectionlib.h"
38 #include "instancelib.h"
39 #include "transformlib.h"
40 #include "traverselib.h"
41 #include "entitylib.h"
42 #include "render.h"
43 #include "eclasslib.h"
44 #include "stream/stringstream.h"
45 #include "pivot.h"
46
47 #include "targetable.h"
48 #include "origin.h"
49 #include "angle.h"
50 #include "rotation.h"
51 #include "model.h"
52 #include "filters.h"
53 #include "namedentity.h"
54 #include "keyobservers.h"
55 #include "namekeys.h"
56 #include "curve.h"
57 #include "modelskinkey.h"
58
59 #include "entity.h"
60
61 inline void PointVertexArray_testSelect(PointVertex* first, std::size_t count, SelectionTest& test, SelectionIntersection& best)
62 {
63   test.TestLineStrip(
64     VertexPointer(
65       reinterpret_cast<VertexPointer::pointer>(&first->vertex),
66       sizeof(PointVertex)
67     ),
68     IndexPointer::index_type(count),
69     best
70   );
71 }
72
73 class Doom3Group :
74   public Bounded,
75   public Snappable
76 {
77   EntityKeyValues m_entity;
78   KeyObserverMap m_keyObservers;
79   TraversableNodeSet m_traverse;
80   MatrixTransform m_transform;
81
82   SingletonModel m_model;
83   OriginKey m_originKey;
84   Vector3 m_origin;
85   RotationKey m_rotationKey;
86   Float9 m_rotation;
87
88   ClassnameFilter m_filter;
89   NamedEntity m_named;
90   NameKeys m_nameKeys;
91   TraversableObserverPairRelay m_traverseObservers;
92   Doom3GroupOrigin m_funcStaticOrigin;
93   RenderablePivot m_renderOrigin;
94   RenderableNamedEntity m_renderName;
95   ModelSkinKey m_skin;
96
97 public:
98   NURBSCurve m_curveNURBS;
99   SignalHandlerId m_curveNURBSChanged;
100   CatmullRomSpline m_curveCatmullRom;
101   SignalHandlerId m_curveCatmullRomChanged;
102 private:
103   mutable AABB m_curveBounds;
104
105   Callback m_transformChanged;
106   Callback m_evaluateTransform;
107
108   CopiedString m_name;
109   CopiedString m_modelKey;
110   bool m_isModel;
111
112   scene::Traversable* m_traversable;
113
114   void construct()
115   {
116     default_rotation(m_rotation);
117
118     m_keyObservers.insert("classname", ClassnameFilter::ClassnameChangedCaller(m_filter));
119     m_keyObservers.insert(Static<KeyIsName>::instance().m_nameKey, NamedEntity::IdentifierChangedCaller(m_named));
120     m_keyObservers.insert("model", Doom3Group::ModelChangedCaller(*this));
121     m_keyObservers.insert("origin", OriginKey::OriginChangedCaller(m_originKey));
122     m_keyObservers.insert("angle", RotationKey::AngleChangedCaller(m_rotationKey));
123     m_keyObservers.insert("rotation", RotationKey::RotationChangedCaller(m_rotationKey));
124     m_keyObservers.insert("name", NameChangedCaller(*this));
125     m_keyObservers.insert(curve_Nurbs, NURBSCurve::CurveChangedCaller(m_curveNURBS));
126     m_keyObservers.insert(curve_CatmullRomSpline, CatmullRomSpline::CurveChangedCaller(m_curveCatmullRom));
127     m_keyObservers.insert("skin", ModelSkinKey::SkinChangedCaller(m_skin));
128
129     m_traverseObservers.attach(m_funcStaticOrigin);
130     m_isModel = false;
131     m_nameKeys.setKeyIsName(keyIsNameDoom3Doom3Group);
132     attachTraverse();
133
134     m_entity.attach(m_keyObservers);
135   }
136   void destroy()
137   {
138     m_entity.detach(m_keyObservers);
139
140     if(isModel())
141     {
142       detachModel();
143     }
144     else
145     {
146       detachTraverse();
147     }
148
149     m_traverseObservers.detach(m_funcStaticOrigin);
150   }
151
152   void attachModel()
153   {
154     m_traversable = &m_model.getTraversable();
155     m_model.attach(&m_traverseObservers);
156   }
157   void detachModel()
158   {
159     m_traversable = 0;
160     m_model.detach(&m_traverseObservers);
161   }
162   void attachTraverse()
163   {
164     m_traversable = &m_traverse;
165     m_traverse.attach(&m_traverseObservers);
166   }
167   void detachTraverse()
168   {
169     m_traversable = 0;
170     m_traverse.detach(&m_traverseObservers);
171   }
172
173   bool isModel() const
174   {
175     return m_isModel;
176   }
177  
178   void setIsModel(bool newValue)
179   {
180     if(newValue && !m_isModel)
181     {
182       detachTraverse();
183       attachModel();
184
185       m_nameKeys.setKeyIsName(Static<KeyIsName>::instance().m_keyIsName);
186       m_model.modelChanged(m_modelKey.c_str());
187     }
188     else if(!newValue && m_isModel)
189     {
190       detachModel();
191       attachTraverse();
192
193       m_nameKeys.setKeyIsName(keyIsNameDoom3Doom3Group);
194     }
195     m_isModel = newValue;
196     updateTransform();
197   }
198
199   void updateIsModel()
200   {
201     setIsModel(!string_empty(m_modelKey.c_str()) && !string_equal(m_modelKey.c_str(), m_name.c_str()));
202   }
203
204   void nameChanged(const char* value)
205   {
206     m_name = value;
207     updateIsModel();
208   }
209   typedef MemberCaller1<Doom3Group, const char*, &Doom3Group::nameChanged> NameChangedCaller;
210
211   void modelChanged(const char* value)
212   {
213     m_modelKey = value;
214     updateIsModel();
215     if(isModel())
216     {
217       m_model.modelChanged(value);
218     }
219     else
220     {
221       m_model.modelChanged("");
222     }
223   }
224   typedef MemberCaller1<Doom3Group, const char*, &Doom3Group::modelChanged> ModelChangedCaller;
225
226   void updateTransform()
227   {
228     m_transform.localToParent() = g_matrix4_identity;
229     if(isModel())
230     {
231       matrix4_translate_by_vec3(m_transform.localToParent(), m_origin);
232       matrix4_multiply_by_matrix4(m_transform.localToParent(), rotation_toMatrix(m_rotation));
233     }
234     m_transformChanged();
235     if(!isModel())
236     {
237       m_funcStaticOrigin.originChanged();
238     }
239   }
240   typedef MemberCaller<Doom3Group, &Doom3Group::updateTransform> UpdateTransformCaller;
241
242   void originChanged()
243   {
244     m_origin = m_originKey.m_origin;
245     updateTransform();
246   }
247   typedef MemberCaller<Doom3Group, &Doom3Group::originChanged> OriginChangedCaller;
248
249   void rotationChanged()
250   {
251     rotation_assign(m_rotation, m_rotationKey.m_rotation);
252     updateTransform();
253   }
254   typedef MemberCaller<Doom3Group, &Doom3Group::rotationChanged> RotationChangedCaller;
255
256   void skinChanged()
257   {
258     if(isModel())
259     {
260       scene::Node* node = m_model.getNode();
261       if(node != 0)
262       {
263         Node_modelSkinChanged(*node);
264       }
265     }
266   }
267   typedef MemberCaller<Doom3Group, &Doom3Group::skinChanged> SkinChangedCaller;
268
269 public:
270   Doom3Group(EntityClass* eclass, scene::Node& node, const Callback& transformChanged, const Callback& boundsChanged, const Callback& evaluateTransform) :
271     m_entity(eclass),
272     m_originKey(OriginChangedCaller(*this)),
273     m_origin(ORIGINKEY_IDENTITY),
274     m_rotationKey(RotationChangedCaller(*this)),
275     m_filter(m_entity, node),
276     m_named(m_entity),
277     m_nameKeys(m_entity),
278     m_funcStaticOrigin(m_traverse, m_origin),
279     m_renderName(m_named, g_vector3_identity),
280     m_skin(SkinChangedCaller(*this)),
281     m_curveNURBS(boundsChanged),
282     m_curveCatmullRom(boundsChanged),
283     m_transformChanged(transformChanged),
284     m_evaluateTransform(evaluateTransform),
285     m_traversable(0)
286   {
287     construct();
288   }
289   Doom3Group(const Doom3Group& other, scene::Node& node, const Callback& transformChanged, const Callback& boundsChanged, const Callback& evaluateTransform) :
290     m_entity(other.m_entity),
291     m_originKey(OriginChangedCaller(*this)),
292     m_origin(ORIGINKEY_IDENTITY),
293     m_rotationKey(RotationChangedCaller(*this)),
294     m_filter(m_entity, node),
295     m_named(m_entity),
296     m_nameKeys(m_entity),
297     m_funcStaticOrigin(m_traverse, m_origin),
298     m_renderName(m_named, g_vector3_identity),
299     m_skin(SkinChangedCaller(*this)),
300     m_curveNURBS(boundsChanged),
301     m_curveCatmullRom(boundsChanged),
302     m_transformChanged(transformChanged),
303     m_evaluateTransform(evaluateTransform),
304     m_traversable(0)
305   {
306     construct();
307   }
308   ~Doom3Group()
309   {
310     destroy();
311   }
312
313   InstanceCounter m_instanceCounter;
314   void instanceAttach(const scene::Path& path)
315   {
316     if(++m_instanceCounter.m_count == 1)
317     {
318       m_filter.instanceAttach();
319       m_entity.instanceAttach(path_find_mapfile(path.begin(), path.end()));
320       m_traverse.instanceAttach(path_find_mapfile(path.begin(), path.end()));
321
322       m_funcStaticOrigin.enable();
323     }
324   }
325   void instanceDetach(const scene::Path& path)
326   {
327     if(--m_instanceCounter.m_count == 0)
328     {
329       m_funcStaticOrigin.disable();
330
331       m_traverse.instanceDetach(path_find_mapfile(path.begin(), path.end()));
332       m_entity.instanceDetach(path_find_mapfile(path.begin(), path.end()));
333       m_filter.instanceDetach();
334     }
335   }
336
337   EntityKeyValues& getEntity()
338   {
339     return m_entity;
340   }
341   const EntityKeyValues& getEntity() const
342   {
343     return m_entity;
344   }
345
346   scene::Traversable& getTraversable()
347   {
348     return *m_traversable;
349   }
350   Namespaced& getNamespaced()
351   {
352     return m_nameKeys;
353   }
354   Nameable& getNameable()
355   {
356     return m_named;
357   }
358   TransformNode& getTransformNode()
359   {
360     return m_transform;
361   }
362   ModelSkin& getModelSkin()
363   {
364     return m_skin.get();
365   }
366
367   void attach(scene::Traversable::Observer* observer)
368   {
369     m_traverseObservers.attach(*observer);
370   }
371   void detach(scene::Traversable::Observer* observer)
372   {
373     m_traverseObservers.detach(*observer);
374   }
375
376   const AABB& localAABB() const
377   {
378     m_curveBounds = m_curveNURBS.m_bounds;
379     aabb_extend_by_aabb_safe(m_curveBounds, m_curveCatmullRom.m_bounds);
380     return m_curveBounds;
381   }
382
383   void renderSolid(Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld, bool selected) const
384   {
385     if(isModel() && selected)
386     {
387       m_renderOrigin.render(renderer, volume, localToWorld);
388     }
389
390     renderer.SetState(m_entity.getEntityClass().m_state_wire, Renderer::eWireframeOnly);
391     renderer.SetState(m_entity.getEntityClass().m_state_wire, Renderer::eFullMaterials);
392
393     if(!m_curveNURBS.m_renderCurve.m_vertices.empty())
394     {
395       renderer.addRenderable(m_curveNURBS.m_renderCurve, localToWorld);
396     }
397     if(!m_curveCatmullRom.m_renderCurve.m_vertices.empty())
398     {
399       renderer.addRenderable(m_curveCatmullRom.m_renderCurve, localToWorld);
400     }
401   }
402   void renderWireframe(Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld, bool selected) const
403   {
404     renderSolid(renderer, volume, localToWorld, selected);
405     if(g_showNames && isModel())
406     {
407       renderer.addRenderable(m_renderName, localToWorld);
408     }
409   }
410
411   void testSelect(Selector& selector, SelectionTest& test, SelectionIntersection& best)
412   {
413     PointVertexArray_testSelect(&m_curveNURBS.m_renderCurve.m_vertices[0], m_curveNURBS.m_renderCurve.m_vertices.size(), test, best);
414     PointVertexArray_testSelect(&m_curveCatmullRom.m_renderCurve.m_vertices[0], m_curveCatmullRom.m_renderCurve.m_vertices.size(), test, best);
415   }
416
417   void translate(const Vector3& translation)
418   {
419     m_origin = origin_translated(m_origin, translation);
420   }
421   void rotate(const Quaternion& rotation)
422   {
423     rotation_rotate(m_rotation, rotation);
424   }
425   void snapto(float snap)
426   {
427     m_originKey.m_origin = origin_snapped(m_originKey.m_origin, snap);
428     m_originKey.write(&m_entity);
429   }
430   void revertTransform()
431   {
432     m_origin = m_originKey.m_origin;
433     rotation_assign(m_rotation, m_rotationKey.m_rotation);
434     m_curveNURBS.m_controlPointsTransformed = m_curveNURBS.m_controlPoints;
435     m_curveCatmullRom.m_controlPointsTransformed = m_curveCatmullRom.m_controlPoints;
436   }
437   void freezeTransform()
438   {
439     m_originKey.m_origin = m_origin;
440     m_originKey.write(&m_entity);
441     rotation_assign(m_rotationKey.m_rotation, m_rotation);
442     m_rotationKey.write(&m_entity);
443     m_curveNURBS.m_controlPoints = m_curveNURBS.m_controlPointsTransformed;
444     ControlPoints_write(m_curveNURBS.m_controlPoints, curve_Nurbs, m_entity);
445     m_curveCatmullRom.m_controlPoints = m_curveCatmullRom.m_controlPointsTransformed;
446     ControlPoints_write(m_curveCatmullRom.m_controlPoints, curve_CatmullRomSpline, m_entity);
447   }
448   void transformChanged()
449   {
450     revertTransform();
451     m_evaluateTransform();
452     updateTransform();
453     m_curveNURBS.curveChanged();
454     m_curveCatmullRom.curveChanged();
455   }
456   typedef MemberCaller<Doom3Group, &Doom3Group::transformChanged> TransformChangedCaller;
457 };
458
459 class ControlPointAddBounds
460 {
461   AABB& m_bounds;
462 public:
463   ControlPointAddBounds(AABB& bounds) : m_bounds(bounds)
464   {
465   }
466   void operator()(const Vector3& point) const
467   {
468     aabb_extend_by_point_safe(m_bounds, point);
469   }
470 };
471
472 class Doom3GroupInstance :
473   public TargetableInstance,
474   public TransformModifier,
475   public Renderable,
476   public SelectionTestable,
477   public ComponentSelectionTestable,
478   public ComponentEditable,
479   public ComponentSnappable
480 {
481   class TypeCasts
482   {
483     InstanceTypeCastTable m_casts;
484   public:
485     TypeCasts()
486     {
487       m_casts = TargetableInstance::StaticTypeCasts::instance().get();
488       InstanceContainedCast<Doom3GroupInstance, Bounded>::install(m_casts);
489       InstanceStaticCast<Doom3GroupInstance, Renderable>::install(m_casts);
490       InstanceStaticCast<Doom3GroupInstance, SelectionTestable>::install(m_casts);
491       InstanceStaticCast<Doom3GroupInstance, ComponentSelectionTestable>::install(m_casts);
492       InstanceStaticCast<Doom3GroupInstance, ComponentEditable>::install(m_casts);
493       InstanceStaticCast<Doom3GroupInstance, ComponentSnappable>::install(m_casts);
494       InstanceStaticCast<Doom3GroupInstance, Transformable>::install(m_casts);
495       InstanceIdentityCast<Doom3GroupInstance>::install(m_casts);
496     }
497     InstanceTypeCastTable& get()
498     {
499       return m_casts;
500     }
501   };
502
503   Doom3Group& m_contained;
504   CurveEdit m_curveNURBS;
505   CurveEdit m_curveCatmullRom;
506   mutable AABB m_aabb_component;
507 public:
508
509   typedef LazyStatic<TypeCasts> StaticTypeCasts;
510
511
512   Bounded& get(NullType<Bounded>)
513   {
514     return m_contained;
515   }
516
517   STRING_CONSTANT(Name, "Doom3GroupInstance");
518
519   Doom3GroupInstance(const scene::Path& path, scene::Instance* parent, Doom3Group& contained) :
520     TargetableInstance(path, parent, this, StaticTypeCasts::instance().get(), contained.getEntity(), *this),
521     TransformModifier(Doom3Group::TransformChangedCaller(contained), ApplyTransformCaller(*this)),
522     m_contained(contained),
523     m_curveNURBS(m_contained.m_curveNURBS.m_controlPointsTransformed, SelectionChangedComponentCaller(*this)),
524     m_curveCatmullRom(m_contained.m_curveCatmullRom.m_controlPointsTransformed, SelectionChangedComponentCaller(*this))
525   {
526     m_contained.instanceAttach(Instance::path());
527     m_contained.m_curveNURBSChanged = m_contained.m_curveNURBS.connect(CurveEdit::CurveChangedCaller(m_curveNURBS));
528     m_contained.m_curveCatmullRomChanged = m_contained.m_curveCatmullRom.connect(CurveEdit::CurveChangedCaller(m_curveCatmullRom));
529
530     StaticRenderableConnectionLines::instance().attach(*this);
531   }
532   ~Doom3GroupInstance()
533   {
534     StaticRenderableConnectionLines::instance().detach(*this);
535
536     m_contained.m_curveCatmullRom.disconnect(m_contained.m_curveCatmullRomChanged);
537     m_contained.m_curveNURBS.disconnect(m_contained.m_curveNURBSChanged);
538     m_contained.instanceDetach(Instance::path());
539   }
540   void renderSolid(Renderer& renderer, const VolumeTest& volume) const
541   {
542     m_contained.renderSolid(renderer, volume, Instance::localToWorld(), getSelectable().isSelected());
543
544     m_curveNURBS.renderComponentsSelected(renderer, volume, localToWorld());
545     m_curveCatmullRom.renderComponentsSelected(renderer, volume, localToWorld());
546   }
547   void renderWireframe(Renderer& renderer, const VolumeTest& volume) const
548   {
549     m_contained.renderWireframe(renderer, volume, Instance::localToWorld(), getSelectable().isSelected());
550
551     m_curveNURBS.renderComponentsSelected(renderer, volume, localToWorld());
552     m_curveCatmullRom.renderComponentsSelected(renderer, volume, localToWorld());
553   }
554   void renderComponents(Renderer& renderer, const VolumeTest& volume) const
555   {
556     if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex)
557     {
558       m_curveNURBS.renderComponents(renderer, volume, localToWorld());
559       m_curveCatmullRom.renderComponents(renderer, volume, localToWorld());
560     }
561   }
562
563   void testSelect(Selector& selector, SelectionTest& test)
564   {
565     test.BeginMesh(localToWorld());
566     SelectionIntersection best;
567
568     m_contained.testSelect(selector, test, best);
569
570     if(best.valid())
571     {
572       Selector_add(selector, getSelectable(), best);
573     }
574   }
575
576   bool isSelectedComponents() const
577   {
578     return m_curveNURBS.isSelected() || m_curveCatmullRom.isSelected();
579   }
580   void setSelectedComponents(bool selected, SelectionSystem::EComponentMode mode)
581   {
582     if(mode == SelectionSystem::eVertex)
583     {
584       m_curveNURBS.setSelected(selected);
585       m_curveCatmullRom.setSelected(selected);
586     }
587   }
588   void testSelectComponents(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
589   {
590     if(mode == SelectionSystem::eVertex)
591     {
592       test.BeginMesh(localToWorld());
593       m_curveNURBS.testSelect(selector, test);
594       m_curveCatmullRom.testSelect(selector, test);
595     }
596   }
597
598   void transformComponents(const Matrix4& matrix)
599   {
600     if(m_curveNURBS.isSelected())
601     {
602       m_curveNURBS.transform(matrix);
603     }
604     if(m_curveCatmullRom.isSelected())
605     {
606       m_curveCatmullRom.transform(matrix);
607     }
608   }
609
610   const AABB& getSelectedComponentsBounds() const
611   {
612     m_aabb_component = AABB();
613     m_curveNURBS.forEachSelected(ControlPointAddBounds(m_aabb_component));
614     m_curveCatmullRom.forEachSelected(ControlPointAddBounds(m_aabb_component));
615     return m_aabb_component;
616   }
617
618   void snapComponents(float snap)
619   {
620     if(m_curveNURBS.isSelected())
621     {
622       m_curveNURBS.snapto(snap);
623       m_curveNURBS.write(curve_Nurbs, m_contained.getEntity());
624     }
625     if(m_curveCatmullRom.isSelected())
626     {
627       m_curveCatmullRom.snapto(snap);
628       m_curveCatmullRom.write(curve_CatmullRomSpline, m_contained.getEntity());
629     }
630   }
631
632   void evaluateTransform()
633   {
634     if(getType() == TRANSFORM_PRIMITIVE)
635     {
636       m_contained.translate(getTranslation());
637       m_contained.rotate(getRotation());
638     }
639     else
640     {
641       transformComponents(calculateTransform());
642     }
643   }
644   void applyTransform()
645   {
646     m_contained.revertTransform();
647     evaluateTransform();
648     m_contained.freezeTransform();
649   }
650   typedef MemberCaller<Doom3GroupInstance, &Doom3GroupInstance::applyTransform> ApplyTransformCaller;
651
652   void selectionChangedComponent(const Selectable& selectable)
653   {
654     GlobalSelectionSystem().getObserver(SelectionSystem::eComponent)(selectable);
655     GlobalSelectionSystem().onComponentSelection(*this, selectable);
656   }
657   typedef MemberCaller1<Doom3GroupInstance, const Selectable&, &Doom3GroupInstance::selectionChangedComponent> SelectionChangedComponentCaller;
658 };
659
660 class Doom3GroupNode :
661   public scene::Node::Symbiot,
662   public scene::Instantiable,
663   public scene::Cloneable,
664   public scene::Traversable::Observer
665 {
666   class TypeCasts
667   {
668     NodeTypeCastTable m_casts;
669   public:
670     TypeCasts()
671     {
672       NodeStaticCast<Doom3GroupNode, scene::Instantiable>::install(m_casts);
673       NodeStaticCast<Doom3GroupNode, scene::Cloneable>::install(m_casts);
674       NodeContainedCast<Doom3GroupNode, scene::Traversable>::install(m_casts);
675       NodeContainedCast<Doom3GroupNode, Snappable>::install(m_casts);
676       NodeContainedCast<Doom3GroupNode, TransformNode>::install(m_casts);
677       NodeContainedCast<Doom3GroupNode, Entity>::install(m_casts);
678       NodeContainedCast<Doom3GroupNode, Nameable>::install(m_casts);
679       NodeContainedCast<Doom3GroupNode, Namespaced>::install(m_casts);
680       NodeContainedCast<Doom3GroupNode, ModelSkin>::install(m_casts);
681     }
682     NodeTypeCastTable& get()
683     {
684       return m_casts;
685     }
686   };
687
688
689   scene::Node m_node;
690   InstanceSet m_instances;
691   Doom3Group m_contained;
692
693   void construct()
694   {
695     m_contained.attach(this);
696   }
697   void destroy()
698   {
699     m_contained.detach(this);
700   }
701 public:
702
703   typedef LazyStatic<TypeCasts> StaticTypeCasts;
704
705   scene::Traversable& get(NullType<scene::Traversable>)
706   {
707     return m_contained.getTraversable();
708   }
709   Snappable& get(NullType<Snappable>)
710   {
711     return m_contained;
712   }
713   TransformNode& get(NullType<TransformNode>)
714   {
715     return m_contained.getTransformNode();
716   }
717   Entity& get(NullType<Entity>)
718   {
719     return m_contained.getEntity();
720   }
721   Nameable& get(NullType<Nameable>)
722   {
723     return m_contained.getNameable();
724   }
725   Namespaced& get(NullType<Namespaced>)
726   {
727     return m_contained.getNamespaced();
728   }
729   ModelSkin& get(NullType<ModelSkin>)
730   {
731     return m_contained.getModelSkin();
732   }
733
734   Doom3GroupNode(EntityClass* eclass) :
735     m_node(this, this, StaticTypeCasts::instance().get()),
736       m_contained(eclass, m_node, InstanceSet::TransformChangedCaller(m_instances), InstanceSet::BoundsChangedCaller(m_instances), InstanceSetEvaluateTransform<Doom3GroupInstance>::Caller(m_instances))
737   {
738     construct();
739   }
740   Doom3GroupNode(const Doom3GroupNode& other) :
741     scene::Node::Symbiot(other),
742     scene::Instantiable(other),
743     scene::Cloneable(other),
744     scene::Traversable::Observer(other),
745     m_node(this, this, StaticTypeCasts::instance().get()),
746     m_contained(other.m_contained, m_node, InstanceSet::TransformChangedCaller(m_instances), InstanceSet::BoundsChangedCaller(m_instances), InstanceSetEvaluateTransform<Doom3GroupInstance>::Caller(m_instances))
747   {
748     construct();
749   }
750   ~Doom3GroupNode()
751   {
752     destroy();
753   }
754
755   void release()
756   {
757     delete this;
758   }
759   scene::Node& node()
760   {
761     return m_node;
762   }
763
764   scene::Node& clone() const
765   {
766     return (new Doom3GroupNode(*this))->node();
767   }
768
769   void insert(scene::Node& child)
770   {
771     m_instances.insert(child);
772   }
773   void erase(scene::Node& child)
774   {
775     m_instances.erase(child);
776   }
777
778   scene::Instance* create(const scene::Path& path, scene::Instance* parent)
779   {
780     return new Doom3GroupInstance(path, parent, m_contained);
781   }
782   void forEachInstance(const scene::Instantiable::Visitor& visitor)
783   {
784     m_instances.forEachInstance(visitor);
785   }
786   void insert(scene::Instantiable::Observer* observer, const scene::Path& path, scene::Instance* instance)
787   {
788     m_instances.insert(observer, path, instance);
789   }
790   scene::Instance* erase(scene::Instantiable::Observer* observer, const scene::Path& path)
791   {
792     return m_instances.erase(observer, path);
793   }
794 };
795
796 void Doom3Group_construct()
797 {
798   CurveEdit::Type::instance().m_controlsShader = GlobalShaderCache().capture("$POINT");
799   CurveEdit::Type::instance().m_selectedShader = GlobalShaderCache().capture("$SELPOINT");
800 }
801
802 void Doom3Group_destroy()
803 {
804   GlobalShaderCache().release("$SELPOINT");
805   GlobalShaderCache().release("$POINT");
806 }
807
808 scene::Node& New_Doom3Group(EntityClass* eclass)
809 {
810   return (new Doom3GroupNode(eclass))->node();
811 }