Beispiel #1
0
        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);
        }
Beispiel #2
0
        public Point WorldToSurfaceSpace(Vec3F posW)
        {
            // convert posW from world space to heightmap space.
            Matrix4F xform = TransformUtils.ComputeWorldTransform(this.As <ITransformable>());
            Vec3F    posH  = posW - xform.Translation;

            return(new Point((int)Math.Round(posH.X / CellSize), (int)Math.Round(posH.Z / CellSize)));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        private DomNode CreatePrefab(IEnumerable <object> gobs)
        {
            UniqueNamer uniqueNamer = new UniqueNamer();

            DomNode[] temp     = new DomNode[1];
            var       copyList = new List <object>();
            AABB      bound    = new AABB();

            foreach (var gameObject in SelectedGobs)
            {
                IBoundable boundable = gameObject.As <IBoundable>();
                bound.Extend(boundable.BoundingBox);

                var trans = gameObject.As <ITransformable>();
                var world = (trans != null) ? TransformUtils.ComputeWorldTransform(trans) : Matrix4F.Identity;

                temp[0] = gameObject.As <DomNode>();
                DomNode[] copies = DomNode.Copy(temp);
                copies[0].InitializeExtensions();

                var nameable = copies[0].As <INameable>();
                if (nameable != null)
                {
                    nameable.Name = uniqueNamer.Name(nameable.Name);
                }

                var copyTrans = copies[0].As <ITransformable>();
                if (copyTrans != null)
                {
                    TransformUtils.SetTransform(copyTrans, world);
                }
                copyList.Add(copies[0]);
            }

            DomNode prefab = new DomNode(Schema.prefabType.Type, Schema.prefabRootElement);
            var     list   = prefab.GetChildList(Schema.prefabType.gameObjectChild);
            Vec3F   center = bound.Center;

            foreach (var gob in copyList)
            {
                var trans = gob.As <ITransformable>();
                if (trans != null)
                {
                    trans.Translation = trans.Translation - center;
                    trans.UpdateTransform();
                }
                var node = gob.As <DomNode>();
                if (node != null)
                {
                    list.Add(node);
                }
            }
            return(prefab);
        }