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