Ejemplo n.º 1
0
        public static float GetComponent(Channel c, V4 color)
        {
            float r = 0;
            float w = 0;

            if (c.HasFlag(Channel.One))
            {
                r += 1; w += 1;
            }
            if (c.HasFlag(Channel.Red))
            {
                r += color.X; w += 1;
            }
            if (c.HasFlag(Channel.Green))
            {
                r += color.Y; w += 1;
            }
            if (c.HasFlag(Channel.Blue))
            {
                r += color.Z; w += 1;
            }
            if (c.HasFlag(Channel.Alpha))
            {
                r += color.W; w += 1;
            }

            return(w == 0 ? 0 : r / w);
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append('{');

            WriteName(sb, "V0");
            sb.Append(V0.ToString() + ",");
            WriteName(sb, "V1");
            sb.Append(V1.ToString() + ",");
            WriteName(sb, "V2");
            sb.Append(V2.ToString() + ",");
            WriteName(sb, "V3");
            sb.Append(V3.ToString() + ",");
            WriteName(sb, "V4");
            sb.Append(V4.ToString() + ",");
            WriteName(sb, "V5");
            sb.Append(V5.ToString() + ",");
            WriteName(sb, "V6");
            sb.Append(V6.ToString() + ",");
            WriteName(sb, "V7");
            sb.Append(V7.ToString() + ",");
            WriteName(sb, "V8");
            sb.Append(V8.ToString() + ",");
            WriteName(sb, "V9");
            sb.Append(V9.ToString() + ",");
            sb.Length--;

            sb.Append('}');
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        internal static V4 UnPremultiply(this V4 source)
        {
            float w = source.W;
            var   unpremultiplied = source / w;

            return(unpremultiplied.WithW(w));
        }
Ejemplo n.º 4
0
        internal static V4 Premultiply(this V4 source)
        {
            float w             = source.W;
            var   premultiplied = source * w;

            return(premultiplied.WithW(w));
        }
Ejemplo n.º 5
0
 static void Check(V4 v4, float x, float y, float z, float w, [CallerLineNumber] int line = 0)
 {
     s_checks++;
     if ((v4.x != x) || (v4.y != y) || (v4.z != z) || (v4.w != w))
     {
         s_errors++;
         Console.WriteLine($"Check at line {line} failed; have ({v4.x},{v4.y},{v4.z},{v4.w}); expected ({x},{y},{z},{w})");
     }
 }
Ejemplo n.º 6
0
        public override int GetHashCode()
        {
            int hash_1 = V1.GetHashCode();
            int hash_2 = V2.GetHashCode();
            int hash_3 = V3.GetHashCode();
            int hash_4 = V4.GetHashCode();

            return(hash_1 ^ hash_2 ^ hash_3 ^ hash_4);
        }
Ejemplo n.º 7
0
 public static V4 Multiply(V4 v, M m)
 {
     return(new V4(
                m.M11 * v.X + m.M12 * v.Y + m.M13 * v.Z + m.M14 * v.W,
                m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z + m.M24 * v.W,
                m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z + m.M34 * v.W,
                m.M41 * v.X + m.M42 * v.Y + m.M43 * v.Z + m.M44 * v.W
                ));
 }
Ejemplo n.º 8
0
        public static JToken toJSON(V4 <V4 <float> > v)
        {
            var obj = new JObject();

            obj["x"] = toJSON(v.x);
            obj["y"] = toJSON(v.y);
            obj["z"] = toJSON(v.z);
            obj["w"] = toJSON(v.w);
            return(obj);
        }
Ejemplo n.º 9
0
 public V4 ShuffleComponents(V4 color)
 {
     return(new V4
            (
                GetComponent(Red, color),
                GetComponent(Green, color),
                GetComponent(Blue, color),
                GetComponent(Alpha, color)
            ));
 }
Ejemplo n.º 10
0
    static void TestV4B()
    {
        Vector4 g4  = G4();
        V4      v4b = new V4();

        v4b.x = g4.Y;
        v4b.y = g4.X;
        v4b.z = g4.W;
        v4b.w = g4.Z;
        Check(v4b, g4Y, g4X, g4W, g4Z);
    }
Ejemplo n.º 11
0
    static void TestV4D()
    {
        Vector3 g3  = G3();
        V4      v4d = new V4();

        v4d.x = g3.X;
        v4d.y = g3.Y;
        v4d.z = g3.Z;
        v4d.w = f1;
        Check(v4d, g3X, g3Y, g3Z, f1);
    }
Ejemplo n.º 12
0
    static void TestV4E()
    {
        Vector2 g2  = G2();
        V4      v4e = new V4();

        v4e.x = f0;
        v4e.y = g2.X;
        v4e.z = g2.Y;
        v4e.w = f1;
        Check(v4e, f0, g2X, g2Y, f1);
    }
Ejemplo n.º 13
0
    static void TestV4F()
    {
        Vector2 g2  = G2();
        V4      v4f = new V4();

        v4f.x = f0;
        v4f.y = f1;
        v4f.z = g2.X;
        v4f.w = g2.Y;
        Check(v4f, f0, f1, g2X, g2Y);
    }
Ejemplo n.º 14
0
    static void TestV4A()
    {
        Vector4 g4  = G4();
        V4      v4a = new V4();

        v4a.x = g4.X;
        v4a.y = g4.Y;
        v4a.z = g4.Z;
        v4a.w = g4.W;
        Check(v4a, g4X, g4Y, g4Z, g4W);
    }
Ejemplo n.º 15
0
    static void TestV4G()
    {
        Vector3 g3  = G3();
        V4      v4g = new V4();

        v4g.x = f1;
        v4g.y = g3.X;
        v4g.z = g3.Y;
        v4g.w = g3.Z;
        Check(v4g, f1, g3X, g3Y, g3Z);
    }
Ejemplo n.º 16
0
    static void TestV4H()
    {
        Vector4 g4  = G4();
        V4      v4h = new V4();

        v4h.y = g4.Y;
        v4h.x = g4.X;
        v4h.w = g4.W;
        v4h.z = g4.Z;
        Check(v4h, g4X, g4Y, g4Z, g4W);
    }
Ejemplo n.º 17
0
    static void TestV4C()

    {
        Vector2 g2  = G2();
        V4      v4c = new V4();

        v4c.x = g2.X;
        v4c.y = g2.Y;
        v4c.z = g2.X;
        v4c.w = g2.Y;
        Check(v4c, g2X, g2Y, g2X, g2Y);
    }
Ejemplo n.º 18
0
 private void Start()
 {
     goList = new List <V4>();
     for (int i = 0; i < count; ++i)
     {
         Vector3 v3 = new Vector3(i % 2000, 1, i / 1000);
         V4      v4 = new V4(v3.x, v3.y, v3.z, 1);
         goList.Add(v4);
     }
     indirectArgs[0] = mesh.GetIndexCount(0);
     argsBuffer      = new ComputeBuffer(1, indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
     buffer          = new ComputeBuffer(count, 16);
 }
Ejemplo n.º 19
0
    public void Execute(int index)
    {
        var rng = rngs[threadId];


        float x_value = Corner_bottom_left.x + rng.NextFloat(0, Width);
        float y_value = 1.2f + rng.NextFloat(0f, 1f);
        float z_value = Corner_bottom_left.z + rng.NextFloat(0, Height);

        rngs[threadId] = rng;

        // Preparing V4 format of the nativearray
        Array[index] = new V4(new Vector3(x_value, y_value, z_value), 0);
    }
        public void TestEchoAsyncTasksAutoRegisterType()
        {
            var v3 = _grid1.GetCompute().ExecuteJavaTaskAsync <V3>(ComputeApiTest.EchoTask, EchoTypeV3Action).Result;

            Assert.AreEqual("V3", v3.Name);

            var arg = new V4 {
                Name = "V4"
            };

            var v4 = _grid1.GetCompute().ExecuteJavaTaskAsync <V4>(ComputeApiTest.EchoArgTask, arg).Result;

            Assert.AreEqual(arg.Name, v4.Name);
        }
 // Use this for initialization
 void Start()
 {
     if (BuyCarScript.V01A == 0)
     {
         BuyCarScript.V01A = 2;
     }
     if (BuyCarScript.V01A == 2)
     {
         V1.SetActive(true);
     }
     if (BuyCarScript.V02A == 2)
     {
         V2.SetActive(true);
     }
     if (BuyCarScript.V03A == 2)
     {
         V3.SetActive(true);
     }
     if (BuyCarScript.V04A == 2)
     {
         V4.SetActive(true);
     }
     if (BuyCarScript.V05A == 2)
     {
         V5.SetActive(true);
     }
     if (BuyCarScript.V06A == 2)
     {
         V6.SetActive(true);
     }
     if (BuyCarScript.V07A == 2)
     {
         V7.SetActive(true);
     }
     if (BuyCarScript.V08A == 2)
     {
         V8.SetActive(true);
     }
     if (BuyCarScript.V09A == 2)
     {
         V9.SetActive(true);
     }
     if (BuyCarScript.V10A == 2)
     {
         V10.SetActive(true);
     }
     car = true;
 }
    private void Update()
    {
        dataList.Clear();
        for (int i = 0; i < count; i++)
        {
            Vector3 v3 = transList[i].position;
            V4      v  = new V4(v3.x, v3.y, v3.z, 1);
            dataList.Add(v);
        }
        indirectArgs[1] = (uint)count;
        argsBuffer.SetData(indirectArgs);
        buffer.SetData(dataList, 0, 0, count);
        mat.SetBuffer("objectPositionsBuffer", buffer);

        Graphics.DrawMeshInstancedIndirect(mesh, 0, mat, new Bounds(Vector3.zero, 10000 * Vector3.one), argsBuffer, 0, new MaterialPropertyBlock(), UnityEngine.Rendering.ShadowCastingMode.On, true);
    }
Ejemplo n.º 23
0
        public ABFPVertex()
        {
            ID       = -1;
            IsBorder = false;

            Position = new V3();
            Normal   = new V3();
            UV       = new V2();
            UVA1     = new V4();
            UVA2     = new V4();
            UVA3     = new V4();
            UVA4     = new V4();

            SDEF_C  = new V3();
            SDEF_R0 = new V3();
            SDEF_R1 = new V3();
        }
Ejemplo n.º 24
0
        public static V4 LerpRGBA(this V4 a, V4 b, float amountOfB) // LerpRGBA
        {
            System.Diagnostics.Debug.Assert(a._IsReal());
            System.Diagnostics.Debug.Assert(b._IsReal());
            System.Diagnostics.Debug.Assert(amountOfB._IsReal());
            System.Diagnostics.Debug.Assert(amountOfB._IsInRange(0, 1));

            var amountOfA = 1.0f - amountOfB;

            if (a.W == 0)
            {
                return(new V4(b.X, b.Y, b.Z, b.W * amountOfB));
            }
            if (b.W == 0)
            {
                return(new V4(a.X, a.Y, a.Z, a.W * amountOfA));
            }

            return(a * amountOfA + b * amountOfB);
        }
 public void Left()
 {
     if (V2.activeInHierarchy == true)
     {
         V1.SetActive(true);    V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V3.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(true);    V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V4.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(true);    V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V5.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(true);    V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V6.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(true);    V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V7.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(true);    V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V8.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(true);    V8.SetActive(false);   V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V9.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(true);    V9.SetActive(false);   V10.SetActive(false);
     }
     else if (V10.activeInHierarchy == true)
     {
         V1.SetActive(false);   V2.SetActive(false);   V3.SetActive(false);   V4.SetActive(false);   V5.SetActive(false);   V6.SetActive(false);   V7.SetActive(false);   V8.SetActive(false);   V9.SetActive(true);    V10.SetActive(false);
     }
 }
Ejemplo n.º 26
0
 //Convert a PEPlugin.SDX.V* vector to an OBJ-compatible string representation
 private string vecToString(object v)
 {
     //Texture coordinates
     if (v is V2)
     {
         V2 cast = (V2)v;
         return($"{cast.X} {-cast.Y}");
     }
     else if (v is V3)
     {
         V3 cast = (V3)v;
         return($"{cast.X} {cast.Y} {cast.Z}");
     }
     else if (v is V4)
     {
         V4 cast = (V4)v;
         return($"{cast.X} {cast.Y} {cast.Z} {cast.W}");
     }
     else
     {
         return("");
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Executes the provided XmlDocument on the PMX object.
        /// </summary>
        public static RunnerResult Execute(XmlDocument doc, IPXPmx pmx, IPXPmxBuilder builder, RunnerProgress progress)
        {
            XmlElement root = doc.DocumentElement;

            progress.Report(0, "> Execution started.");

            // Begin processing
            // Only the first level of elements are interpreted as commands.
            XmlElement[] commands = root.ChildNodes.OfType <XmlElement>().ToArray();
            for (int i = 0; i < commands.Length; ++i)
            {
                try
                {
                    XmlElement node = commands[i];

                    // The meaningful content of each case constitutes a separate block to avoid mixing variables. Might be unnecessary, but right now I'm not feeling too hot and my output WILL be sloppy.
                    // Should review this code later.
                    switch (node.Name.ToLowerInvariant())
                    {
                    // Creates a new bone with the provided properties.
                    case "bone":
                    {
                        string  name = Math.Abs(Guid.NewGuid().GetHashCode()).ToString();
                        IPXBone bone = null;

                        // Get name and check for collision
                        if (node["name"] != null)
                        {
                            name = node["name"].InnerText;

                            IPXBone existing = pmx.Bone.Where(b => b.Name == name).FirstOrDefault();
                            if (existing != null)
                            {
                                // If there is a collision, refer to the collision attribute
                                switch (node["name"].GetAttribute("collision"))
                                {
                                // If the attribute is "update" or "replace", refer to the existing bone for the rest of the command.
                                case "replace":
                                case "update":
                                    bone = existing;
                                    break;

                                // If the attribute is "skip", don't do anything with the bone and skip the command.
                                case "skip":
                                    continue;

                                // If the attribute is not valid, create a new bone and ignore the old one.
                                default:
                                    bone      = builder.Bone();
                                    bone.Name = bone.NameE = name;
                                    break;
                                }
                            }
                            else
                            {
                                bone      = builder.Bone();
                                bone.Name = bone.NameE = name;
                            }
                        }
                        else
                        {
                            bone      = builder.Bone();
                            bone.Name = bone.NameE = name;
                        }

                        if (node["position"] != null)
                        {
                            bone.Position = node["position"].GetV3();
                        }
                        if (node["translation"] != null)
                        {
                            bone.IsTranslation = bool.TryParse(node["translation"].InnerText, out bool translation) ? translation : false;
                        }
                        if (node["parent"] != null)
                        {
                            bone.Parent = Selector.Bone.Selector(node["parent"], pmx).FirstOrDefault();
                        }
                        if (node["axis"] != null)
                        {
                            V3 v = node["axis"].GetV3();
                            v.Normalize();
                            bone.IsFixAxis = true;
                            bone.FixAxis   = v;
                        }
                        if (node["weight"] != null)
                        {
                            //IEnumerable<IPXVertex> vertices = Selector.Vertex.SelectorList(node["weight"].ChildNodes, pmx);
                            IEnumerable <IPXVertex> vertices = Selector.Vertex.SelectorNode(node["weight"], pmx);
                            foreach (IPXVertex v in vertices)
                            {
                                v.Bone1   = bone;
                                v.Weight1 = 1;
                                v.Bone2   = v.Bone3 = v.Bone4 = null;
                                v.Weight2 = v.Weight3 = v.Weight4 = 0;
                            }
                        }
                        pmx.Bone.Add(bone);
                        progress.Report(Percent(i + 1, commands.Length), string.Format("[bone] Added new bone {0}.", bone.Name));
                    }
                    break;

                    // Assigns the selected vertices to the selected bone using BDEF1.
                    case "weight":
                    {
                        IPXBone bone = null;
                        if (node["target"] != null)
                        {
                            bone = Selector.Bone.Selector(node["target"], pmx).FirstOrDefault();
                            if (bone == null)
                            {
                                progress.Report(Percent(i + 1, commands.Length), string.Format("[weight] Bone was not found.", node["target"].InnerText));
                                break;
                            }
                        }
                        else
                        {
                            progress.Report(Percent(i + 1, commands.Length), "[weight] Bone selector was not specified.");
                            break;
                        }

                        // Set vertex weights
                        if (node["select"] == null)
                        {
                            progress.Report(Percent(i + 1, commands.Length), "[weight] No vertices were selected.");
                            break;
                        }
                        IEnumerable <IPXVertex> vertices = Selector.Vertex.SelectorNode(node["select"], pmx);
                        foreach (IPXVertex v in vertices)
                        {
                            v.Bone1   = bone;
                            v.Weight1 = 1;
                            v.Bone2   = v.Bone3 = v.Bone4 = null;
                            v.Weight2 = v.Weight3 = v.Weight4 = 0;
                        }

                        progress.Report(Percent(i + 1, commands.Length), string.Format("[weight] Weighted {0} vertices to {1} ({2}).", vertices.Count(), bone.Name, bone.NameE));
                    }
                    break;

                    // Creates a new UV morph.
                    case "uvmorph":
                    {
                        // The morph's properties are defined in attributes.
                        IPXMorph morph = builder.Morph();
                        morph.Kind = MorphKind.UV;

                        // Set the UV channel
                        if (int.TryParse(node.GetAttribute("channel"), out int ch))
                        {
                            switch (ch)
                            {
                            case 1:
                                morph.Kind = MorphKind.UVA1;
                                break;

                            case 2:
                                morph.Kind = MorphKind.UVA2;
                                break;

                            case 3:
                                morph.Kind = MorphKind.UVA3;
                                break;

                            case 4:
                                morph.Kind = MorphKind.UVA4;
                                break;

                            default:
                                morph.Kind = MorphKind.UV;
                                break;
                            }
                        }

                        // Set the group panel
                        if (int.TryParse(node.GetAttribute("group"), out int group) && group <= 4 && group >= 0)
                        {
                            morph.Panel = group;
                        }
                        else
                        {
                            switch (node.GetAttribute("group").ToLowerInvariant())
                            {
                            case "hidden":
                            case "hide":
                            case "none":
                            case "0":
                                morph.Panel = 0;
                                break;

                            case "eyebrow":
                            case "eyebrows":
                            case "1":
                                morph.Panel = 1;
                                break;

                            case "eye":
                            case "eyes":
                            case "2":
                                morph.Panel = 2;
                                break;

                            case "mouth":
                            case "3":
                                morph.Panel = 3;
                                break;

                            default:
                                morph.Panel = 4;
                                break;
                            }
                        }

                        // Set the name, ignore collisions
                        if (node.HasAttribute("name"))
                        {
                            morph.Name = morph.NameE = node.GetAttribute("name");
                        }
                        else
                        {
                            morph.Name = morph.NameE = morph.GetHashCode().ToString();
                        }

                        // Each morph contains one or more steps. Each step has its own selectors and transforms, which are applied independently.
                        foreach (XmlElement step in node.ChildNodes.OfType <XmlElement>().Where(el => el.Name.ToLowerInvariant() == "step"))
                        {
                            // Skip steps that have no selectors
                            if (step["select"] == null)
                            {
                                continue;
                            }
                            // Select vertices
                            IEnumerable <IPXVertex> vertices = Selector.Vertex.SelectorNode(step["select"], pmx);
                            foreach (XmlElement e in step)
                            {
                                switch (e.Name.ToLowerInvariant())
                                {
                                case "pan":
                                case "translate":
                                {
                                    V2 v = e.GetV2();
                                    foreach (IPXVertex vertex in vertices)
                                    {
                                        IPXUVMorphOffset offset = builder.UVMorphOffset();
                                        offset.Vertex = vertex;
                                        offset.Offset = new V4(v.X, v.Y, 0, 0);
                                        morph.Offsets.Add(offset);
                                    }
                                }
                                break;

                                case "rotate":              // TODO: UV morph rotation
                                case "scale":               // TODO: UV morph scaling
                                default:
                                    break;
                                }
                            }
                        }

                        pmx.Morph.Add(morph);
                        progress.Report(Percent(i + 1, commands.Length), string.Format("[uvmorph] Created UV morph {0} with {1} offsets.", morph.Name, morph.Offsets.Count));
                    }
                    break;

                    // No particular functionality, testing only.
                    case "test":
                    {
                        //foreach (IPXMorph morph in pmx.Morph.Where(m => m.Kind == MorphKind.UV))
                        //{
                        //    foreach (IPXUVMorphOffset o in morph.Offsets)
                        //    {
                        //        _report(string.Format("{0:f2}, {1:f2}, {2:f2}, {3:f2}", o.Offset.X, o.Offset.Y, o.Offset.Z, o.Offset.W), -1);
                        //    }
                        //}
                    }
                    break;

                    // Sets up the selected vertices for use with AutoLuminous.
                    case "autoluminous":
                    {
                        if (node["select"] == null)
                        {
                            progress.Report(Percent(i + 1, commands.Length), "[weight] No vertices were selected.");
                            break;
                        }
                        IEnumerable <IPXVertex> vertices = Selector.Vertex.SelectorNode(node["select"], pmx);

                        // Set required values.
                        pmx.Header.UVACount = Math.Max(pmx.Header.UVACount, 3);

                        // UV1
                        int   texture        = 0;
                        int   hsv            = 0;
                        float flashFrequency = 0;
                        // UV2
                        V4 baseColor = new V4(0, 0, 0, 0);
                        // UV3
                        float texSubtract = 0;
                        float flashBias   = 0;
                        float push        = 0;

                        // Base emissive color
                        if (node["color"] != null)
                        {
                            baseColor = node["color"].GetV4();
                        }

                        // Base emissive power
                        if (node["power"] != null)
                        {
                            baseColor.W = node["power"].GetSingle();
                        }

                        if (node["texture"] != null)
                        {
                            int.TryParse(node["texture"].InnerText, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out texture);
                        }

                        if (node["colormode"] != null)
                        {
                            switch (node["colormode"].InnerText.ToLowerInvariant())
                            {
                            case "hsv":
                                hsv = 10;
                                break;

                            default:
                                hsv = 0;
                                break;
                            }
                        }

                        if (node["flash"] != null)
                        {
                            float.TryParse(node["flash"].GetAttribute("bias"), System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out flashBias);
                            flashFrequency = node["flash"].GetSingle();
                        }

                        if (node["subtract"] != null)
                        {
                            texSubtract = node["subtract"].GetSingle();
                        }

                        if (node["push"] != null)
                        {
                            push = node["push"].GetSingle();
                        }

                        foreach (IPXVertex v in vertices)
                        {
                            v.UVA1.X = 0.2f;            // Required value
                            v.UVA1.Y = 0.7f;            // Required value
                            v.UVA1.Z = flashFrequency;
                            v.UVA1.W = texture + hsv;

                            v.UVA2 = baseColor;

                            v.UVA3.X = texSubtract;
                            v.UVA3.Y = flashBias;
                            v.UVA3.Z = push;
                        }
                    }
                    break;

                    // Creates a vertex morph for AutoLuminous properties.
                    case "almorph":
                    {
                        if (node["select"] == null)
                        {
                            progress.Report(Percent(i + 1, commands.Length), "[weight] No vertices were selected.");
                            break;
                        }
                        HashSet <IPXVertex> vertices = new HashSet <IPXVertex>(Selector.Vertex.SelectorNode(node["select"], pmx));

                        V4 color = new V4();

                        if (node["color"] != null)
                        {
                            color = node["color"].GetV4();
                        }

                        // TODO: Implement the rest of the AL properties in ALMorph

                        IPXMorph morph = builder.Morph();
                        morph.Kind = MorphKind.UVA2;
                        if (node.HasAttribute("name"))
                        {
                            morph.Name = morph.NameE = node.GetAttribute("name");
                        }
                        else
                        {
                            morph.Name = morph.NameE = morph.GetHashCode().ToString();
                        }

                        foreach (IPXVertex v in vertices)
                        {
                            // Set required values in case the vertex isn't already AL-enabled
                            v.UVA1.X = 0.2f;
                            v.UVA1.Y = 0.7f;
                            // Create the offset
                            morph.Offsets.Add(builder.UVMorphOffset(v, color));
                        }
                    }
                    break;

                    // Sets environment variables.
                    case "settings":
                    {
                        foreach (XmlElement child in node.ChildNodes.OfType <XmlElement>())
                        {
                            switch (child.Name.ToLowerInvariant())
                            {
                            case "exception":
                                break;

                            case "regex":
                                bool regexCI = GlobalSettings.RegexCaseInsensitive;
                                bool.TryParse(child.GetAttributeCI("caseinsensitive"), out regexCI);
                                break;

                            case "colortype":
                                GlobalSettings.ColorIsFloat = child.InnerText.ToLowerInvariant() == "float";
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    break;

                    // Displays a MessageBox with the provided content. Optionally perform certain actions based on user input.
                    case "mbox":
                    case "messagebox":
                    case "prompt":
                    {
                        if (int.TryParse(node.GetAttributeCI("skip"), out int skipNumber) && skipNumber > 0)
                        {
                            StringBuilder sb = new StringBuilder(string.Format("Would you like to skip the following {0} command(s)?\n", skipNumber));
                            for (int j = 1; j <= skipNumber; ++j)
                            {
                                sb.Append(commands[i + j].Name);
                            }
                            MessageBox.Show(sb.ToString(), "Prompt: skip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        }
                        else
                        {
                            MessageBox.Show(node.InnerText, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    break;

                    // Prints a line in the console.
                    case "echo":
                    case "print":
                        progress.Report(Percent(i + 1, commands.Length), node.InnerText);
                        break;

                    default:
                        progress.Report(Percent(i + 1, commands.Length), "Skipping unknown command " + node.Name);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (GlobalSettings.Exception == GlobalSettings.ErrorHandling.Ask)
                    {
                        if (MessageBox.Show(string.Format("The following exception has occured:\n\n{0}\n\nWould you like to continue execution?", ex.ToString()), "Exception", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No)
                        {
                            return(RunnerResult.Fail);
                        }
                    }
                    else if (GlobalSettings.Exception == GlobalSettings.ErrorHandling.Abort)
                    {
                        return(RunnerResult.Fail);
                    }
                }
            }

            // If control has reached this point, the execution is considered successful.
            return(RunnerResult.Success);
        }
 public static Vector4 FromSpeedTree(V4 v)
 {
     return new Vector4(v.x, v.y, v.z, v.w);
 }
Ejemplo n.º 29
0
 public IPXUVMorphOffset UVMorphOffset(IPXVertex vertex, V4 offset)
 {
     return(new MockUVMorphOffset(vertex, offset));
 }
Ejemplo n.º 30
0
    public void Execute(int index)
    {
        if (MPC_array[index].Coordinates.x >= Xleft && MPC_array[index].Coordinates.x <= Xright && MPC_array[index].Coordinates.z >= Zdown && MPC_array[index].Coordinates.z <= Zup)
        {
            if (MPC_array[index].Inclusion == 0)
            {
                if (p1 == p2) // the polygon is a triangle
                {
                    Vector3 side1      = s1 - p1;
                    Vector3 side2      = s2 - p2;
                    float   S_triangle = Mathf.Abs(-side1.x * side2.z + side1.z * side2.x); // double area


                    // We check if MPC_array[index] is in the triangle side1 side2
                    Vector3 v1 = s1 - MPC_array[index].Coordinates;
                    Vector3 v2 = p1 - MPC_array[index].Coordinates;
                    Vector3 v3 = s2 - MPC_array[index].Coordinates;
                    float   S1 = Mathf.Abs(-v1.x * v2.z + v1.z * v2.x); // double area
                    float   S2 = Mathf.Abs(-v2.x * v3.z + v2.z * v3.x); // double area
                    float   S3 = Mathf.Abs(-v3.x * v1.z + v3.z * v1.x); // double area

                    if (Mathf.Abs(S_triangle - S1 - S2 - S3) < 0.001)
                    {
                        // if the sum of areas is almost equal to the whole area, then the MPC is included into the active set of MPCs
                        Vector3 new_norm = (n1 + n2).normalized;
                        MPC_V6[index]    = new V6(MPC_array[index].Coordinates, new_norm);
                        MPC_perp[index]  = new Vector3(-new_norm.z, 0, new_norm.x);
                        MPC_array[index] = new V4(MPC_array[index].Coordinates, 1);
                    }
                }
                else // the polygon is not a triangle
                {
                    float dot_prod_normals = Vector3.Dot(n1, n2);
                    if (dot_prod_normals <= 0)    // then the polygon is not convex (or triangle where p1 != p2)
                    {
                        // in this case, we consider two triangles separately
                        Vector3 v11 = p1 - s1;
                        Vector3 v12 = p2 - s1;
                        float   S1  = Mathf.Abs(-v11.x * v12.z + v11.z * v12.x); //(v11, v12, out float S1);

                        Vector3 v21 = p1 - s2;
                        Vector3 v22 = p2 - s2;
                        float   S2  = Mathf.Abs(-v21.x * v22.z + v21.z * v22.x); //Area2D(v21, v22, out float S2);
                                                                                 // we consider such strange triangles in order to cover the biggest area defined at leas with one correct triangle
                                                                                 // and at the same time to avoid considering a non-convex quadrangle

                        Vector3 vp1 = p1 - MPC_array[index].Coordinates;
                        Vector3 vp2 = p2 - MPC_array[index].Coordinates;

                        Vector3 vs1 = s1 - MPC_array[index].Coordinates;
                        Vector3 vs2 = s2 - MPC_array[index].Coordinates;

                        // common area that is related to both S1 and S2
                        float Spp = Mathf.Abs(-vp1.x * vp2.z + vp1.z * vp2.x); //Area2D(vp1, vp2, out float Spp);

                        // areas related to S1
                        float Sp1s1 = Mathf.Abs(-vp1.x * vs1.z + vp1.z * vs1.x); //Area2D(vp1, vs1, out float Sp1s1);
                        float Sp2s1 = Mathf.Abs(-vp2.x * vs1.z + vp2.z * vs1.x); //Area2D(vp2, vs1, out float Sp2s1);

                        // areas related to S2
                        float Sp1s2 = Mathf.Abs(-vp1.x * vs2.z + vp1.z * vs2.x); //Area2D(vp1, vs2, out float Sp1s2);
                        float Sp2s2 = Mathf.Abs(-vp2.x * vs2.z + vp2.z * vs2.x); //Area2D(vp2, vs2, out float Sp2s2);

                        // check if the point [i] belongs to S1 or S2
                        if (Mathf.Abs(S1 - Spp - Sp1s1 - Sp2s1) < 0.001)
                        {
                            MPC_V6[index]    = new V6(MPC_array[index].Coordinates, n1);
                            MPC_perp[index]  = new Vector3(-n1.z, 0, n1.x);
                            MPC_array[index] = new V4(MPC_array[index].Coordinates, 1);
                        }
                        else if (Mathf.Abs(S2 - Spp - Sp1s2 - Sp2s2) < 0.001)
                        {
                            MPC_V6[index]    = new V6(MPC_array[index].Coordinates, n2);
                            MPC_perp[index]  = new Vector3(-n2.z, 0, n2.x);
                            MPC_array[index] = new V4(MPC_array[index].Coordinates, 1);
                        }
                    }
                    else // the polygon is convex
                    {
                        // the first triangle of the quadrangle
                        Vector3 v11 = p1 - s1;
                        Vector3 v12 = s2 - s1;
                        float   S1  = Mathf.Abs(-v11.x * v12.z + v11.z * v12.x);//Area2D(v11, v12, out float S1);

                        // the second triangle of the quadrangle
                        Vector3 v21 = p1 - p2;
                        Vector3 v22 = s2 - p2;
                        float   S2  = Mathf.Abs(-v21.x * v22.z + v21.z * v22.x);//Area2D(v21, v22, out float S2);

                        Vector3 v1 = p1 - MPC_array[index].Coordinates;
                        Vector3 v2 = s1 - MPC_array[index].Coordinates;
                        Vector3 v3 = s2 - MPC_array[index].Coordinates;
                        Vector3 v4 = p2 - MPC_array[index].Coordinates;

                        float A1 = Mathf.Abs(-v1.x * v2.z + v1.z * v2.x); //Area2D(v1, v2, out float A1);
                        float A2 = Mathf.Abs(-v2.x * v3.z + v2.z * v3.x); //Area2D(v2, v3, out float A2);
                        float A3 = Mathf.Abs(-v3.x * v4.z + v3.z * v4.x); //Area2D(v3, v4, out float A3);
                        float A4 = Mathf.Abs(-v4.x * v1.z + v4.z * v1.x); //Area2D(v4, v1, out float A4);


                        float area_diff = Mathf.Abs(S1 + S2 - A1 - A2 - A3 - A4);

                        if (area_diff < 1)
                        {
                            Vector3 new_norm = (n1 + n2).normalized;
                            MPC_V6[index]    = new V6(MPC_array[index].Coordinates, new_norm);
                            MPC_perp[index]  = new Vector3(-new_norm.z, 0, new_norm.x);
                            MPC_array[index] = new V4(MPC_array[index].Coordinates, 1);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 31
0
 void SelectCotnentBackgroundColorChange(GameObject g, V4 from, V4 to)
 {
     MiniItween.ColorFromTo(g, from, to, 0.3f, MiniItween.EasingType.Normal, MiniItween.Type.ColorWidget);
 }