Пример #1
0
        public void AddToScene()
        {
            if (!foundOffset)
            {
                terrainOffset = position.y - app.GetTerrainHeight(Position.x, Position.z);
                foundOffset   = true;
            }
            if (app.DisplayPointLightMarker)
            {
                this.DisplayPointLightMarker();
                if (displayObject.Entity.Mesh.TriangleIntersector == null)
                {
                    displayObject.Entity.Mesh.CreateTriangleIntersector();
                }
            }
            string uniqueName = WorldEditor.GetUniqueName(ObjectType, name);

            pLight           = this.scene.CreateLight(uniqueName);
            pLight.Type      = Axiom.Graphics.LightType.Point;
            pLight.Position  = position;
            pLight.Specular  = specular;
            pLight.Diffuse   = diffuse;
            pLight.IsVisible = true;
            pLight.SetAttenuation(attenuationRange, attenuationConstant, attenuationLinear, attenuationQuadratic);
            inScene = true;
            if (app.DisplayPointLightCircles)
            {
                UpdateShowCircles();
            }
        }
 public void SetFocus(Vector2 focusLoc)
 {
     position.x = focusLoc.x + focusOffset.x;
     position.z = focusLoc.y + focusOffset.y;
     position.y = app.GetTerrainHeight(position.x, position.z);
     if (inScene)
     {
         this.displayObject.Position = position;
     }
 }
Пример #3
0
        public void MultipleDragMove(WorldEditor app, int x, int y)
        {
            int i = 0;

            location = app.PickTerrain(x, y);
            Vector3 position;

            foreach (IObjectDrag disObject in dragObjects)
            {
                switch (disObject.ObjectType)
                {
                case "PointLight":
                case "Marker":
                case "Object":
                    position = location + dragOffset[i];
                    if (i == 0)
                    {
                        if (disObject.AllowAdjustHeightOffTerrain)
                        {
                            position = app.ObjectPlacementLocation(x, y) + new Vector3(0, terrainOffset[i], 0);
                        }
                        else
                        {
                            position = app.ObjectPlacementLocation(x, y);
                        }
                        disObject.Position = position;
                        break;
                    }
                    else
                    {
                        if (disObject.AllowAdjustHeightOffTerrain)
                        {
                            position = app.ObjectPlacementLocation(location + dragOffset[i]) + new Vector3(0, terrainOffset[i], 0);
                        }
                        else
                        {
                            position = app.ObjectPlacementLocation(location + dragOffset[i]);
                        }
                        disObject.Position = position;
                        break;
                    }

                default:
                    position           = location + dragOffset[i];
                    position.y         = app.GetTerrainHeight(location.x, location.z);
                    disObject.Position = position;
                    if (String.Equals(disObject.ObjectType, "Points") && (disObject as PointCollection).DisplayMarkers != true)
                    {
                        (disObject as PointCollection).DisplayMarkers = true;
                    }
                    break;
                }
                if (!disObject.InScene)
                {
                    (disObject as IWorldObject).AddToScene();
                }
                i++;
            }
        }
Пример #4
0
 public void DragMove(WorldEditor app, int x, int y)
 {
     if (dragging)
     {
         location            = app.PickTerrain(x, y);
         location.y          = app.GetTerrainHeight(location.x, location.z) + dragObject.TerrainOffset;
         dragObject.Position = location;
     }
 }
Пример #5
0
        private bool DragCallback(bool accept, Vector3 loc)
        {
            placing = false;
            int i = 0;

            foreach (IObjectDrag obj in dragObjects.DragList)
            {
                (obj as IWorldObject).RemoveFromScene();
                pasteObjects[i].Position = loc + dragOffset[i];
                if (pasteObjects[i].AllowAdjustHeightOffTerrain)
                {
                    pasteObjects[i].Position = new Vector3(obj.Position.x, app.GetTerrainHeight(obj.Position.x, obj.Position.z) +
                                                           terrainOffset[i], obj.Position.z);
                }
                else
                {
                    if (pasteObjects[i] is Waypoint || pasteObjects[i] is StaticObject || pasteObjects[i] is PointLight)
                    {
                        pasteObjects[i].Position = new Vector3(obj.Position.x, pasteObjects[i].Position.y, obj.Position.z);
                    }
                    else
                    {
                        pasteObjects[i].Position = new Vector3(obj.Position.x, app.GetTerrainHeight(obj.Position.x, obj.Position.z),
                                                               obj.Position.z);
                    }
                }
                switch (obj.ObjectType)
                {
                case "Points":
                    (obj as PointCollection).Dispose();
                    break;
                }
                parents[i].Add(pasteObjects[i]);
                pasteObjects[i].Parent = parents[i];
                i++;
            }
            return(true);
        }
        public bool DragCallback(bool accept, Vector3 loc)
        {
            placing        = false;
            placedPosition = loc;
            Vector3 location = loc;

            if (accept)
            {
                if (type == MPPointType.Boundary)
                {
                    if ((((obj).Parent) as PointCollection).NoIntersect)
                    {
                        PointCollection pc   = obj.Parent as PointCollection;
                        int             i    = 0;
                        List <Vector3>  list = new List <Vector3>();
                        foreach (Vector3 point in pc.VectorList)
                        {
                            if (i == obj.PointNum)
                            {
                                list.Add(location);
                            }
                            else
                            {
                                list.Add(point);
                            }
                            i++;
                        }
                        if (IntersectionHelperClass.BoundaryIntersectionSearch(obj.PointNum, list))
                        {
                            ErrorHelper.SendUserError("Unable to move point to that Position", "Region", app.Config.ErrorDisplayTimeDefault, true, (object)obj, app);
                            obj.Position       = origPosition;
                            app.MouseDragEvent = false;
                            return(true);
                        }
                    }
                }
                loc.y          = app.GetTerrainHeight(loc.x, loc.z);
                placedPosition = loc;
                obj.Position   = loc;

                app.MouseDragEvent = false;
                return(true);
            }
            obj.Position       = origPosition;
            app.MouseDragEvent = false;
            return(false);
        }
        public void AddToScene()
        {
            float x = parent.FocusLocation.x;
            float z = parent.FocusLocation.z;

            Vector3 location = new Vector3(x, app.GetTerrainHeight(x, z) + 2000, z);

            displayObject = new DisplayObject(String.Format("{0}-{1}", parent.Name, "DirectionalLight"), app, "DirectionalLight", app.Scene, (app.Assets.assetFromName(app.Config.DirectionalLightMeshName)).AssetName, location, new Vector3(1, 1, 1), this.Orientation, null);
            inScene       = true;

            UpdateOrientation();

            if (displayObject.Entity.Mesh.TriangleIntersector == null)
            {
                displayObject.Entity.Mesh.CreateTriangleIntersector();
            }
        }
        public void Execute()
        {
            if (placing)
            {
                foreach (IObjectDrag obj in dragObject)
                {
                    dragOffset.Add((obj as IObjectDrag).Position - (hitObject as IObjectDrag).Position);
                    switch (obj.ObjectType)
                    {
                    case "Road":
                        (obj as RoadObject).Points.Clone(dragObjects as IWorldContainer);
                        terrainOffset.Add(0f);
                        (obj as IWorldObject).RemoveFromScene();
                        break;

                    case "Region":
                        (obj as Boundary).Points.Clone(dragObjects as IWorldContainer);
                        terrainOffset.Add(0f);
                        (obj as IWorldObject).RemoveFromScene();
                        break;

                    case "TerrainDecal":
                        dragObjects.Add(obj as IWorldObject);
                        terrainOffset.Add(0f);
                        break;

                    case "Marker":
                    case "Object":
                    case "PointLight":
                        dragObjects.Add(obj as IWorldObject);
                        if (obj.AllowAdjustHeightOffTerrain)
                        {
                            terrainOffset.Add((obj as IObjectDrag).TerrainOffset);
                        }
                        else
                        {
                            terrainOffset.Add(0f);
                        }
                        break;
                    }
                }
                if (dragObject.Count > 0)
                {
                    new DragHelper(app, dragObjects.DragList, dragOffset, terrainOffset, DragCallback, true);
                }
                else
                {
                    return;
                }
            }
            else
            {
                int i = 0;
                foreach (IObjectDrag obj in dragObject)
                {
                    Vector3 position = placePosition[i];
                    if (obj.AllowAdjustHeightOffTerrain)
                    {
                        position.y = ((app.GetTerrainHeight(obj.Position.x, obj.Position.z)) + terrainOffset[i]);
                    }
                    else
                    {
                        position.y = app.GetTerrainHeight(obj.Position.x, obj.Position.z);
                    }
                    obj.Position = position;
                    i++;
                }
            }
        }
        protected void FromXml(XmlReader r)
        {
            // first parse the attributes

            bool adjustHeightFound = false;

            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                case "Name":
                    this.name = r.Value;
                    break;

                //case "Sound":
                //    this.soundAssetName = r.Value;
                //    break;
                case "TerrainOffset":
                    offsetFound   = true;
                    terrainOffset = float.Parse(r.Value);
                    break;

                case "AllowHeightAdjustment":
                    adjustHeightFound = true;
                    if (String.Equals(r.Value.ToLower(), "false"))
                    {
                        allowAdjustHeightOffTerrain = false;
                    }
                    break;

                case "Azimuth":
                    azimuth = float.Parse(r.Value);
                    break;

                case "Zenith":
                    zenith = float.Parse(r.Value);
                    break;

                case "WorldViewSelect":
                    worldViewSelectable = bool.Parse(r.Value);
                    break;
                }
            }
//            this.nameValuePairs = new NameValueObject();
            r.Read();
            do
            {
                if (r.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }
                if (r.NodeType == XmlNodeType.Element)
                {
                    switch (r.Name)
                    {
                    case "Position":
                        this.position = XmlHelperClass.ParseVectorAttributes(r);
                        break;

                    case "Orientation":
                        orientation = XmlHelperClass.ParseQuaternion(r);
                        break;

                    case "NameValuePairs":
                        this.nameValuePairs = new NameValueObject(r);
                        break;

                    case "ParticleEffect":
                        ParticleEffect particle = new ParticleEffect(r, this, app);
                        Add(particle);
                        break;

                    case "SpawnGen":
                        SpawnGen mob = new SpawnGen(r, app, this);
                        Add(mob);
                        break;

                    case "Sound":
                        Sound sound = new Sound(r, this, app);
                        Add(sound);
                        break;

                    case "Color":
                        Color = XmlHelperClass.ParseColorAttributes(r);
                        break;
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
            } while (r.Read());
            if (!adjustHeightFound)
            {
                allowAdjustHeightOffTerrain = true;
            }
            if (!offsetFound)
            {
                terrainOffset = this.Position.y - app.GetTerrainHeight(position.x, position.z);
            }

            if (orientation != null && disp != null)
            {
                disp.SetOrientation(orientation);
                foreach (IWorldObject obj in children)
                {
                    if (obj is ParticleEffect)
                    {
                        (obj as ParticleEffect).Orientation = this.orientation;
                    }
                }
            }
        }
Пример #10
0
        protected void FromXml(XmlReader r)
        {
            bool adjustHeightFound = false;
            bool offsetFound       = false;
            bool pRFound           = false;

            // first parse name and mesh, which are attributes
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                case "Name":
                    this.name = r.Value;
                    break;

                case "Mesh":
                    this.meshName = r.Value;
                    break;

                case "Sound":
                    string filename = r.Value;
                    if (!String.Equals(filename, ""))
                    {
                        ICommandFactory ret = new AddSoundCommandFactory(app, this, r.Value);
                        ICommand        com = ret.CreateCommand();
                        com.Execute();
                    }
                    break;

                case "TerrainOffset":
                    terrainOffset = float.Parse(r.Value);
                    offsetFound   = true;
                    break;

                case "AllowHeightAdjustment":
                    if (String.Equals(r.Value.ToLower(), "false"))
                    {
                        allowAdjustHeightOffTerrain = false;
                    }
                    break;

                case "AcceptObjectPlacement":
                    acceptObjectPlacement = bool.Parse(r.Value);
                    break;

                case "PerceptionRadius":
                    pRFound          = true;
                    perceptionRadius = float.Parse(r.Value);
                    break;

                case "CastShadows":
                    castShadows = bool.Parse(r.Value);
                    break;

                case "ReceiveShadows":
                    receiveShadows = bool.Parse(r.Value);
                    break;

                case "Azimuth":
                    azimuth = float.Parse(r.Value);
                    break;

                case "Zenith":
                    zenith = float.Parse(r.Value);
                    break;

                case "WorldViewSelect":
                    worldViewSelectable = bool.Parse(r.Value);
                    break;

                case "Targetable":
                    targetable = bool.Parse(r.Value);
                    break;
                }
            }
            r.MoveToElement(); //Moves the reader back to the element node.

            // now parse the sub-elements
            while (r.Read())
            {
                // look for the start of an element
                if (r.NodeType == XmlNodeType.Element)
                {
                    // parse that element
                    // save the name of the element
                    string elementName = r.Name;
                    switch (elementName)
                    {
                    case "Position":
                        location = XmlHelperClass.ParseVectorAttributes(r);
                        break;

                    case "Scale":
                        scale = XmlHelperClass.ParseVectorAttributes(r);
                        break;

                    case "Rotation":
                        Vector3 rotation = XmlHelperClass.ParseVectorAttributes(r);
                        // force rotation to be between -180 and 180
                        while (rotation.y < -180)
                        {
                            rotation.y += 360;
                        }
                        while (rotation.y > 180)
                        {
                            rotation.y -= 360;
                        }
                        SetDirection(rotation.y, 90f);
                        break;

                    case "Orientation":
                        orientation = XmlHelperClass.ParseQuaternion(r);
                        break;

                    case "SubMeshes":
                        subMeshes = new SubMeshCollection(r);
                        if (!subMeshes.CheckValid(app, meshName))
                        {
                            app.AddPopupMessage(string.Format("Some submesh names in {0} changed.  Submesh display and material parameters for this object were reset.", meshName));

                            // if the check fails, then reset the subMeshes from the mesh
                            subMeshes = new SubMeshCollection(meshName);
                        }
                        break;

                    case "NameValuePairs":
                        nameValuePairs = new NameValueObject(r);
                        break;

                    case "ParticleEffect":
                        ParticleEffect particle = new ParticleEffect(r, this, app);
                        Add(particle);
                        break;

                    case "PathData":
                        pathData      = new PathData(r);
                        locationDirty = pathData.Version != pathData.CodeVersion;
                        break;

                    case "Sound":
                        Sound sound = new Sound(r, this, app);
                        Add(sound);
                        break;
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
            }
            if (!adjustHeightFound)
            {
                allowAdjustHeightOffTerrain = true;
            }
            if (!offsetFound)
            {
                terrainOffset = location.y - app.GetTerrainHeight(location.x, location.z);
            }
            if (!pRFound && nameValuePairs != null)
            {
                valueItem value = nameValuePairs.LookUp("perceptionRadius");
                if (value != null && ValidityHelperClass.isFloat(value.value))
                {
                    perceptionRadius = float.Parse(value.value);
                }
            }
            return;
        }