Пример #1
0
    static void Init()
    {
        window = (VertexPainter)EditorWindow.GetWindow(typeof(VertexPainter));

        onSceneGUIFunc = new SceneView.OnSceneFunc(OnSceneGUI);
        SceneView.onSceneGUIDelegate += onSceneGUIFunc;

        VertexPainterHash = window.GetHashCode();
        currentSelection  = Selection.activeGameObject;
        if (currentSelection != null)
        {
            currentSelectionMeshFilter = currentSelection.GetComponent <MeshFilter>();

            if (currentSelectionMeshFilter != null)
            {
                currentSelectionMesh = currentSelectionMeshFilter.sharedMesh;
            }
            else
            {
                Debug.Log("Meshfilter null");
            }
        }

        ChannelsToPaint.Red   = true;
        ChannelsToPaint.Blue  = true;
        ChannelsToPaint.Green = true;
    }
Пример #2
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        VertexPainter window = EditorWindow.GetWindow <VertexPainter> ("VertexPainter");

        window.Show();
    }
Пример #3
0
 public void RandomiseColors()
 {
     Transform trigger = this.transform.FindChild("trigger");
     Transform target = this.transform.FindChild("target");
     triggerVP = trigger.GetComponent<VertexPainter>();
     targetVP = target.GetComponent<VertexPainter>();
     triggerColor = Colors.getRandomPrimaryColor();
     targetColor = Colors.getRandomCombinedColorFor(triggerColor);
     triggerVP.changeVertexesColor(triggerColor);
     targetVP.changeVertexesColor(targetColor);
 }
Пример #4
0
    private static void CreateWindow()
    {
        //Init window
        int x = 150, y = 150, w = 320, h = 150;

        window          = (VertexPainter)GetWindow(typeof(VertexPainter), false);
        window.position = new Rect(x, y, w + x, h + y);
        window.minSize  = new Vector2(w, h);
        window.maxSize  = new Vector2(w + 2, h + 2);
        window.title    = "Vertex Paint";
        window.Show();
    }
Пример #5
0
    private void OnEnable()
    {
        vp     = (VertexPainter)target;
        trans  = vp.transform;
        matrix = trans.localToWorldMatrix;
        MeshFilter mf = vp.GetComponent <MeshFilter>();

        if (mf == null)
        {
            sharedMesh = vp.GetComponent <SkinnedMeshRenderer>().sharedMesh;
        }
        else
        {
            sharedMesh = mf.sharedMesh;
        }

        colors = new Color[sharedMesh.vertexCount];
        uvs    = new Vector2[colors.Length];

        palette = LoadTexture();
        if (palette == null)
        {
            palette = new Texture2D(5, 1);
            for (int i = 0; i < 5; i++)
            {
                paletteColors[i] = Color.black;
            }
            palette.SetPixels(paletteColors);
            palette.filterMode = FilterMode.Point;
            palette.Apply();
        }

        currentPaletteColor = 0;

        for (int i = 0; i < colors.Length; i++)
        {
            if (sharedMesh.colors.Length > 0)
            {
                colors[i] = sharedMesh.colors[i];
            }
            else
            {
                colors[i] = Color.white;
            }
            uvs[i] = sharedMesh.uv[i];
        }

        paintMode = true;
        SetupReferences();
        SetupPainter();
    }
Пример #6
0
    public void OnDestroy()
    {
        Save();

        if (oldMaterial != null)
        {
            if (Selection.activeGameObject != null)
            {
                Selection.activeGameObject.GetComponent <Renderer>().sharedMaterial = oldMaterial;
            }
        }
        oldMaterial = null;
        currentMode = Mode.None;
        window      = null;
    }
    public void OnSceneGUI()
    {
        if (m_painter == null)
        {
            m_painter = (VertexPainter)target;
        }

        if (Event.current.isMouse)
        {
            m_painter.SelectedObject = HandleUtility.PickGameObject(Event.current.mousePosition, false);
        }

        if (m_painter.SelectedObject == null)
        {
            m_lastRaycastHit = new RaycastHit();
            return;
        }

        if (Event.current.isMouse && Event.current.button == 0)
        {
            Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out m_lastRaycastHit);

            if (Event.current.type == EventType.MouseDown)
            {
                m_isMouseDown = true;
                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                m_isMouseDown = false;
                Event.current.Use();
            }
        }
        else if (Event.current.isKey && Event.current.keyCode == KeyCode.Escape)
        {
            m_painter.ResetMeshColors();
        }

        if (m_isMouseDown)
        {
            PaintVertices(m_lastRaycastHit.point);
        }

        DrawBrush(m_lastRaycastHit.point, m_lastRaycastHit.normal);

        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
    }
    public override void OnInspectorGUI()
    {
        if (m_painter == null)
        {
            m_painter = (VertexPainter)target;
        }

        m_painter._brushRadius = EditorGUILayout.Slider("Size", m_painter._brushRadius, 0f, 10f);

        m_painter._brushIntensity = EditorGUILayout.Slider("Intensity", m_painter._brushIntensity, -0.1f, 0.1f);

        m_painter._brushChannel = (ColorChannel)GUILayout.Toolbar(
            (int)m_painter._brushChannel, s_channelLabels);

        EditorGUILayout.Space();

        string previewButtonLabel;

        if (!m_painter.IsPreviewingRaw)
        {
            previewButtonLabel = "Show Raw Painting";
        }
        else
        {
            previewButtonLabel = "Hide Raw Painting";
        }

        if (GUILayout.Button(previewButtonLabel))
        {
            m_painter.IsPreviewingRaw = !m_painter.IsPreviewingRaw;
        }

        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Press Esc. to reset vertices colors", MessageType.Info);

        EditorGUILayout.Space();

        if ((m_advancedFoldout = EditorGUILayout.Foldout(m_advancedFoldout, "Advanced")))
        {
            m_painter._previewMaterial = (Material)EditorGUILayout.ObjectField("Preview Material", m_painter._previewMaterial, typeof(Material), false);

            m_painter._brushFalloff = EditorGUILayout.CurveField("Falloff Curve", m_painter._brushFalloff);
        }

        EditorUtility.SetDirty(m_painter);
    }
Пример #9
0
    static void Init () {
        window = (VertexPainter)EditorWindow.GetWindow (typeof (VertexPainter));
		
		onSceneGUIFunc = new SceneView.OnSceneFunc(OnSceneGUI);
		SceneView.onSceneGUIDelegate += onSceneGUIFunc;
		
		VertexPainterHash = window.GetHashCode();
		currentSelection = Selection.activeGameObject;
		if (currentSelection!= null) {
			currentSelectionMeshFilter = currentSelection.GetComponent<MeshFilter>();
			
			if (currentSelectionMeshFilter!= null) 
				currentSelectionMesh = currentSelectionMeshFilter.sharedMesh;
			else
				Debug.Log("meshfilter null");
		}
    }
Пример #10
0
    void OnDestroy()
    {
        Save();

        if (oldMaterial != null)
        {
            if (currentSelection != null)
            {
                if (currentSelection.GetComponent <Renderer>() != null)
                {
                    currentSelection.GetComponent <Renderer>().sharedMaterial = oldMaterial;
                }
            }
        }
        oldMaterial = null;
        currentMode = Mode.None;
        SceneView.onSceneGUIDelegate -= onSceneGUIFunc;
        window = null;
    }
Пример #11
0
    void OnDestroy()
    {
        if (currentMode == Mode.Painting)
        {
            EndPaint();
        }

        if (oldMaterial != null)
        {
            if (currentSelection != null)
            {
                if (currentSelection.GetComponent <Renderer>() != null)
                {
                    EditorUtility.SetSelectedWireframeHidden(currentSelection.GetComponent <Renderer>(), true);
                    currentSelection.GetComponent <Renderer>().sharedMaterial = oldMaterial;
                }
            }
        }
        oldMaterial = null;
        currentMode = Mode.None;
        SceneView.onSceneGUIDelegate -= onSceneGUIFunc;
        window = null;
    }
Пример #12
0
 void Start()
 {
     Transform t = this.transform.FindChild("shipTriangle");
     vp = t.GetComponent<VertexPainter>();
     currentColor = Colors.getRandomPrimaryColor();
 }
Пример #13
0
 private static void Init()
 {
     window = (VertexPainter)GetWindow(typeof(VertexPainter));
     CheckSelection();
 }
    public static void ShowExample()
    {
        VertexPainter wnd = GetWindow <VertexPainter>();

        wnd.titleContent = new GUIContent("VertexPainter");
    }
Пример #15
0
 private static void Init()
 {
     window = (VertexPainter)GetWindow (typeof (VertexPainter));
     CheckSelection();
 }
Пример #16
0
    public void OnDestroy()
    {
        Save();

        if (oldMaterial != null)
        {
            if (Selection.activeGameObject != null)
                Selection.activeGameObject.GetComponent<Renderer>().sharedMaterial = oldMaterial;
        }
        oldMaterial = null;
        currentMode = Mode.None;
        window = null;
    }
Пример #17
0
    public override void OnInspectorGUI()
    {
        vp = (VertexPainter)target;

        DrawInspectorGUI();
    }
Пример #18
0
	void OnDestroy()
	{
		Save();
		
		if (oldMaterial != null) {
			if (currentSelection != null)
				if (currentSelection.GetComponent<Renderer>() != null)
					currentSelection.GetComponent<Renderer>().sharedMaterial = oldMaterial;
		}
		oldMaterial = null;
		currentMode = Mode.None;
		SceneView.onSceneGUIDelegate -= onSceneGUIFunc;
		window = null;
	}