private DomNode CreatePrefab(IEnumerable<IGameObject> gobs) { UniqueNamer uniqueNamer = new UniqueNamer(); DomNode[] temp = new DomNode[1]; List<IGameObject> copyList = new List<IGameObject>(); AABB bound = new AABB(); foreach (IGameObject gameObject in SelectedGobs) { IBoundable boundable = gameObject.As<IBoundable>(); bound.Extend(boundable.BoundingBox); Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject); temp[0] = gameObject.As<DomNode>(); DomNode[] copies = DomNode.Copy(temp); copies[0].InitializeExtensions(); IGameObject copy = copies[0].As<IGameObject>(); copy.Name = uniqueNamer.Name(copy.Name); TransformUtils.SetTransform(copy, world); copyList.Add(copy); } DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement); var list = prefab.GetChildList(Schema.prefabType.gameObjectChild); Vec3F center = bound.Center; foreach (IGameObject gob in copyList) { gob.Translation = gob.Translation - center; gob.UpdateTransform(); list.Add(gob.As<DomNode>()); } return prefab; }
private DomNode CreatePrototype(IEnumerable<IGameObject> gobs) { DomNode[] originals = new DomNode[1]; List<IGameObject> copyList = new List<IGameObject>(); AABB bound = new AABB(); foreach (IGameObject gameObject in SelectedGobs) { IBoundable boundable = gameObject.As<IBoundable>(); bound.Extend(boundable.BoundingBox); Matrix4F world = TransformUtils.ComputeWorldTransform(gameObject); originals[0] = gameObject.As<DomNode>(); DomNode[] copies = DomNode.Copy(originals); IGameObject copy = copies[0].As<IGameObject>(); TransformUtils.SetTransform(copy, world); copyList.Add(copy); } DomNode gobchild = null; if (copyList.Count > 1) {// create group IGame game = m_contextRegistry.GetActiveContext<IGame>(); IGameObjectGroup gobgroup = game.CreateGameObjectGroup(); gobgroup.Translation = bound.Center; gobgroup.UpdateTransform(); Matrix4F worldInv = new Matrix4F(); worldInv.Invert(gobgroup.Transform); foreach (IGameObject gob in copyList) { Vec3F translate = gob.Translation; worldInv.Transform(ref translate); gob.Translation = translate; gob.UpdateTransform(); gobgroup.GameObjects.Add(gob); } gobchild = gobgroup.As<DomNode>(); } else { gobchild = copyList[0].As<DomNode>(); } gobchild.InitializeExtensions(); gobchild.As<IGameObject>().Translation = new Vec3F(0, 0, 0); DomNode prototype = null; if (gobchild != null) { prototype = new DomNode(Schema.prototypeType.Type, Schema.prototypeRootElement); prototype.SetChild(Schema.prototypeType.gameObjectChild, gobchild); } return prototype; }
public void Frame(IEnumerable<object> items) { IEnumerable<DomNode> rootDomNodes = DomNode.GetRoots(items.AsIEnumerable<DomNode>()); AABB bound = new AABB(); foreach (var item in items) { IBoundable boundable = null; DomNode domItem = item.As<DomNode>(); if (domItem != null) { foreach (var node in domItem.Lineage) { boundable = node.As<IBoundable>(); if (boundable != null) break; } } else { Slot slot = item.As<Slot>(); boundable = slot.Owner.As<IBoundable>(); } IVisible vn = boundable.As<IVisible>(); if (boundable != null && (vn == null || vn.Visible)) bound.Extend(boundable.BoundingBox); } if (!bound.IsEmpty) { Sphere3F sphere = bound.ToSphere(); sphere.Radius *= 3.0f; IDesignView designView = Globals.MEFContainer.GetExportedValue<IDesignView>(); Util.ZoomOnSphere(designView.ActiveView.Camera, sphere); } }
/// <summary> /// Groups the specified GameObjects</summary> /// <param name="gobs">GameObjects to be grouped</param> /// <remarks>Creates a new GameObjectGroup and moves all /// the GameObjects into it.</remarks> public IGameObjectGroup Group(IEnumerable<IGameObject> gobs) { // extra check. if (!CanGroup(gobs)) return null; IGame game = null; AABB groupBox = new AABB(); List<IGameObject> gameObjects = new List<IGameObject>(); foreach (IGameObject gameObject in gobs) { if (game == null) { game = gameObject.As<DomNode>().GetRoot().As<IGame>(); } gameObjects.Add(gameObject); IBoundable boundable = gameObject.As<IBoundable>(); groupBox.Extend(boundable.BoundingBox); } IGameObjectGroup group = game.CreateGameObjectGroup(); DomNode node = group.As<DomNode>(); node.InitializeExtensions(); ITransformable transformable = node.As<ITransformable>(); transformable.Translation = groupBox.Center; Matrix4F invWorld = new Matrix4F(); invWorld.Invert(transformable.Transform); game.RootGameObjectFolder.GameObjects.Add(group); foreach (IGameObject gameObject in gameObjects) { ITransformable xformable = gameObject.As<ITransformable>(); Matrix4F world = ComputeWorldTransform(xformable); SetTransform(xformable, world); group.GameObjects.Add(gameObject); Vec3F trans = world.Translation; invWorld.Transform(ref trans); xformable.Translation = trans; } return group; }