private void SetLivePreviewTerrain(GStylizedTerrain terrain) { GLivePreviewParams param = GTextureToolParams.Instance.LivePreview; param.Terrain = terrain; GTextureToolParams.Instance.LivePreview = param; }
private void DrawLivePreviewParamsGUI() { string id = "texture-editor-live-preview"; string label = "Live Preview"; GEditorCommon.Foldout(label, true, id, () => { GLivePreviewParams param = GTextureToolParams.Instance.LivePreview; param.Enable = EditorGUILayout.Toggle("Enable", param.Enable); GUI.enabled = !lockLivePreviewTerrain; param.Terrain = EditorGUILayout.ObjectField("Terrain", param.Terrain, typeof(GStylizedTerrain), true) as GStylizedTerrain; GUI.enabled = param.Mode == GLivePreviewMode.Mask; param.Color = EditorGUILayout.ColorField("Color", param.Color); GUI.enabled = true; param.Mode = (GLivePreviewMode)EditorGUILayout.EnumPopup("Mode", param.Mode); GTextureToolParams.Instance.LivePreview = param; }); }
private void OnBeginCameraRender(Camera cam) { GLivePreviewParams livePreviewParam = GTextureToolParams.Instance.LivePreview; if (!livePreviewParam.Enable || livePreviewParam.Terrain == null) { return; } GGeneralParams generalParam = GTextureToolParams.Instance.General; Material mat = GInternalMaterials.UnlitTextureMaterial; livePreviewMaterialProperties.Clear(); if (livePreviewParam.Mode == GLivePreviewMode.Mask) { mat = GInternalMaterials.MaskVisualizerMaterial; livePreviewMaterialProperties.SetTexture("_MainTex", PreviewRt); livePreviewMaterialProperties.SetColor("_Color", livePreviewParam.Color); } else if (livePreviewParam.Mode == GLivePreviewMode.ColorMap) { mat = GInternalMaterials.UnlitTextureMaterial; livePreviewMaterialProperties.SetTexture("_MainTex", PreviewRt); } else if (livePreviewParam.Mode == GLivePreviewMode.Geometry) { mat = GInternalMaterials.GeometryLivePreviewMaterial; GStylizedTerrain t = livePreviewParam.Terrain; Vector3 terrainSize = new Vector3( t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length); livePreviewMaterialProperties.SetTexture("_OldHeightMap", t.TerrainData.Geometry.HeightMap); livePreviewMaterialProperties.SetTexture("_NewHeightMap", PreviewRt); livePreviewMaterialProperties.SetTexture("_MainTex", PreviewRt); livePreviewMaterialProperties.SetFloat("_Height", t.TerrainData.Geometry.Height); livePreviewMaterialProperties.SetVector("_BoundMin", t.transform.position); livePreviewMaterialProperties.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize)); } GTerrainChunk[] chunks = livePreviewParam.Terrain.GetChunks(); for (int i = 0; i < chunks.Length; ++i) { Mesh m = chunks[i].MeshFilterComponent.sharedMesh; if (m == null) { continue; } Graphics.DrawMesh( m, chunks[i].transform.localToWorldMatrix, mat, chunks[i].gameObject.layer, cam, 0, livePreviewMaterialProperties, false, false); } }