示例#1
0
        protected override void DrawInternal()
        {
            GUIControlHandle handle = GUIExtensions.GetControlHandle(FocusType.Passive);

            Texture2D  texture            = this.GetContents <Texture2D>();
            Vector3    position           = this.GetAuxContents <Vector3>("position");
            Quaternion rotation           = this.GetAuxContents <Quaternion>("rotation");
            Vector2    size               = this.GetAuxContents <Vector2>("size");
            bool       is_overlay_enabled = this.GetAuxContents <bool>("is_overlay_enabled");

            Surface <Color> surface = texture.GetSurface();
            Utensil <Color> utensil = Painter.GetInstance().GetUtensil();

            Matrix4x4 transform     = Matrix4x4.TRS(position, rotation, size.GetSpacar(1.0f));
            Matrix4x4 inv_transform = transform.inverse;

            Vector3 world_point = Camera.current.ScreenToWorldPlanePoint(
                transform.MultiplyPlane(PlaneExtensions.CreateNormalAndPoint(new Vector3(0.0f, 0.0f, 1.0f), Vector3.zero)),
                handle.GetEvent().mousePosition.ConvertFromGUIToScreen()
                );

            Vector3 local_point   = inv_transform.MultiplyPoint(world_point);
            Vector2 texture_point = local_point.GetComponentMultiply(texture.GetSize()).GetPlanar() + 0.5f * texture.GetSize();

            Vector3 brush_size = new Vector2(Painter.GetInstance().GetBrushSize(), Painter.GetInstance().GetBrushSize())
                                 .GetComponentDivide(texture.GetSize())
                                 .GetComponentMultiply(size)
                                 .GetSpacar(1.0f);

            if (handle.IsControlCaptured() && is_overlay_enabled)
            {
                surface_now_mesh.GetMaterial().SetMainTexture(texture);
                surface_now_mesh.Draw(transform);
            }

            brush_now_mesh.Draw(world_point, rotation, brush_size);

            if (handle.GetEventType().IsMouseRelated() && handle.GetEvent().button == 0)
            {
                if (handle.GetEventType() == EventType.MouseDown)
                {
                    handle.CaptureControl();

                    this.Execute("MouseDown");
                    last_texture_point = texture_point;
                }

                if (handle.GetEventType() == EventType.MouseUp)
                {
                    handle.ReleaseControl();

                    this.Execute("MouseUp");
                }

                if (handle.IsControlCaptured())
                {
                    line_tool.MarkLines(surface, utensil, last_texture_point.GetVectorF2(), texture_point.GetVectorF2());
                    texture.Apply();
                }

                last_texture_point = texture_point;
                handle.UseEvent();
            }
        }
示例#2
0
        /// <summary>
        /// Constructs a <see cref="MapBrushSide"/> object using the provided <c>string</c> array as the data.
        /// </summary>
        /// <param name="lines">Data to parse.</param>
        public MapBrushSide(IReadOnlyList <string> lines)
        {
            // If lines.Length is 1, then this line contains all data for a brush side
            if (lines.Count == 1)
            {
                string[] tokens = lines[0].SplitUnlessInContainer(' ', '\"', StringSplitOptions.RemoveEmptyEntries);

                // If this succeeds, assume brushDef3
                if (float.TryParse(tokens[4], out float dist))
                {
                    plane       = new Plane(new Vector3(float.Parse(tokens[1], _format), float.Parse(tokens[2], _format), float.Parse(tokens[3], _format)), dist);
                    textureInfo = new TextureInfo(new Vector3(float.Parse(tokens[8], _format), float.Parse(tokens[9], _format), float.Parse(tokens[10], _format)),
                                                  new Vector3(float.Parse(tokens[13], _format), float.Parse(tokens[14], _format), float.Parse(tokens[15], _format)),
                                                  new Vector2(0, 0),
                                                  new Vector2(1, 1),
                                                  0, 0, 0);
                    texture = tokens[18];
                }
                else
                {
                    Vector3 v1 = new Vector3(float.Parse(tokens[1], _format), float.Parse(tokens[2], _format), float.Parse(tokens[3], _format));
                    Vector3 v2 = new Vector3(float.Parse(tokens[6], _format), float.Parse(tokens[7], _format), float.Parse(tokens[8], _format));
                    Vector3 v3 = new Vector3(float.Parse(tokens[11], _format), float.Parse(tokens[12], _format), float.Parse(tokens[13], _format));
                    vertices = new[] { v1, v2, v3 };
                    plane    = PlaneExtensions.CreateFromVertices(v1, v2, v3);
                    texture  = tokens[15];
                    // GearCraft
                    if (tokens[16] == "[")
                    {
                        textureInfo = new TextureInfo(new Vector3(float.Parse(tokens[17], _format), float.Parse(tokens[18], _format), float.Parse(tokens[19], _format)),
                                                      new Vector3(float.Parse(tokens[23], _format), float.Parse(tokens[24], _format), float.Parse(tokens[25], _format)),
                                                      new Vector2(float.Parse(tokens[20], _format), float.Parse(tokens[26], _format)),
                                                      new Vector2(float.Parse(tokens[29], _format), float.Parse(tokens[30], _format)),
                                                      int.Parse(tokens[31]), 0, float.Parse(tokens[28], _format));
                        material = tokens[32];
                    }
                    else
                    {
                        //<x_shift> <y_shift> <rotation> <x_scale> <y_scale> <content_flags> <surface_flags> <value>
                        Vector3[] axes = TextureInfo.TextureAxisFromPlane(plane);
                        textureInfo = new TextureInfo(axes[0],
                                                      axes[1],
                                                      new Vector2(float.Parse(tokens[16], _format), float.Parse(tokens[17], _format)),
                                                      new Vector2(float.Parse(tokens[19], _format), float.Parse(tokens[20], _format)),
                                                      int.Parse(tokens[22]), 0, float.Parse(tokens[18], _format));
                    }
                }
            }
            else
            {
                bool inDispInfo = false;
                int  braceCount = 0;
                textureInfo = new TextureInfo();
                List <string> child = new List <string>(37);
                foreach (string line in lines)
                {
                    switch (line)
                    {
                    case "{":
                        ++braceCount;
                        break;

                    case "}":
                    {
                        --braceCount;
                        if (braceCount == 1)
                        {
                            child.Add(line);
                            displacement = new MapDisplacement(child.ToArray());
                            child        = new List <string>(37);
                            inDispInfo   = false;
                        }

                        break;
                    }

                    case "dispinfo":
                        inDispInfo = true;
                        continue;
                    }

                    if (braceCount == 1)
                    {
                        string[] tokens = line.SplitUnlessInContainer(' ', '\"', StringSplitOptions.RemoveEmptyEntries);
                        switch (tokens[0])
                        {
                        case "material": {
                            texture = tokens[1];
                            break;
                        }

                        case "plane": {
                            string[] points     = tokens[1].SplitUnlessBetweenDelimiters(' ', '(', ')', StringSplitOptions.RemoveEmptyEntries);
                            string[] components = points[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            Vector3  v1         = new Vector3(float.Parse(components[0], _format), float.Parse(components[1], _format), float.Parse(components[2], _format));
                            components = points[1].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            Vector3 v2 = new Vector3(float.Parse(components[0], _format), float.Parse(components[1], _format), float.Parse(components[2], _format));
                            components = points[2].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            Vector3 v3 = new Vector3(float.Parse(components[0], _format), float.Parse(components[1], _format), float.Parse(components[2], _format));
                            plane = PlaneExtensions.CreateFromVertices(v1, v2, v3);
                            break;
                        }

                        case "uaxis": {
                            string[] split = tokens[1].SplitUnlessBetweenDelimiters(' ', '[', ']', StringSplitOptions.RemoveEmptyEntries);
                            textureInfo.scale       = new Vector2(float.Parse(split[1], _format), textureInfo.scale.Y());
                            split                   = split[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            textureInfo.UAxis       = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
                            textureInfo.Translation = new Vector2(float.Parse(split[3], _format), textureInfo.Translation.Y());
                            break;
                        }

                        case "vaxis": {
                            string[] split = tokens[1].SplitUnlessBetweenDelimiters(' ', '[', ']', StringSplitOptions.RemoveEmptyEntries);
                            textureInfo.scale       = new Vector2(textureInfo.scale.X(), float.Parse(split[1], _format));
                            split                   = split[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            textureInfo.VAxis       = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
                            textureInfo.Translation = new Vector2(textureInfo.Translation.X(), float.Parse(split[3], _format));
                            break;
                        }

                        case "rotation": {
                            textureInfo.rotation = float.Parse(tokens[1], _format);
                            break;
                        }
                        }
                    }
                    else if (braceCount > 1)
                    {
                        if (inDispInfo)
                        {
                            child.Add(line);
                        }
                    }
                }
            }
        }