Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building runtime editing example to standalone #199

Merged
merged 5 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Runtime/Core/ProBuilderMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public IList<SharedVertex> sharedVertices
{
if ((m_CacheValid & CacheValidState.SharedVertex) != CacheValidState.SharedVertex)
{
if (m_SharedVertexLookup == null)
m_SharedVertexLookup = new Dictionary<int, int>();
SharedVertex.GetSharedVertexLookup(m_SharedVertices, m_SharedVertexLookup);
m_CacheValid |= CacheValidState.SharedVertex;
}
Expand Down
113 changes: 98 additions & 15 deletions Samples~/Runtime/Runtime Editing/MeshEditorScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ LightmapSettings:
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
Expand All @@ -120,6 +120,53 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &2277086
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2277087}
- component: {fileID: 2277088}
m_Layer: 0
m_Name: Handles
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2277087
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2277086}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 656536841}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2277088
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2277086}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 66763c701ecd4747b117f3fd153dc4ed, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FaceHighlight: {fileID: 4800000, guid: 6f37d9e45fbae41b386f76d3bfefec4a, type: 3}
m_LineBillboard: {fileID: 4800000, guid: 4293210a3280c4283b9872316017f1f9, type: 3}
m_PointBillboard: {fileID: 4800000, guid: 8ca8b34aa013842f3b399b6961e7dc3b, type: 3}
m_VertexShader: {fileID: 4800000, guid: d6e5744ac426949ff8c0f02936689d4c, type: 3}
--- !u!1 &112140836
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -213,7 +260,6 @@ MonoBehaviour:
m_GameObject: {fileID: 112140836}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 11500000, guid: 5c9c851079c8c42de80d622ca825a9dc, type: 3}
m_Name:
m_EditorClassIdentifier:
Expand Down Expand Up @@ -269,7 +315,6 @@ MonoBehaviour:
m_GameObject: {fileID: 263074387}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 11500000, guid: 8233d90336aea43098adf6dbabd606a2, type: 3}
m_Name:
m_EditorClassIdentifier:
Expand Down Expand Up @@ -501,6 +546,7 @@ MeshRenderer:
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
Expand Down Expand Up @@ -579,6 +625,7 @@ MeshRenderer:
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
Expand Down Expand Up @@ -608,7 +655,6 @@ MonoBehaviour:
m_GameObject: {fileID: 488875049}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 11500000, guid: c5e18053250949969ca18bc5c8b35805, type: 3}
m_Name:
m_EditorClassIdentifier:
Expand Down Expand Up @@ -823,6 +869,7 @@ Transform:
- {fileID: 1816950047}
- {fileID: 488875053}
- {fileID: 1517202986}
- {fileID: 2277087}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -867,19 +914,40 @@ Light:
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &960534280
Expand Down Expand Up @@ -924,8 +992,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1419486695}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
Expand All @@ -942,8 +1009,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1419486695}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
Expand Down Expand Up @@ -1024,8 +1090,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1427483072}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
Expand All @@ -1044,8 +1109,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1427483072}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
Expand Down Expand Up @@ -1106,19 +1170,40 @@ Light:
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1517202986
Expand Down Expand Up @@ -1181,8 +1266,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1785512225}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
Expand Down Expand Up @@ -1241,7 +1325,6 @@ MonoBehaviour:
m_GameObject: {fileID: 1816950045}
m_Enabled: 1
m_EditorHideFlags: 0
m_GeneratorAsset: {fileID: 0}
m_Script: {fileID: 11500000, guid: b1980aa2876b44faeb9680d0c72b418b, type: 3}
m_Name:
m_EditorClassIdentifier:
Expand Down
7 changes: 7 additions & 0 deletions Samples~/Runtime/Runtime Editing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Important

By default, ProBuilder scripts are removed during the build process. To enable runtime editing in Standalone builds:

- Open the **Preferences** window
- Select the **ProBuilder** category
- Under **General**, un-check **Script Stripping**
7 changes: 7 additions & 0 deletions Samples~/Runtime/Runtime Editing/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions Samples~/Runtime/Runtime Editing/Scripts/Handles.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.ProBuilder;
using UnityEngine.Rendering;

namespace ProBuilder.Examples
{
static class Handles
{
class Handles : MonoBehaviour
{
static Handles s_Instance;
static bool s_Initialized;
static Material s_EdgeMaterial;
#pragma warning disable 649
public Shader m_FaceHighlight;
public Shader m_LineBillboard;
public Shader m_PointBillboard;
public Shader m_VertexShader;
#pragma warning restore 649
static Material s_EdgeMaterial;
static Material s_VertMaterial;
static Material s_FaceMaterial;
static Face[] s_FaceArray = new Face[1];

static void Init()
{
void Awake()
{
s_Instance = this;
}

static void Init()
{
if (s_Instance == null)
Debug.LogError("No Handles object found in scene");

if (s_Initialized)
return;

s_Initialized = true;

var lineShader = BuiltinMaterials.geometryShadersSupported ? BuiltinMaterials.lineShader : BuiltinMaterials.wireShader;
var vertShader = BuiltinMaterials.geometryShadersSupported ? BuiltinMaterials.pointShader : BuiltinMaterials.dotShader;
var lineShader = BuiltinMaterials.geometryShadersSupported ? s_Instance.m_LineBillboard : s_Instance.m_FaceHighlight;
var vertShader = BuiltinMaterials.geometryShadersSupported ? s_Instance.m_PointBillboard : s_Instance.m_VertexShader;

s_EdgeMaterial = new Material(Shader.Find(lineShader));
s_VertMaterial = new Material(Shader.Find(vertShader));
s_FaceMaterial = new Material(Shader.Find(BuiltinMaterials.faceShader));
s_EdgeMaterial = new Material(lineShader);
s_VertMaterial = new Material(vertShader);
s_FaceMaterial = new Material(s_Instance.m_FaceHighlight);
s_FaceMaterial.SetFloat("_Dither", 1f);
}

Expand Down
14 changes: 8 additions & 6 deletions Samples~/Runtime/Runtime Editing/Scripts/MeshEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class MeshEditor : MonoBehaviour

class MeshState
{
public ProBuilderMesh mesh;
public Vector3[] vertices;
public Vector3[] origins;
public List<int> indices;

public MeshState(ProBuilderMesh mesh, IList<int> selectedIndices)
{
this.mesh = mesh;
vertices = mesh.positions.ToArray();
indices = mesh.GetCoincidentVertices(selectedIndices);
origins = new Vector3[indices.Count];
Expand Down Expand Up @@ -108,7 +110,7 @@ void HandleInput()

void BeginDrag()
{
if (m_DragState.active)
if (m_DragState.active || m_Selection.mesh == null || m_Selection.face == null)
return;

m_DragState.active = true;
Expand All @@ -133,19 +135,19 @@ void UpdateDrag()
{
var distance = GetDragDistance() - m_DragState.offset;

var mesh = m_Selection.mesh;
var indices = m_DragState.meshState.indices;
var vertices = m_DragState.meshState.vertices;
var origins = m_DragState.meshState.origins;
// Constraint is in world coordinates, but we need model space when applying changes to mesh values.
var direction = m_Selection.mesh.transform.InverseTransformDirection(m_DragState.constraint.direction);
var direction = mesh.transform.InverseTransformDirection(m_DragState.constraint.direction);

for (int i = 0, c = indices.Count; i < c; i++)
vertices[indices[i]] = origins[i] + direction * distance;

m_Selection.mesh.positions = vertices;

m_Selection.mesh.ToMesh();
m_Selection.mesh.Refresh();
mesh.positions = vertices;
mesh.ToMesh();
mesh.Refresh();
}

float GetDragDistance()
Expand Down