예제 #1
0
        void DrawAboutGUI()
        {
            GUILayout.FlexibleSpace();

            EditorGUILayout.LabelField("Programming:", EditorStyles.centeredGreyMiniLabel);
            EditorGUILayout.LabelField("José María Méndez González", EditorStyles.centeredGreyMiniLabel);

            EditorGUILayout.LabelField("Additional resources:", EditorStyles.centeredGreyMiniLabel);
            EditorGUILayout.LabelField("Lidia Martínez Prado", EditorStyles.centeredGreyMiniLabel);

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Manual", EditorStyles.toolbarButton))
            {
                Application.OpenURL("http://obi.virtualmethodstudio.com/tutorials/");
            }
            if (GUILayout.Button("API docs", EditorStyles.toolbarButton))
            {
                Application.OpenURL("http://obi.virtualmethodstudio.com/docs/");
            }
            if (GUILayout.Button("visit www.virtualmethodstudio.com", EditorStyles.toolbarButton))
            {
                Application.OpenURL("http://www.virtualmethodstudio.com");
            }
            if (GUILayout.Button("Create preferences file", EditorStyles.toolbarButton))
            {
                ObiEditorSettings.GetOrCreateSettings();
            }
        }
        public override Color ToColor(int index)
        {
            Gradient gradient = ObiEditorSettings.GetOrCreateSettings().propertyGradient;

            if (!Mathf.Approximately(minVisualizationValue, maxVisualizationValue))
            {
                return(gradient.Evaluate(Mathf.InverseLerp(minVisualizationValue, maxVisualizationValue, Get(index))));
            }
            else
            {
                return(gradient.Evaluate(0));
            }
        }
        public void DrawGradientMesh(float[] vertexWeights = null, float[] wireframeWeights = null)
        {
            visualizationMesh = GameObject.Instantiate(sourceMesh);

            if (gradientMaterial.SetPass(0))
            {
                var matrix = Matrix4x4.Scale((blueprint as ObiMeshBasedActorBlueprint).scale);

                Color[] colors = new Color[visualizationMesh.vertexCount];
                for (int i = 0; i < colors.Length; i++)
                {
                    int   particle = VertexToParticle(i);
                    float weight   = 1;
                    if (vertexWeights != null)
                    {
                        weight = vertexWeights[particle];
                    }

                    colors[i] = weight * currentProperty.ToColor(particle);
                }

                visualizationMesh.colors = colors;
                Graphics.DrawMeshNow(visualizationMesh, matrix);

                Color wireColor = ObiEditorSettings.GetOrCreateSettings().brushWireframeColor;

                if (gradientMaterial.SetPass(1))
                {
                    for (int i = 0; i < colors.Length; i++)
                    {
                        if (wireframeWeights != null)
                        {
                            colors[i] = wireColor * wireframeWeights[VertexToParticle(i)];
                        }
                        else
                        {
                            colors[i] = wireColor;
                        }
                    }

                    visualizationMesh.colors = colors;
                    GL.wireframe             = true;
                    Graphics.DrawMeshNow(visualizationMesh, matrix);
                    GL.wireframe = false;
                }
            }

            GameObject.DestroyImmediate(visualizationMesh);
        }
예제 #4
0
        protected override void OnRepaint()
        {
            base.OnRepaint();

            if (raycastTarget != null)
            {
                Color brushColor = ObiEditorSettings.GetOrCreateSettings().brushColor;

                if (hit != null && hit.triangle >= 0)
                {
                    Handles.color = brushColor;
                    Handles.DrawLine(hit.position, hit.position + hit.normal.normalized * radius);
                    Handles.DrawWireDisc(hit.position, hit.normal, radius);
                    Handles.DrawWireDisc(hit.position, hit.normal, innerRadius * radius);
                }
            }
        }
        protected override void OnRepaint()
        {
            base.OnRepaint();

            Camera cam   = Camera.current;
            float  depth = (cam.nearClipPlane + cam.farClipPlane) * 0.5f;

            Vector2 mousePos = new Vector2(Event.current.mousePosition.x,
                                           cam.pixelHeight - Event.current.mousePosition.y);

            Handles.color = ObiEditorSettings.GetOrCreateSettings().brushColor;
            Vector3 point   = new Vector3(mousePos.x, mousePos.y, depth);
            Vector3 wsPoint = cam.ScreenToWorldPoint(point);

            var   p1    = cam.ScreenToWorldPoint(new Vector3(1, 0, depth));
            var   p2    = cam.ScreenToWorldPoint(new Vector3(0, 0, depth));
            float units = Vector3.Distance(p1, p2);

            Handles.DrawWireDisc(wsPoint, cam.transform.forward, radius * units);
        }
예제 #6
0
        void UpdateTargetObject()
        {
            if (slaveObject == null)
            {
                return;
            }

            slaveObject.GetComponent <MeshRenderer>().material = standardMaterial;

            if (Selection.activeGameObject != slaveObject)
            {
                return;
            }

            Selection.objects = new Object[] { slaveObject };

            if (paintMode)
            {
                slaveObject.GetComponent <MeshRenderer>().material = paintMaterial;
                if (masterObject != null)
                {
                    masterObject.GetComponent <MeshRenderer>().material = standardMaterial;
                }

                Mesh    mesh   = slaveObject.GetComponent <MeshFilter>().sharedMesh;
                Color[] colors = new Color[mesh.vertexCount];

                Color active   = ObiEditorSettings.GetOrCreateSettings().propertyGradient.Evaluate(1);
                Color inactive = ObiEditorSettings.GetOrCreateSettings().propertyGradient.Evaluate(0);

                for (int i = 0; i < mesh.vertexCount; i++)
                {
                    if ((skinMap.m_SlaveChannels[i] & (1 << currentProperty.GetDefault())) != 0)
                    {
                        colors[i] = active;
                    }
                    else
                    {
                        colors[i] = inactive;
                    }
                }

                mesh.colors = colors;

                if (paintMaterial.SetPass(1))
                {
                    Color wireColor = ObiEditorSettings.GetOrCreateSettings().brushWireframeColor;
                    Mesh  wireMesh  = Instantiate(mesh);
                    for (int i = 0; i < paintBrush.weights.Length; i++)
                    {
                        colors[i] = wireColor * paintBrush.weights[i];
                    }

                    wireMesh.colors = colors;
                    GL.wireframe    = true;
                    Graphics.DrawMeshNow(wireMesh, slaveObject.transform.localToWorldMatrix);
                    GL.wireframe = false;
                    DestroyImmediate(wireMesh);
                }
            }
        }
예제 #7
0
        public static bool Draw(bool selected, int id, ref Vector2 position, Color color)
        {
            Texture texture = Resources.Load <Texture2D>("Dot");

            int controlID = GUIUtility.GetControlID(id, FocusType.Passive);

            // select vertex on mouse click:
            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:

                Rect area = new Rect(position.x - 5, position.y - 5, 10, 10);

                if (area.Contains(Event.current.mousePosition))
                {
                    selected = true;
                    GUIUtility.hotControl = controlID;
                    Event.current.Use();
                }
                else if ((Event.current.modifiers & EventModifiers.Shift) == 0 && (Event.current.modifiers & EventModifiers.Command) == 0)
                {
                    selected = false;
                }

                break;

            case EventType.MouseDrag:

                if (GUIUtility.hotControl == controlID)
                {
                    position    = Event.current.mousePosition;
                    GUI.changed = true;

                    Event.current.Use();
                }

                break;

            case EventType.MouseUp:

                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                }

                break;

            case EventType.Repaint:

                Color oldColor = GUI.color;
                GUI.color = selected ? ObiEditorSettings.GetOrCreateSettings().selectedParticleColor : ObiEditorSettings.GetOrCreateSettings().particleColor;
                Rect rect = new Rect(position.x - 2, position.y - 2, 4, 4);
                GUI.Box(rect, EditorGUIUtility.whiteTexture);
                GUI.color = oldColor;

                break;
            }

            return(selected);
        }
예제 #8
0
        public override void OnActivate(string searchContext, UnityEngine.Experimental.UIElements.VisualElement rootElement)
#endif
        {
            // This function is called when the user clicks on the MyCustom element in the Settings window.
            m_ObiSettings = ObiEditorSettings.GetSerializedSettings();
        }
        public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, bool[] facingCamera, bool[] selectionStatus, int[] sortedIndices)
        {
            CreateParticlesMesh();
            CreateParticleMaterials();

            if (!particleMaterial.SetPass(0))
            {
                return;
            }

            //because each vertex needs to be drawn as a quad.
            int particlesPerDrawcall = Constants.maxVertsPerMesh / 4;
            int drawcallCount        = blueprint.particleCount / particlesPerDrawcall + 1;

            particlesPerDrawcall = Mathf.Min(particlesPerDrawcall, blueprint.particleCount);

            List <Vector3> vertices  = new List <Vector3>(blueprint.activeParticleCount * 4);
            List <Vector3> normals   = new List <Vector3>(blueprint.activeParticleCount * 4);
            List <Vector4> uvs       = new List <Vector4>(blueprint.activeParticleCount * 4);
            List <Color>   colors    = new List <Color>(blueprint.activeParticleCount * 4);
            List <int>     triangles = new List <int>(blueprint.activeParticleCount * 6);

            Color regularColor  = ObiEditorSettings.GetOrCreateSettings().particleColor;
            Color selectedColor = ObiEditorSettings.GetOrCreateSettings().selectedParticleColor;

            Vector3 particleOffset0 = new Vector3(1, 1, 0);
            Vector3 particleOffset1 = new Vector3(-1, 1, 0);
            Vector3 particleOffset2 = new Vector3(-1, -1, 0);
            Vector3 particleOffset3 = new Vector3(1, -1, 0);

            Vector4 radius = new Vector4(1, 0, 0, 0.006f);

            for (int i = 0; i < drawcallCount; ++i)
            {
                //Draw all cloth vertices:
                particlesMesh.Clear();
                vertices.Clear();
                uvs.Clear();
                normals.Clear();
                colors.Clear();
                triangles.Clear();

                int index = 0;

                // Run over all particles (not only active ones), since they're reordered based on distance to camera.
                // Then test if the sorted index is active or not, and skip inactive ones.
                int limit = Mathf.Min((i + 1) * particlesPerDrawcall, blueprint.particleCount);

                for (int j = i * particlesPerDrawcall; j < limit; ++j)
                {
                    int sortedIndex = sortedIndices[j];

                    // skip inactive ones:
                    if (!blueprint.IsParticleActive(sortedIndex))
                    {
                        continue;
                    }

                    // get particle color:
                    Color color = selectionStatus[sortedIndex] ? selectedColor : regularColor;
                    color.a = facingCamera[sortedIndex] ? 1 : 0.15f;

                    normals.Add(particleOffset0);
                    normals.Add(particleOffset1);
                    normals.Add(particleOffset2);
                    normals.Add(particleOffset3);

                    uvs.Add(radius);
                    uvs.Add(radius);
                    uvs.Add(radius);
                    uvs.Add(radius);

                    vertices.Add(blueprint.positions[sortedIndex]);
                    vertices.Add(blueprint.positions[sortedIndex]);
                    vertices.Add(blueprint.positions[sortedIndex]);
                    vertices.Add(blueprint.positions[sortedIndex]);

                    colors.Add(color);
                    colors.Add(color);
                    colors.Add(color);
                    colors.Add(color);

                    triangles.Add(index + 2);
                    triangles.Add(index + 1);
                    triangles.Add(index);
                    triangles.Add(index + 3);
                    triangles.Add(index + 2);
                    triangles.Add(index);

                    index += 4;
                }

                particlesMesh.SetVertices(vertices);
                particlesMesh.SetNormals(normals);
                particlesMesh.SetColors(colors);
                particlesMesh.SetUVs(0, uvs);
                particlesMesh.SetTriangles(triangles, 0, true);

                Graphics.DrawMeshNow(particlesMesh, Matrix4x4.identity);
            }
        }
예제 #10
0
        public static void DrawParticles(Camera cam, ObiActorBlueprint blueprint, bool[] facingCamera, bool[] selectionStatus, int[] sortedIndices)
        {
            CreateParticlesMesh();
            CreateParticleMaterials();

            if (!particleMaterial.SetPass(0))
            {
                return;
            }

            Vector3 camup      = cam.transform.up;
            Vector3 camright   = cam.transform.right;
            Vector3 camforward = cam.transform.forward;

            //because each vertex needs to be drawn as a quad.
            int particlesPerDrawcall = Constants.maxVertsPerMesh / 4;
            int drawcallCount        = blueprint.positions.Length / particlesPerDrawcall + 1;

            particlesPerDrawcall = Mathf.Min(particlesPerDrawcall, blueprint.positions.Length);

            Color regularColor  = ObiEditorSettings.GetOrCreateSettings().particleColor;
            Color selectedColor = ObiEditorSettings.GetOrCreateSettings().selectedParticleColor;

            int i = 0;

            for (int m = 0; m < drawcallCount; ++m)
            {
                //Draw all cloth vertices:
                particlesMesh.Clear();
                Vector3[] vertices  = new Vector3[particlesPerDrawcall * 4];
                Vector2[] uv        = new Vector2[particlesPerDrawcall * 4];
                Color[]   colors    = new Color[particlesPerDrawcall * 4];
                int[]     triangles = new int[particlesPerDrawcall * 6];

                for (int particlesDrawn = 0; i < blueprint.positions.Length && particlesDrawn < particlesPerDrawcall; ++i, ++particlesDrawn)
                {
                    int sortedIndex = sortedIndices[i];

                    // skip inactive ones:
                    if (!blueprint.IsParticleActive(sortedIndex))
                    {
                        continue;
                    }

                    int i4  = i * 4;
                    int i41 = i4 + 1;
                    int i42 = i4 + 2;
                    int i43 = i4 + 3;
                    int i6  = i * 6;

                    // get particle size in screen space:
                    float size = HandleUtility.GetHandleSize(blueprint.positions[sortedIndex]) * 0.04f;

                    // get particle color:
                    Color color = selectionStatus[sortedIndex] ? selectedColor : regularColor;
                    color.a = facingCamera[sortedIndex] ? 1 : 0.15f;

                    uv[i4]  = Vector2.one;
                    uv[i41] = new Vector2(0, 1);
                    uv[i42] = Vector3.zero;
                    uv[i43] = new Vector2(1, 0);

                    vertices[i4]  = blueprint.positions[sortedIndex] + camup * size + camright * size;
                    vertices[i41] = blueprint.positions[sortedIndex] + camup * size - camright * size;
                    vertices[i42] = blueprint.positions[sortedIndex] - camup * size - camright * size;
                    vertices[i43] = blueprint.positions[sortedIndex] - camup * size + camright * size;

                    colors[i4]  = color;
                    colors[i41] = color;
                    colors[i42] = color;
                    colors[i43] = color;

                    triangles[i6]     = i42;
                    triangles[i6 + 1] = i41;
                    triangles[i6 + 2] = i4;
                    triangles[i6 + 3] = i43;
                    triangles[i6 + 4] = i42;
                    triangles[i6 + 5] = i4;
                }

                particlesMesh.vertices  = vertices;
                particlesMesh.triangles = triangles;
                particlesMesh.uv        = uv;
                particlesMesh.colors    = colors;

                Graphics.DrawMeshNow(particlesMesh, Matrix4x4.identity);
            }
        }