private void LoadState(StateData state) { scene.Clear(); scene.Objs = state.Objs; scene.Mats = state.Mats; scene.Layers = state.Layers; currentLayer = null; currentMat = null; currentObj = null; if (scene.Layers.Count > 0) { currentLayer = scene.Layers[0]; } UpdatePaintedMats(); }
private void Render(P3dCommand command, P3dScene.Mat mat, P3dScene.Image image, P3dScene.Obj obj, int subMesh) { var oldActive = RenderTexture.active; if (image.Current == null) { if (image.Width > 0 && image.Height > 0 && image.Pixels != null && image.Pixels.Length > 0) { var texture = new Texture2D(1, 1); if (texture.LoadImage(image.Pixels) == true) { var desc = mat.Desc; desc.width = image.Width; desc.height = image.Height; image.Current = P3dHelper.GetRenderTexture(mat.Desc); P3dPaintReplace.BlitFast(image.Current, texture, Color.white); } else { image.Current = P3dHelper.GetRenderTexture(mat.Desc); P3dPaintReplace.BlitFast(image.Current, default(Texture), default(Color)); } DestroyImmediate(texture); } else { image.Current = P3dHelper.GetRenderTexture(mat.Desc); P3dPaintReplace.BlitFast(image.Current, default(Texture), default(Color)); } } var swap = P3dHelper.GetRenderTexture(image.Current.descriptor); if (command.Preview == true) { if (image.Preview == null) { image.Preview = P3dHelper.GetRenderTexture(image.Current.descriptor); P3dPaintReplace.BlitFast(image.Preview, image.Current, Color.white); } P3dPaintReplace.BlitFast(swap, image.Preview, Color.white); command.Apply(image.Preview); } else { P3dPaintReplace.BlitFast(swap, image.Current, Color.white); command.Apply(image.Current); } RenderTexture.active = swap; if (command.RequireMesh == true) { P3dHelper.Draw(command.Material, obj.Mesh, obj.Matrix, subMesh, obj.Coord); } else { P3dHelper.Draw(command.Material); } RenderTexture.active = oldActive; if (command.Preview == true) { P3dHelper.ReleaseRenderTexture(image.Preview); image.Preview = swap; previewDrawn = true; } else { P3dHelper.ReleaseRenderTexture(image.Current); image.Current = swap; } paintedGroups.Add(command.Priority); // Group is stored in priority }
protected override void OnInspector() { DrawNextPaint(); if (scene == null) { scene = CreateInstance <P3dScene>(); scene.name = "Temp"; scene.AddLayer(); scene.AddCloner("Mirror X", Vector3.zero, new Vector3(0.0f, 90.0f, 0.0f)); scene.AddCloner("Mirror Y", Vector3.zero, new Vector3(90.0f, 0.0f, 0.0f)); scene.AddCloner("Mirror Z", Vector3.zero, new Vector3(0.0f, 0.0f, 0.0f)); } if (previewDrawn == true && Event.current.type == EventType.Repaint) { previewDrawn = false; foreach (var layer in scene.Layers) { foreach (var images in layer.Images) { if (images.Preview != null) { images.Preview = P3dHelper.ReleaseRenderTexture(images.Preview); } } } pendingUpdate = true; } if (scene.Layers.Contains(currentLayer) == false) { currentLayer = null; if (scene.Layers.Count > 0) { currentLayer = scene.Layers[scene.Layers.Count - 1]; } } if (scene.Mats.Contains(currentMat) == false) { currentMat = null; if (scene.Mats.Count > 0) { currentMat = scene.Mats[scene.Mats.Count - 1]; } } if (scene.Objs.Contains(currentObj) == false) { currentObj = null; if (scene.Objs.Count > 0) { currentObj = scene.Objs[scene.Objs.Count - 1]; } } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginDisabledGroup(CanUndo == false); if (GUILayout.Button(new GUIContent("◄", "Undo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true) { Undo(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanRedo == false); if (GUILayout.Button(new GUIContent("►", "Redo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true) { Redo(); } EditorGUI.EndDisabledGroup(); if (GUILayout.Toggle(currentState == StateType.Scene, "Scene", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Scene; } if (GUILayout.Toggle(currentState == StateType.Paint, "Paint", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Paint; } if (GUILayout.Toggle(currentState == StateType.Layer, "Layer", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Layer; } if (GUILayout.Toggle(currentState == StateType.Config, "Config", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Config; } EditorGUILayout.Separator(); EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(40)) == true) { HandleSave(); } EditorGUI.EndDisabledGroup(); P3dHelper.BeginColor(Color.green, P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Save As", EditorStyles.toolbarButton, GUILayout.Width(55)) == true) { HandleSaveAs(); } P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseUp) { dragId = -1; dragHandle = -1; } switch (currentState) { case StateType.Scene: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); objectsScrollPosition = GUILayout.BeginScrollView(objectsScrollPosition, GUILayout.Width(200)); UpdateObjectsPanel(); GUILayout.EndScrollView(); DrawViewport(); materialsScrollPosition = GUILayout.BeginScrollView(materialsScrollPosition, GUILayout.Width(200)); UpdateMaterialsPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Paint: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); GUILayout.BeginVertical(GUILayout.Width(200)); brushesScrollPosition = GUILayout.BeginScrollView(brushesScrollPosition, GUILayout.ExpandWidth(true)); UpdatePaintBrushesPanel(200); GUILayout.EndScrollView(); dynamicsScrollPosition = GUILayout.BeginScrollView(dynamicsScrollPosition, GUILayout.ExpandWidth(true), GUILayout.Height(200)); UpdateDynamicsPanel(); GUILayout.EndScrollView(); GUILayout.EndVertical(); DrawViewport(); paintScrollPosition = GUILayout.BeginScrollView(paintScrollPosition, GUILayout.Width(200)); UpdatePaintMaterialsPanel(200); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Layer: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); repeatersScrollPosition = GUILayout.BeginScrollView(repeatersScrollPosition, GUILayout.Width(200)); UpdateClonersPanel(); GUILayout.EndScrollView(); DrawViewport(); layersScrollPosition = GUILayout.BeginScrollView(layersScrollPosition, GUILayout.Width(200)); UpdateLayersPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Config: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); sceneScrollPosition = GUILayout.BeginScrollView(sceneScrollPosition, GUILayout.Width(200)); UpdateScenePanel(); GUILayout.EndScrollView(); DrawViewport(); settingsScrollPosition = GUILayout.BeginScrollView(settingsScrollPosition, GUILayout.Width(200)); UpdateSettingsPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUILayout.LabelField("Undo state " + stateIndex + " of " + states.Count, GUILayout.Width(135)); EditorGUILayout.Separator(); scene = (P3dScene)EditorGUILayout.ObjectField(scene, typeof(P3dScene), false, GUILayout.MinWidth(50)); EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(55)) == true) { HandleExport(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); HandleDraw(); if (pendingUpdate == true && Event.current.type == EventType.Repaint) { pendingUpdate = false; UpdatePaintedMats(); } Repaint(); }