浏览代码
Twas the night before Poly Brush, and all was quiet and safe. No errors in the console, least till the packages awake.
Twas the night before Poly Brush, and all was quiet and safe. No errors in the console, least till the packages awake.
Also saving before I upgrade Shader Graph/main
John-O-Really
6 年前
当前提交
18f9cdc5
共有 579 个文件被更改,包括 7919 次插入 和 153 次删除
-
6Assets/IslandScene/Water/Material_IslandWater.mat
-
538Assets/IslandScene/Water/Shader_IslandWater.ShaderGraph
-
2ProjectSettings/ProjectVersion.txt
-
8Assets/IslandScene/Fish/Materials.meta
-
8Assets/IslandScene/Fish/TropicalFish03.fbm.meta
-
8Assets/ProCore.meta
-
76Assets/IslandScene/Fish/Materials/TropicalFish03-02 - Default.mat
-
8Assets/IslandScene/Fish/Materials/TropicalFish03-02 - Default.mat.meta
-
602Assets/IslandScene/Fish/TropicalFish03.fbm/TropicalFish02.jpg
-
132Assets/IslandScene/Fish/TropicalFish03.fbm/TropicalFish02.jpg.meta
-
9Assets/ProCore/Polybrush.meta
-
8Assets/ProCore/Polybrush/Brush Settings.meta
-
43Assets/ProCore/Polybrush/Brush Settings/Default.asset
-
8Assets/ProCore/Polybrush/Brush Settings/Default.asset.meta
-
9Assets/ProCore/Polybrush/Code.meta
-
9Assets/ProCore/Polybrush/Code/Editor.meta
-
9Assets/ProCore/Polybrush/Code/Editor/Brush Modes.meta
-
206Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushMode.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushMode.cs.meta
-
94Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeMesh.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeMesh.cs.meta
-
393Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModePaint.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModePaint.cs.meta
-
434Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModePrefab.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModePrefab.cs.meta
-
123Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeRaiseLower.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeRaiseLower.cs.meta
-
129Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeSculpt.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeSculpt.cs.meta
-
115Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeSmooth.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeSmooth.cs.meta
-
422Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeTexture.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Brush Modes/z_BrushModeTexture.cs.meta
-
9Assets/ProCore/Polybrush/Code/Editor/Classes.meta
-
134Assets/ProCore/Polybrush/Code/Editor/Classes/z_BrushSettings.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_BrushSettings.cs.meta
-
100Assets/ProCore/Polybrush/Code/Editor/Classes/z_BrushTarget.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_BrushTarget.cs.meta
-
47Assets/ProCore/Polybrush/Code/Editor/Classes/z_ColorPalette.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_ColorPalette.cs.meta
-
4Assets/ProCore/Polybrush/Code/Editor/Classes/z_Delegate.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_Delegate.cs.meta
-
507Assets/ProCore/Polybrush/Code/Editor/Classes/z_EditableObject.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_EditableObject.cs.meta
-
66Assets/ProCore/Polybrush/Code/Editor/Classes/z_LocalPref.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_LocalPref.cs.meta
-
30Assets/ProCore/Polybrush/Code/Editor/Classes/z_PrefabAndSettings.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_PrefabAndSettings.cs.meta
-
20Assets/ProCore/Polybrush/Code/Editor/Classes/z_PrefabPalette.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_PrefabPalette.cs.meta
-
220Assets/ProCore/Polybrush/Code/Editor/Classes/z_PreferenceDictionary.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_PreferenceDictionary.cs.meta
-
77Assets/ProCore/Polybrush/Code/Editor/Classes/z_RaycastHit.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_RaycastHit.cs.meta
-
437Assets/ProCore/Polybrush/Code/Editor/Classes/z_ReflectionUtil.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Classes/z_ReflectionUtil.cs.meta
-
9Assets/ProCore/Polybrush/Code/Editor/Enum.meta
-
42Assets/ProCore/Polybrush/Code/Editor/Enum/z_BrushTool.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Enum/z_BrushTool.cs.meta
-
9Assets/ProCore/Polybrush/Code/Editor/Interface.meta
-
80Assets/ProCore/Polybrush/Code/Editor/Interface/z_About.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_About.cs.meta
-
49Assets/ProCore/Polybrush/Code/Editor/Interface/z_AdditionalVertexStreamsEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_AdditionalVertexStreamsEditor.cs.meta
-
76Assets/ProCore/Polybrush/Code/Editor/Interface/z_AttributeLayoutContainerEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_AttributeLayoutContainerEditor.cs.meta
-
148Assets/ProCore/Polybrush/Code/Editor/Interface/z_AttributeLayoutJsonEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_AttributeLayoutJsonEditor.cs.meta
-
52Assets/ProCore/Polybrush/Code/Editor/Interface/z_BlendMaterialInspector.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_BlendMaterialInspector.cs.meta
-
197Assets/ProCore/Polybrush/Code/Editor/Interface/z_BrushSettingsEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_BrushSettingsEditor.cs.meta
-
366Assets/ProCore/Polybrush/Code/Editor/Interface/z_ColorPaletteEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_ColorPaletteEditor.cs.meta
-
1001Assets/ProCore/Polybrush/Code/Editor/Interface/z_Editor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_Editor.cs.meta
-
113Assets/ProCore/Polybrush/Code/Editor/Interface/z_GlobalSettingsEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_GlobalSettingsEditor.cs.meta
-
38Assets/ProCore/Polybrush/Code/Editor/Interface/z_MeshFilterEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_MeshFilterEditor.cs.meta
-
207Assets/ProCore/Polybrush/Code/Editor/Interface/z_PrefabPaletteEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_PrefabPaletteEditor.cs.meta
-
125Assets/ProCore/Polybrush/Code/Editor/Interface/z_PreferenceDictionaryEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_PreferenceDictionaryEditor.cs.meta
-
34Assets/ProCore/Polybrush/Code/Editor/Interface/z_SplatWeightEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_SplatWeightEditor.cs.meta
-
59Assets/ProCore/Polybrush/Code/Editor/Interface/z_ZoomOverrideEditor.cs
-
12Assets/ProCore/Polybrush/Code/Editor/Interface/z_ZoomOverrideEditor.cs.meta
-
9Assets/ProCore/Polybrush/Code/Editor/Utility.meta
538
Assets/IslandScene/Water/Shader_IslandWater.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
m_EditorVersion: 2018.2.4f1 |
|||
m_EditorVersion: 2018.2.8f1 |
|
|||
fileFormatVersion: 2 |
|||
guid: 8bc88451f67a54a48ae59b0f048b8702 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3174d514c25b94a4f905d43660eb20fb |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1610a8ff9609c5641861aeea9edbc5d4 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: TropicalFish03-02 - Default |
|||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_DoubleSidedGI: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailAlbedoMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMask: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 2800000, guid: 9a919a681b93f5f4d9dc8bc8d1528285, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ParallaxMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- _BumpScale: 1 |
|||
- _Cutoff: 0.5 |
|||
- _DetailNormalMapScale: 1 |
|||
- _DstBlend: 0 |
|||
- _GlossMapScale: 1 |
|||
- _Glossiness: 0 |
|||
- _GlossyReflections: 1 |
|||
- _Metallic: 0 |
|||
- _Mode: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _Parallax: 0.02 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 1 |
|||
- _UVSec: 0 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _Color: {r: 0.5882353, g: 0.5882353, b: 0.5882353, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5da75daabe504794eabf02a8eef7740a |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
602
Assets/IslandScene/Fish/TropicalFish03.fbm/TropicalFish02.jpg
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 9a919a681b93f5f4d9dc8bc8d1528285 |
|||
TextureImporter: |
|||
fileIDToRecycleName: {} |
|||
externalObjects: {} |
|||
serializedVersion: 7 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
streamingMipmaps: 0 |
|||
streamingMipmapsPriority: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: 2 |
|||
mipBias: -100 |
|||
wrapU: 0 |
|||
wrapV: 0 |
|||
wrapW: 0 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spritePixelsToUnits: 100 |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spriteGenerateFallbackPhysicsShape: 1 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
singleChannelComponent: 0 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- serializedVersion: 2 |
|||
buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 8192 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
- serializedVersion: 2 |
|||
buildTarget: Standalone |
|||
maxTextureSize: 8192 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
- serializedVersion: 2 |
|||
buildTarget: iPhone |
|||
maxTextureSize: 4096 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: 32 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 1 |
|||
androidETC2FallbackOverride: 0 |
|||
- serializedVersion: 2 |
|||
buildTarget: Android |
|||
maxTextureSize: 4096 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: 34 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 1 |
|||
androidETC2FallbackOverride: 0 |
|||
- serializedVersion: 2 |
|||
buildTarget: Windows Store Apps |
|||
maxTextureSize: 8192 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
bones: [] |
|||
spriteID: |
|||
vertices: [] |
|||
indices: |
|||
edges: [] |
|||
weights: [] |
|||
spritePackingTag: |
|||
pSDRemoveMatte: 0 |
|||
pSDShowRemoveMatteOption: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e88df36e2b19b854eb1458fd08552791 |
|||
folderAsset: yes |
|||
timeCreated: 1444938565 |
|||
licenseType: Store |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c3e11b7f11f9c9a4b9d67a4ac473779e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 0c229c73eab51b9478029375e5ca314a, type: 3} |
|||
m_Name: Default |
|||
m_EditorClassIdentifier: |
|||
brushRadiusMin: 0.001 |
|||
brushRadiusMax: 5 |
|||
_radius: 1 |
|||
_falloff: 0.5 |
|||
_strength: 1 |
|||
_curve: |
|||
serializedVersion: 2 |
|||
m_Curve: |
|||
- serializedVersion: 3 |
|||
time: 0 |
|||
value: 1 |
|||
inSlope: 0 |
|||
outSlope: 0 |
|||
tangentMode: 0 |
|||
weightedMode: 0 |
|||
inWeight: 0 |
|||
outWeight: 0 |
|||
- serializedVersion: 3 |
|||
time: 1 |
|||
value: 0 |
|||
inSlope: -3 |
|||
outSlope: -3 |
|||
tangentMode: 0 |
|||
weightedMode: 0 |
|||
inWeight: 0 |
|||
outWeight: 0 |
|||
m_PreInfinity: 2 |
|||
m_PostInfinity: 2 |
|||
m_RotationOrder: 4 |
|||
allowNonNormalizedFalloff: 0 |
|
|||
fileFormatVersion: 2 |
|||
guid: 371c9f00ac06ade40bc1547283173ae0 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 11400000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c173ce858118bfd4cad923b0608a888b |
|||
folderAsset: yes |
|||
timeCreated: 1444938570 |
|||
licenseType: Store |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7416ccb9a80991e4fb5678884b5098d2 |
|||
folderAsset: yes |
|||
timeCreated: 1444938577 |
|||
licenseType: Store |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b408c10689a2f164fa20aaf168c0872f |
|||
folderAsset: yes |
|||
timeCreated: 1447947185 |
|||
licenseType: Store |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// #define Z_DEBUG
|
|||
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Polybrush |
|||
{ |
|||
/** |
|||
* Base class for brush modes. |
|||
*/ |
|||
[System.Serializable] |
|||
public abstract class z_BrushMode : ScriptableObject |
|||
{ |
|||
// The message that will accompany Undo commands for this brush. Undo/Redo is handled by z_Editor.
|
|||
public virtual string UndoMessage { get { return "Apply Brush"; } } |
|||
|
|||
// A temporary component attached to the currently editing object. Use this to (by default) override the
|
|||
// scene zoom functionality, or optionally extend (see z_OverlayRenderer).
|
|||
[SerializeField] protected z_ZoomOverride tempComponent; |
|||
|
|||
// The title to be displayed in the settings header.
|
|||
protected abstract string ModeSettingsHeader { get; } |
|||
|
|||
// The link to the documentation page for this mode.
|
|||
protected abstract string DocsLink { get; } |
|||
|
|||
protected Color innerColor, outerColor; |
|||
|
|||
protected virtual void CreateTempComponent(z_EditableObject target, z_BrushSettings settings) |
|||
{ |
|||
if(!z_Util.IsValid(target)) |
|||
return; |
|||
|
|||
tempComponent = target.gameObject.AddComponent<z_ZoomOverride>(); |
|||
tempComponent.hideFlags = HideFlags.HideAndDontSave; |
|||
tempComponent.SetWeights(null, 0f); |
|||
} |
|||
|
|||
protected virtual void UpdateTempComponent(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
if(!z_Util.IsValid(target)) |
|||
return; |
|||
|
|||
tempComponent.SetWeights(target.GetAllWeights(), settings.strength); |
|||
} |
|||
|
|||
protected virtual void DestroyTempComponent() |
|||
{ |
|||
if(tempComponent != null) |
|||
GameObject.DestroyImmediate(tempComponent); |
|||
} |
|||
|
|||
// Called on instantiation. Base implementation sets HideFlags.
|
|||
public virtual void OnEnable() |
|||
{ |
|||
this.hideFlags = HideFlags.HideAndDontSave; |
|||
|
|||
innerColor = z_Pref.GetColor(z_Pref.brushColor); |
|||
outerColor = z_Pref.GetGradient(z_Pref.brushGradient).Evaluate(1f); |
|||
|
|||
innerColor.a = .9f; |
|||
outerColor.a = .35f; |
|||
} |
|||
|
|||
// Called when mode is disabled.
|
|||
public virtual void OnDisable() |
|||
{ |
|||
DestroyTempComponent(); |
|||
} |
|||
|
|||
// Called by z_Editor when brush settings have been modified.
|
|||
public virtual void OnBrushSettingsChanged(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
UpdateTempComponent(target, settings); |
|||
} |
|||
|
|||
// Inspector GUI shown in the Editor window.
|
|||
public virtual void DrawGUI(z_BrushSettings brushSettings) |
|||
{ |
|||
if( z_GUILayout.HeaderWithDocsLink( z_GUI.TempContent(ModeSettingsHeader, "")) ) |
|||
Application.OpenURL(DocsLink); |
|||
} |
|||
|
|||
// Called when the mouse begins hovering an editable object.
|
|||
public virtual void OnBrushEnter(z_EditableObject target, z_BrushSettings settings) |
|||
{ |
|||
if(z_Pref.GetBool(z_Pref.hideWireframe) && target.renderer != null) |
|||
{ |
|||
// disable wirefame
|
|||
z_EditorUtility.SetSelectionRenderState(target.renderer, z_EditorUtility.GetSelectionRenderState() & z_SelectionRenderState.Outline); |
|||
} |
|||
|
|||
CreateTempComponent(target, settings); |
|||
} |
|||
|
|||
// Called whenever the brush is moved. Note that @target may have a null editableObject.
|
|||
public virtual void OnBrushMove(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
UpdateTempComponent(target, settings); |
|||
} |
|||
|
|||
// Called when the mouse exits hovering an editable object.
|
|||
public virtual void OnBrushExit(z_EditableObject target) |
|||
{ |
|||
if(target.renderer != null) |
|||
z_EditorUtility.SetSelectionRenderState(target.renderer, z_EditorUtility.GetSelectionRenderState()); |
|||
|
|||
DestroyTempComponent(); |
|||
} |
|||
|
|||
// Called when the mouse begins a drag across a valid target.
|
|||
public virtual void OnBrushBeginApply(z_BrushTarget target, z_BrushSettings settings) {} |
|||
|
|||
// Called every time the brush should apply itself to a valid target. Default is on mouse move.
|
|||
public abstract void OnBrushApply(z_BrushTarget target, z_BrushSettings settings); |
|||
|
|||
// Called when a brush application has finished. Use this to clean up temporary resources or apply
|
|||
// deferred actions to a mesh (rebuild UV2, tangents, whatever).
|
|||
public virtual void OnBrushFinishApply(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
DestroyTempComponent(); |
|||
} |
|||
|
|||
// Draw scene gizmos. Base implementation draws the brush preview.
|
|||
public virtual void DrawGizmos(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
foreach(z_RaycastHit hit in target.raycastHits) |
|||
z_Handles.DrawBrush(hit.position, hit.normal, settings, target.localToWorldMatrix, innerColor, outerColor); |
|||
|
|||
#if Z_DEBUG
|
|||
|
|||
#if Z_DRAW_WEIGHTS || DRAW_PER_VERTEX_ATTRIBUTES
|
|||
float[] w = target.GetAllWeights(); |
|||
#endif
|
|||
|
|||
#if Z_DRAW_WEIGHTS
|
|||
Mesh m = target.mesh; |
|||
Vector3[] v = m.vertices; |
|||
GUIContent content = new GUIContent("",""); |
|||
|
|||
Handles.BeginGUI(); |
|||
for(int i = 0; i < v.Length; i++) |
|||
{ |
|||
if(w[i] < .0001f) |
|||
continue; |
|||
|
|||
content.text = w[i].ToString("F2"); |
|||
GUI.Label(HandleUtility.WorldPointToSizedRect(target.transform.TransformPoint(v[i]), content, EditorStyles.label), content); |
|||
} |
|||
Handles.EndGUI(); |
|||
#endif
|
|||
|
|||
#if DRAW_PER_VERTEX_ATTRIBUTES
|
|||
|
|||
z_Mesh m = target.editableObject.editMesh; |
|||
Color32[] colors = m.colors; |
|||
Vector4[] tangents = m.tangents; |
|||
List<Vector4> uv0 = m.uv0; |
|||
List<Vector4> uv1 = m.uv1; |
|||
List<Vector4> uv2 = m.uv2; |
|||
List<Vector4> uv3 = m.uv3; |
|||
|
|||
int vertexCount = m.vertexCount; |
|||
|
|||
Vector3[] verts = m.vertices; |
|||
GUIContent gc = new GUIContent(""); |
|||
|
|||
List<List<int>> common = z_MeshUtility.GetCommonVertices(m); |
|||
System.Text.StringBuilder sb = new System.Text.StringBuilder(); |
|||
|
|||
Handles.BeginGUI(); |
|||
foreach(List<int> l in common) |
|||
{ |
|||
if( w[l[0]] < .001 ) |
|||
continue; |
|||
|
|||
Vector3 v = target.transform.TransformPoint(verts[l[0]]); |
|||
|
|||
if(colors != null) sb.AppendLine("color: " + colors[l[0]].ToString("F2")); |
|||
if(tangents != null) sb.AppendLine("tangent: " + tangents[l[0]].ToString("F2")); |
|||
if(uv0 != null && uv0.Count == vertexCount) sb.AppendLine("uv0: " + uv0[l[0]].ToString("F2")); |
|||
if(uv1 != null && uv1.Count == vertexCount) sb.AppendLine("uv1: " + uv1[l[0]].ToString("F2")); |
|||
if(uv2 != null && uv2.Count == vertexCount) sb.AppendLine("uv2: " + uv2[l[0]].ToString("F2")); |
|||
if(uv3 != null && uv3.Count == vertexCount) sb.AppendLine("uv3: " + uv3[l[0]].ToString("F2")); |
|||
|
|||
gc.text = sb.ToString(); |
|||
sb.Remove(0, sb.Length); // @todo .NET 4.0
|
|||
GUI.Label(HandleUtility.WorldPointToSizedRect(v, gc, EditorStyles.label), gc); |
|||
} |
|||
Handles.EndGUI(); |
|||
#endif
|
|||
|
|||
#endif
|
|||
} |
|||
|
|||
public abstract void RegisterUndo(z_BrushTarget brushTarget); |
|||
|
|||
public virtual void UndoRedoPerformed(List<GameObject> modified) |
|||
{ |
|||
DestroyTempComponent(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ef7af1d5fe5c313488bb9b9ebc72fd2c |
|||
timeCreated: 1445433619 |
|||
licenseType: Store |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
|
|||
namespace Polybrush |
|||
{ |
|||
/** |
|||
* Base class for brush modes that modify the mesh. |
|||
*/ |
|||
[System.Serializable] |
|||
public abstract class z_BrushModeMesh : z_BrushMode |
|||
{ |
|||
// All meshes that have ever been modified, ever. Kept around to refresh mesh vertices
|
|||
// on Undo/Redo since Unity doesn't.
|
|||
private HashSet<Mesh> modifiedMeshes = new HashSet<Mesh>(); |
|||
private HashSet<object> modifiedPbMeshes = new HashSet<object>(); |
|||
EditorWindow _pbEditor = null; |
|||
|
|||
public override void OnBrushBeginApply(z_BrushTarget brushTarget, z_BrushSettings brushSettings) |
|||
{ |
|||
_pbEditor = z_ReflectionUtil.ProBuilderEditorWindow; |
|||
|
|||
base.OnBrushBeginApply(brushTarget, brushSettings); |
|||
} |
|||
|
|||
public override void OnBrushApply(z_BrushTarget brushTarget, z_BrushSettings brushSettings) |
|||
{ |
|||
// false means no ToMesh or Refresh, true does. Optional addl bool runs pb_Object.Optimize()
|
|||
brushTarget.editableObject.Apply(true); |
|||
|
|||
if(_pbEditor != null) |
|||
z_ReflectionUtil.Invoke(_pbEditor, "Internal_UpdateSelectionFast", BindingFlags.Instance | BindingFlags.NonPublic); |
|||
|
|||
UpdateTempComponent(brushTarget, brushSettings); |
|||
} |
|||
|
|||
public override void RegisterUndo(z_BrushTarget brushTarget) |
|||
{ |
|||
if(z_ReflectionUtil.IsProBuilderObject(brushTarget.gameObject)) |
|||
{ |
|||
object pb = z_ReflectionUtil.GetComponent(brushTarget.gameObject, "pb_Object"); |
|||
Undo.RegisterCompleteObjectUndo(pb as UnityEngine.Object, UndoMessage); |
|||
modifiedPbMeshes.Add(pb); |
|||
} |
|||
else |
|||
{ |
|||
Undo.RegisterCompleteObjectUndo(brushTarget.editableObject.graphicsMesh, UndoMessage); |
|||
modifiedMeshes.Add(brushTarget.editableObject.graphicsMesh); |
|||
} |
|||
|
|||
brushTarget.editableObject.isDirty = true; |
|||
} |
|||
|
|||
public override void UndoRedoPerformed(List<GameObject> modified) |
|||
{ |
|||
modifiedMeshes = new HashSet<Mesh>(modifiedMeshes.Where(x => x != null)); |
|||
|
|||
if(z_ReflectionUtil.ProBuilderExists()) |
|||
{ |
|||
// delete & undo causes cases where object is not null but the reference to it's pb_Object is
|
|||
HashSet<object> remove = new HashSet<object>(); |
|||
|
|||
foreach(object pb in modifiedPbMeshes) |
|||
{ |
|||
try |
|||
{ |
|||
z_ReflectionUtil.ProBuilder_ToMesh(pb); |
|||
z_ReflectionUtil.ProBuilder_Refresh(pb); |
|||
z_ReflectionUtil.ProBuilder_Optimize(pb); |
|||
} |
|||
catch |
|||
{ |
|||
remove.Add(pb); |
|||
} |
|||
|
|||
} |
|||
|
|||
if(remove.Count() > 0) |
|||
modifiedPbMeshes.SymmetricExceptWith(remove); |
|||
} |
|||
|
|||
foreach(Mesh m in modifiedMeshes) |
|||
{ |
|||
m.vertices = m.vertices; |
|||
m.UploadMeshData(false); |
|||
} |
|||
|
|||
base.UndoRedoPerformed(modified); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 28a002c53bdb2204f8ff3786a5af1b27 |
|||
timeCreated: 1447956411 |
|||
licenseType: Store |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Polybrush |
|||
{ |
|||
/** |
|||
* Vertex painter brush mode. |
|||
*/ |
|||
public class z_BrushModePaint : z_BrushModeMesh |
|||
{ |
|||
// how many applications it should take to reach the full strength
|
|||
const float STRENGTH_MODIFIER = 1f/8f; |
|||
private static readonly Color32 WHITE = new Color32(255, 255, 255, 255); |
|||
|
|||
[SerializeField] z_PaintMode paintMode = z_PaintMode.Brush; |
|||
[SerializeField] bool likelySupportsVertexColors = false; |
|||
|
|||
// mesh vertex colors
|
|||
[SerializeField] Color32[] colors_cache = null, target_colors = null, erase_colors = null, colors = null; |
|||
[SerializeField] Color32 brushColor = Color.green; |
|||
|
|||
z_ColorMask mask = new z_ColorMask(true, true, true, true); |
|||
|
|||
z_ColorPalette[] availablePalettes = null; |
|||
string[] availablePalettes_str = null; |
|||
int currentPaletteIndex = -1; |
|||
|
|||
// temp vars
|
|||
private z_Edge[] _fillModeEdges = new z_Edge[3]; |
|||
private List<int> _fillModeAdjacentTris = null; |
|||
|
|||
// used for fill mode
|
|||
Dictionary<z_Edge, List<int>> triangleLookup = null; |
|||
|
|||
public GUIContent[] modeIcons = new GUIContent[] |
|||
{ |
|||
new GUIContent("Brush", "Brush" ), |
|||
new GUIContent("Fill", "Fill" ), |
|||
new GUIContent("Flood", "Flood" ) |
|||
}; |
|||
|
|||
// The current color palette.
|
|||
[SerializeField] z_ColorPalette _colorPalette = null; |
|||
|
|||
private z_ColorPalette colorPalette |
|||
{ |
|||
get |
|||
{ |
|||
if(_colorPalette == null) |
|||
colorPalette = z_EditorUtility.GetDefaultAsset<z_ColorPalette>("Color Palettes/Default.asset"); |
|||
return _colorPalette; |
|||
} |
|||
set |
|||
{ |
|||
_colorPalette = value; |
|||
} |
|||
} |
|||
|
|||
// An Editor for the colorPalette.
|
|||
[SerializeField] z_ColorPaletteEditor _colorPaletteEditor = null; |
|||
|
|||
private z_ColorPaletteEditor colorPaletteEditor |
|||
{ |
|||
get |
|||
{ |
|||
if(_colorPaletteEditor == null || _colorPaletteEditor.target != colorPalette) |
|||
{ |
|||
_colorPaletteEditor = (z_ColorPaletteEditor) Editor.CreateEditor(colorPalette); |
|||
_colorPaletteEditor.hideFlags = HideFlags.HideAndDontSave; |
|||
} |
|||
|
|||
return _colorPaletteEditor; |
|||
} |
|||
} |
|||
|
|||
// The message that will accompany Undo commands for this brush. Undo/Redo is handled by z_Editor.
|
|||
public override string UndoMessage { get { return "Paint Brush"; } } |
|||
protected override string ModeSettingsHeader { get { return "Paint Settings"; } } |
|||
protected override string DocsLink { get { return "http://procore3d.github.io/polybrush/modes/color/"; } } |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
|
|||
//modeIcons[0].image = z_IconUtility.GetIcon("Icon/Brush");
|
|||
//modeIcons[1].image = z_IconUtility.GetIcon("Icon/Roller");
|
|||
//modeIcons[2].image = z_IconUtility.GetIcon("Icon/Flood");
|
|||
|
|||
RefreshAvailablePalettes(); |
|||
} |
|||
|
|||
public override void OnDisable() |
|||
{ |
|||
base.OnDisable(); |
|||
if(_colorPaletteEditor != null) |
|||
Object.DestroyImmediate(_colorPaletteEditor); |
|||
} |
|||
|
|||
|
|||
// Inspector GUI shown in the Editor window. Base class shows z_BrushSettings by default
|
|||
public override void DrawGUI(z_BrushSettings brushSettings) |
|||
{ |
|||
base.DrawGUI(brushSettings); |
|||
|
|||
GUILayout.BeginHorizontal(); |
|||
|
|||
if(colorPalette == null) |
|||
RefreshAvailablePalettes(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
currentPaletteIndex = EditorGUILayout.Popup(currentPaletteIndex, availablePalettes_str, "popup"); |
|||
if(EditorGUI.EndChangeCheck()) |
|||
{ |
|||
if(currentPaletteIndex >= availablePalettes.Length) |
|||
SetColorPalette( z_ColorPaletteEditor.AddNew() ); |
|||
else |
|||
SetColorPalette(availablePalettes[currentPaletteIndex]); |
|||
} |
|||
|
|||
paintMode = (z_PaintMode) GUILayout.Toolbar( (int) paintMode, modeIcons, "Command", GUILayout.Width(120)); |
|||
|
|||
GUILayout.EndHorizontal(); |
|||
|
|||
if(!likelySupportsVertexColors) |
|||
EditorGUILayout.HelpBox("It doesn't look like any of the materials on this object support vertex colors!", MessageType.Warning); |
|||
|
|||
colorPaletteEditor.onSelectIndex = (color) => { SetBrushColor(color, brushSettings.strength); }; |
|||
colorPaletteEditor.onSaveAs = SetColorPalette; |
|||
|
|||
mask = z_GUILayout.ColorMaskField("Color Mask", mask); |
|||
|
|||
colorPaletteEditor.OnInspectorGUI(); |
|||
} |
|||
|
|||
private void SetBrushColor(Color color, float strength) |
|||
{ |
|||
brushColor = color; |
|||
RebuildColorTargets(color, strength); |
|||
} |
|||
|
|||
private void RefreshAvailablePalettes() |
|||
{ |
|||
if(colorPalette == null) |
|||
colorPalette = z_EditorUtility.GetDefaultAsset<z_ColorPalette>("Color Palettes/Default.asset"); |
|||
|
|||
availablePalettes = Resources.FindObjectsOfTypeAll<z_ColorPalette>().Where(x => !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(x))).ToArray(); |
|||
availablePalettes_str = availablePalettes.Select(x => x.name).ToArray(); |
|||
ArrayUtility.Add<string>(ref availablePalettes_str, string.Empty); |
|||
ArrayUtility.Add<string>(ref availablePalettes_str, "Add Palette..."); |
|||
currentPaletteIndex = System.Array.IndexOf(availablePalettes, colorPalette); |
|||
} |
|||
|
|||
private void SetColorPalette(z_ColorPalette palette) |
|||
{ |
|||
colorPalette = palette; |
|||
RefreshAvailablePalettes(); |
|||
} |
|||
|
|||
public override void OnBrushSettingsChanged(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushSettingsChanged(target, settings); |
|||
RebuildColorTargets(brushColor, settings.strength); |
|||
} |
|||
|
|||
private void RebuildColorTargets(Color color, float strength) |
|||
{ |
|||
if( colors_cache == null || |
|||
target_colors == null || |
|||
colors_cache.Length != target_colors.Length) |
|||
return; |
|||
|
|||
for(int i = 0; i < colors_cache.Length; i++) |
|||
{ |
|||
target_colors[i] = z_Util.Lerp(colors_cache[i], color, mask, strength); |
|||
erase_colors[i] = z_Util.Lerp(colors_cache[i], WHITE, mask, strength); |
|||
} |
|||
} |
|||
|
|||
// Called when the mouse begins hovering an editable object.
|
|||
public override void OnBrushEnter(z_EditableObject target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushEnter(target, settings); |
|||
|
|||
if(target.graphicsMesh == null) |
|||
return; |
|||
|
|||
RebuildCaches(target, settings); |
|||
|
|||
triangleLookup = z_MeshUtility.GetAdjacentTriangles(target.editMesh); |
|||
|
|||
MeshRenderer mr = target.gameObject.GetComponent<MeshRenderer>(); |
|||
|
|||
if(mr != null && mr.sharedMaterials != null) |
|||
likelySupportsVertexColors = mr.sharedMaterials.Any(x => x.shader != null && z_ShaderUtil.SupportsVertexColors(x.shader)); |
|||
else |
|||
likelySupportsVertexColors = false; |
|||
} |
|||
|
|||
private void RebuildCaches(z_EditableObject target, z_BrushSettings settings) |
|||
{ |
|||
z_Mesh m = target.editMesh; |
|||
int vertexCount = m.vertexCount; |
|||
|
|||
if(m.colors != null && m.colors.Length == vertexCount) |
|||
colors_cache = z_Util.Duplicate(m.colors); |
|||
else |
|||
colors_cache = z_Util.Fill<Color32>( x => { return Color.white; }, vertexCount); |
|||
|
|||
colors = new Color32[vertexCount]; |
|||
target_colors = new Color32[vertexCount]; |
|||
erase_colors = new Color32[vertexCount]; |
|||
|
|||
RebuildColorTargets(brushColor, settings.strength); |
|||
} |
|||
|
|||
// Called whenever the brush is moved. Note that @target may have a null editableObject.
|
|||
public override void OnBrushMove(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushMove(target, settings); |
|||
|
|||
if(!z_Util.IsValid(target)) |
|||
return; |
|||
|
|||
bool shift = Event.current.shift && Event.current.type != EventType.ScrollWheel; |
|||
|
|||
z_Mesh mesh = target.editableObject.editMesh; |
|||
int vertexCount = mesh.vertexCount; |
|||
float[] weights = target.GetAllWeights(); |
|||
|
|||
switch(paintMode) |
|||
{ |
|||
case z_PaintMode.Flood: |
|||
for(int i = 0; i < vertexCount; i++) |
|||
colors[i] = target_colors[i]; |
|||
break; |
|||
|
|||
case z_PaintMode.Fill: |
|||
|
|||
System.Array.Copy(colors_cache, colors, vertexCount); |
|||
int[] indices = target.editableObject.editMesh.GetTriangles(); |
|||
int index = 0; |
|||
|
|||
foreach(z_RaycastHit hit in target.raycastHits) |
|||
{ |
|||
if(hit.triangle > -1) |
|||
{ |
|||
index = hit.triangle * 3; |
|||
|
|||
colors[indices[index + 0]] = shift ? WHITE : target_colors[indices[index + 0]]; |
|||
colors[indices[index + 1]] = shift ? WHITE : target_colors[indices[index + 1]]; |
|||
colors[indices[index + 2]] = shift ? WHITE : target_colors[indices[index + 2]]; |
|||
|
|||
_fillModeEdges[0].x = indices[index+0]; |
|||
_fillModeEdges[0].y = indices[index+1]; |
|||
|
|||
_fillModeEdges[1].x = indices[index+1]; |
|||
_fillModeEdges[1].y = indices[index+2]; |
|||
|
|||
_fillModeEdges[2].x = indices[index+2]; |
|||
_fillModeEdges[2].y = indices[index+0]; |
|||
|
|||
for(int i = 0; i < 3; i++) |
|||
{ |
|||
if(triangleLookup.TryGetValue(_fillModeEdges[i], out _fillModeAdjacentTris)) |
|||
{ |
|||
for(int n = 0; n < _fillModeAdjacentTris.Count; n++) |
|||
{ |
|||
index = _fillModeAdjacentTris[n] * 3; |
|||
|
|||
colors[indices[index + 0]] = shift ? WHITE : target_colors[indices[index + 0]]; |
|||
colors[indices[index + 1]] = shift ? WHITE : target_colors[indices[index + 1]]; |
|||
colors[indices[index + 2]] = shift ? WHITE : target_colors[indices[index + 2]]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
break; |
|||
|
|||
default: |
|||
{ |
|||
for(int i = 0; i < vertexCount; i++) |
|||
{ |
|||
colors[i] = z_Util.Lerp(colors_cache[i], |
|||
shift ? erase_colors[i] : target_colors[i], |
|||
mask, |
|||
weights[i]); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
|
|||
target.editableObject.editMesh.colors = colors; |
|||
target.editableObject.ApplyMeshAttributes(z_MeshChannel.Color); |
|||
} |
|||
|
|||
// Called when the mouse exits hovering an editable object.
|
|||
public override void OnBrushExit(z_EditableObject target) |
|||
{ |
|||
base.OnBrushExit(target); |
|||
|
|||
if(target.editMesh != null) |
|||
{ |
|||
target.editMesh.colors = colors_cache; |
|||
target.ApplyMeshAttributes(z_MeshChannel.Color); |
|||
} |
|||
|
|||
likelySupportsVertexColors = true; |
|||
} |
|||
|
|||
// Called every time the brush should apply itself to a valid target. Default is on mouse move.
|
|||
public override void OnBrushApply(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
System.Array.Copy(colors, colors_cache, colors.Length); |
|||
target.editableObject.editMesh.colors = colors_cache; |
|||
base.OnBrushApply(target, settings); |
|||
} |
|||
|
|||
// set mesh colors back to their original state before registering for undo
|
|||
public override void RegisterUndo(z_BrushTarget brushTarget) |
|||
{ |
|||
brushTarget.editableObject.editMesh.colors = colors_cache; |
|||
brushTarget.editableObject.ApplyMeshAttributes(z_MeshChannel.Color); |
|||
|
|||
base.RegisterUndo(brushTarget); |
|||
} |
|||
|
|||
public override void DrawGizmos(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
if(z_Util.IsValid(target) && paintMode == z_PaintMode.Fill) |
|||
{ |
|||
Vector3[] vertices = target.editableObject.editMesh.vertices; |
|||
int[] indices = target.editableObject.editMesh.GetTriangles(); |
|||
|
|||
z_Handles.PushMatrix(); |
|||
z_Handles.PushHandleColor(); |
|||
|
|||
Handles.matrix = target.transform.localToWorldMatrix; |
|||
|
|||
int index = 0; |
|||
|
|||
foreach(z_RaycastHit hit in target.raycastHits) |
|||
{ |
|||
if(hit.triangle > -1) |
|||
{ |
|||
Handles.color = target_colors[indices[index]]; |
|||
|
|||
index = hit.triangle * 3; |
|||
|
|||
Handles.DrawLine(vertices[indices[index+0]] + hit.normal * .1f, vertices[indices[index+1]] + hit.normal * .1f); |
|||
Handles.DrawLine(vertices[indices[index+1]] + hit.normal * .1f, vertices[indices[index+2]] + hit.normal * .1f); |
|||
Handles.DrawLine(vertices[indices[index+2]] + hit.normal * .1f, vertices[indices[index+0]] + hit.normal * .1f); |
|||
|
|||
_fillModeEdges[0].x = indices[index+0]; |
|||
_fillModeEdges[0].y = indices[index+1]; |
|||
|
|||
_fillModeEdges[1].x = indices[index+1]; |
|||
_fillModeEdges[1].y = indices[index+2]; |
|||
|
|||
_fillModeEdges[2].x = indices[index+2]; |
|||
_fillModeEdges[2].y = indices[index+0]; |
|||
|
|||
for(int i = 0; i < 3; i++) |
|||
{ |
|||
if(triangleLookup.TryGetValue(_fillModeEdges[i], out _fillModeAdjacentTris)) |
|||
{ |
|||
for(int n = 0; n < _fillModeAdjacentTris.Count; n++) |
|||
{ |
|||
index = _fillModeAdjacentTris[n] * 3; |
|||
|
|||
Handles.DrawLine(vertices[indices[index+0]] + hit.normal * .1f, vertices[indices[index+1]] + hit.normal * .1f); |
|||
Handles.DrawLine(vertices[indices[index+1]] + hit.normal * .1f, vertices[indices[index+2]] + hit.normal * .1f); |
|||
Handles.DrawLine(vertices[indices[index+2]] + hit.normal * .1f, vertices[indices[index+0]] + hit.normal * .1f); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
z_Handles.PopHandleColor(); |
|||
z_Handles.PopMatrix(); |
|||
} |
|||
else |
|||
{ |
|||
base.DrawGizmos(target, settings); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f425014c97249344099c3f447082d4bc |
|||
timeCreated: 1446562266 |
|||
licenseType: Store |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Polybrush |
|||
{ |
|||
/** |
|||
* Prefab painter brush mode. |
|||
*/ |
|||
public class z_BrushModePrefab : z_BrushMode |
|||
{ |
|||
const string PREFAB_PALETTE_PATH = "Prefab Palettes/Default.asset"; |
|||
private double lastBrushApplication = 0.0; |
|||
|
|||
private z_LocalPref<bool> hitSurfaceIsParent; |
|||
private z_LocalPref<bool> avoidOverlappingGameObjects; |
|||
private z_LocalPref<int> previewThumbSize; |
|||
|
|||
// preferences
|
|||
private bool placeWithPivot = false; |
|||
|
|||
// The current prefab palette
|
|||
[SerializeField] z_PrefabPalette _prefabPalette = null; |
|||
|
|||
z_PrefabPalette[] availablePalettes = null; |
|||
string[] availablePalettes_str = null; |
|||
int currentPaletteIndex = -1; |
|||
|
|||
private z_PrefabPalette prefabPalette |
|||
{ |
|||
get |
|||
{ |
|||
if(_prefabPalette == null) |
|||
prefabPalette = z_EditorUtility.GetDefaultAsset<z_PrefabPalette>(PREFAB_PALETTE_PATH); |
|||
|
|||
return _prefabPalette; |
|||
} |
|||
set |
|||
{ |
|||
if(prefabPaletteEditor != null) |
|||
GameObject.DestroyImmediate(prefabPaletteEditor); |
|||
|
|||
_prefabPalette = value; |
|||
|
|||
prefabPaletteEditor = (z_PrefabPaletteEditor) Editor.CreateEditor(_prefabPalette); |
|||
prefabPaletteEditor.onSelectionChanged = SelectedPrefab; |
|||
} |
|||
} |
|||
|
|||
// An Editor for the prefabPalette.
|
|||
z_PrefabPaletteEditor prefabPaletteEditor = null; |
|||
|
|||
// all instances of prefabs in the current palette in this scene.
|
|||
private List<GameObject> instances = null; |
|||
private List<z_PrefabAndSettings> queued = null; |
|||
|
|||
public override string UndoMessage { get { return "Paint Prefabs"; } } |
|||
protected override string ModeSettingsHeader { get { return "Placement Settings"; } } |
|||
protected override string DocsLink { get { return "http://procore3d.github.io/polybrush/modes/place/"; } } |
|||
private GUIStyle paletteStyle; |
|||
|
|||
static GUIContent gc_usePrefabPivot = new GUIContent("Use Pivot", "By default Polybrush will position placed objects entirely on top of the target plane. When 'Use Pivot' is enabled objects will instead be placed by their assigned mesh origin."); |
|||
static GUIContent gc_hitSurfaceIsParent = new GUIContent("Hit Surface is Parent", "When enabled any instantiated prefab from this mode will be automatically made a child of the surface it was placed on."); |
|||
static GUIContent gc_avoidOverlappingGameObjects = new GUIContent("Avoid Overlap", "If enabled Polybrush will attempt to avoid placing prefabs where they may overlap with another placed GameObject."); |
|||
|
|||
static string FormatInstanceName(GameObject go) |
|||
{ |
|||
return string.Format("{0}(Clone)", go.name); |
|||
} |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
|
|||
RefreshAvailablePalettes(); |
|||
|
|||
if(_prefabPalette == null) |
|||
prefabPalette = z_EditorUtility.GetDefaultAsset<z_PrefabPalette>(PREFAB_PALETTE_PATH); |
|||
|
|||
if(prefabPaletteEditor != null) |
|||
{ |
|||
Object.DestroyImmediate(prefabPaletteEditor); |
|||
prefabPaletteEditor = null; |
|||
} |
|||
|
|||
prefabPaletteEditor = (z_PrefabPaletteEditor) Editor.CreateEditor(_prefabPalette); |
|||
|
|||
// unity won't serialize delegates, so even if prefabPalette isn't null and the editor remains valid
|
|||
// the delegate could still be null after a script reload.
|
|||
prefabPaletteEditor.onSelectionChanged = SelectedPrefab; |
|||
|
|||
paletteStyle = new GUIStyle(); |
|||
paletteStyle.padding = new RectOffset(8, 8, 8, 8); |
|||
|
|||
hitSurfaceIsParent = new z_LocalPref<bool>("prefab_hitSurfaceIsParent", true); |
|||
avoidOverlappingGameObjects = new z_LocalPref<bool>("prefab_avoidOverlappingGameObjects"); |
|||
previewThumbSize = new z_LocalPref<int>("prefab_previewThumbSize", 64); |
|||
} |
|||
|
|||
public override void OnDisable() |
|||
{ |
|||
base.OnDisable(); |
|||
|
|||
if(prefabPaletteEditor != null) |
|||
{ |
|||
GameObject.DestroyImmediate(prefabPaletteEditor); |
|||
prefabPaletteEditor = null; |
|||
} |
|||
} |
|||
|
|||
// Inspector GUI shown in the Editor window. Base class shows z_BrushSettings by default
|
|||
public override void DrawGUI(z_BrushSettings brushSettings) |
|||
{ |
|||
base.DrawGUI(brushSettings); |
|||
|
|||
placeWithPivot = z_GUILayout.Toggle(gc_usePrefabPivot, placeWithPivot); |
|||
|
|||
z_GlobalSettingsEditor.lockBrushToFirst = z_GUILayout.Toggle(z_GlobalSettingsEditor.gc_lockBrushToFirst, z_GlobalSettingsEditor.lockBrushToFirst); |
|||
|
|||
hitSurfaceIsParent.prefValue = z_GUILayout.Toggle(gc_hitSurfaceIsParent, hitSurfaceIsParent); |
|||
avoidOverlappingGameObjects.prefValue = z_GUILayout.Toggle(gc_avoidOverlappingGameObjects, avoidOverlappingGameObjects); |
|||
|
|||
GUILayout.Space(4); |
|||
|
|||
if(prefabPalette == null) |
|||
RefreshAvailablePalettes(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
currentPaletteIndex = EditorGUILayout.Popup(currentPaletteIndex, availablePalettes_str, "popup"); |
|||
if(EditorGUI.EndChangeCheck()) |
|||
{ |
|||
if(currentPaletteIndex >= availablePalettes.Length) |
|||
SetPrefabPalette( z_PrefabPaletteEditor.AddNew() ); |
|||
else |
|||
SetPrefabPalette(availablePalettes[currentPaletteIndex]); |
|||
} |
|||
|
|||
GUILayout.Space(4); |
|||
|
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label("Prefabs"); |
|||
previewThumbSize.prefValue = (int) GUILayout.HorizontalSlider((float)previewThumbSize, 16f, 128f); |
|||
GUILayout.EndHorizontal(); |
|||
|
|||
GUILayout.BeginVertical( paletteStyle ); |
|||
if(prefabPaletteEditor != null) |
|||
prefabPaletteEditor.OnInspectorGUI_Internal(previewThumbSize); |
|||
GUILayout.EndVertical(); |
|||
} |
|||
|
|||
private void SetPrefabPalette(z_PrefabPalette palette) |
|||
{ |
|||
prefabPalette = palette; |
|||
RefreshAvailablePalettes(); |
|||
} |
|||
|
|||
private void RefreshAvailablePalettes() |
|||
{ |
|||
availablePalettes = Resources.FindObjectsOfTypeAll<z_PrefabPalette>().Where(x => !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(x))).ToArray(); |
|||
availablePalettes_str = availablePalettes.Select(x => x.name).ToArray(); |
|||
ArrayUtility.Add<string>(ref availablePalettes_str, string.Empty); |
|||
ArrayUtility.Add<string>(ref availablePalettes_str, "Add Palette..."); |
|||
currentPaletteIndex = System.Array.IndexOf(availablePalettes, _prefabPalette); |
|||
} |
|||
|
|||
private void SelectedPrefab(IEnumerable<int> selected) |
|||
{ |
|||
if(selected == null) |
|||
queued = null; |
|||
else |
|||
queued = prefabPalette.prefabs.Where( (x, i) => { return selected.Contains(i); } ).ToList(); |
|||
} |
|||
|
|||
public override void OnBrushSettingsChanged(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushSettingsChanged(target, settings); |
|||
} |
|||
|
|||
// Called when the mouse begins hovering an editable object.
|
|||
public override void OnBrushEnter(z_EditableObject target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushEnter(target, settings); |
|||
} |
|||
|
|||
// Called whenever the brush is moved. Note that @target may have a null editableObject.
|
|||
public override void OnBrushMove(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushMove(target, settings); |
|||
} |
|||
|
|||
// Called when the mouse exits hovering an editable object.
|
|||
public override void OnBrushExit(z_EditableObject target) |
|||
{ |
|||
base.OnBrushExit(target); |
|||
} |
|||
|
|||
public override void OnBrushBeginApply(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.OnBrushBeginApply(target, settings); |
|||
instances = z_SceneUtility.FindInstancesInScene(prefabPalette.prefabs.Select(x => x.gameObject), FormatInstanceName).ToList(); |
|||
} |
|||
|
|||
// Called every time the brush should apply itself to a valid target. Default is on mouse move.
|
|||
public override void OnBrushApply(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
bool shift = Event.current.shift && Event.current.type != EventType.ScrollWheel; |
|||
|
|||
if( (EditorApplication.timeSinceStartup - lastBrushApplication) > Mathf.Max(.06f, (1f - settings.strength)) ) |
|||
{ |
|||
lastBrushApplication = EditorApplication.timeSinceStartup; |
|||
|
|||
if(shift) |
|||
{ |
|||
foreach(z_RaycastHit hit in target.raycastHits) |
|||
RemoveGameObjects(hit, target, settings); |
|||
} |
|||
else |
|||
{ |
|||
foreach(z_RaycastHit hit in target.raycastHits) |
|||
PlaceGameObject(hit, GetPrefab().gameObject, target, settings); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Handle Undo locally since it doesn't follow the same pattern as mesh modifications.
|
|||
public override void RegisterUndo(z_BrushTarget brushTarget) {} |
|||
|
|||
private void PlaceGameObject(z_RaycastHit hit, GameObject prefab, z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
if(prefab == null) |
|||
return; |
|||
|
|||
Ray ray = RandomRay(hit.position, hit.normal, settings.radius, settings.falloff, settings.falloffCurve); |
|||
|
|||
z_RaycastHit rand_hit; |
|||
|
|||
Vector3[] vertices = target.editableObject.editMesh.vertices; |
|||
int[] triangles = target.editableObject.editMesh.GetTriangles(); |
|||
|
|||
if( z_SceneUtility.MeshRaycast(ray, vertices, triangles, out rand_hit) ) |
|||
{ |
|||
float pivotOffset = placeWithPivot ? 0f : GetPivotOffset(prefab); |
|||
|
|||
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, target.transform.TransformDirection(rand_hit.normal)); |
|||
Quaternion random = Quaternion.AngleAxis(Random.Range(0f, 360f), Vector3.up); |
|||
|
|||
GameObject inst = PrefabUtility.ConnectGameObjectToPrefab(Instantiate(prefab), prefab); |
|||
|
|||
inst.transform.localPosition = target.transform.TransformPoint(rand_hit.position); |
|||
inst.transform.localRotation = rotation * random; |
|||
inst.name = FormatInstanceName(prefab); |
|||
inst.transform.position = inst.transform.position + inst.transform.up * pivotOffset; |
|||
|
|||
if( avoidOverlappingGameObjects && TestIntersection(inst) ) |
|||
{ |
|||
Object.DestroyImmediate(inst); |
|||
return; |
|||
} |
|||
|
|||
if( hitSurfaceIsParent ) |
|||
inst.transform.SetParent(target.transform); |
|||
|
|||
PrefabUtility.RecordPrefabInstancePropertyModifications(inst); |
|||
|
|||
instances.Add(inst); |
|||
|
|||
Undo.RegisterCreatedObjectUndo(inst, UndoMessage); |
|||
} |
|||
} |
|||
|
|||
private void RemoveGameObjects(z_RaycastHit hit, z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
Vector3 worldHitPosition = target.editableObject.transform.TransformPoint(hit.position); |
|||
|
|||
int count = instances.Count; |
|||
|
|||
for(int i = 0; i < count; i++) |
|||
{ |
|||
if( instances[i] != null && Vector3.Distance(worldHitPosition, instances[i].transform.position) < settings.radius ) |
|||
{ |
|||
GameObject go = instances[i]; |
|||
instances.RemoveAt(i); |
|||
count--; |
|||
Undo.DestroyObjectImmediate(go); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private Ray RandomRay(Vector3 position, Vector3 normal, float radius, float falloff, AnimationCurve curve) |
|||
{ |
|||
Vector3 a = Vector3.zero; |
|||
Quaternion rotation = Quaternion.LookRotation(normal, Vector3.up); |
|||
|
|||
a.x = Mathf.Cos(Random.Range(0f, 360f)); |
|||
a.y = Mathf.Sin(Random.Range(0f, 360f)); |
|||
|
|||
float r = Mathf.Sqrt(Random.Range(0f, 1f)); |
|||
|
|||
while(true) |
|||
{ |
|||
// this isn't great
|
|||
if(r < falloff || Random.Range(0f, 1f) > Mathf.Clamp(curve.Evaluate( 1f - ((r - falloff) / (1f - falloff))), 0f, 1f)) |
|||
{ |
|||
a = position + (rotation * (a.normalized * r * radius)); |
|||
return new Ray(a + normal * 10f, -normal); |
|||
} |
|||
else |
|||
{ |
|||
r = Mathf.Sqrt(Random.Range(0f, 1f)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private z_PrefabAndSettings GetPrefab() |
|||
{ |
|||
List<z_PrefabAndSettings> pool = queued != null && queued.Count > 0 ? queued : prefabPalette.prefabs; |
|||
int count = pool == null ? 0 : pool.Count; |
|||
return count > 0 ? pool[(int) Random.Range(0, count)] : null; |
|||
} |
|||
|
|||
private float GetPivotOffset(GameObject go) |
|||
{ |
|||
MeshFilter mf = go.GetComponent<MeshFilter>(); |
|||
|
|||
// probuilder meshes that are prefabs might not have a mesh
|
|||
// associated with them, so make sure they do before querying
|
|||
// for bounds
|
|||
object pb = go.GetComponent("pb_Object"); |
|||
|
|||
if(pb != null) |
|||
z_ReflectionUtil.Invoke(pb, "Awake"); |
|||
|
|||
if(mf == null || mf.sharedMesh == null) |
|||
return 0f; |
|||
|
|||
Bounds bounds = mf.sharedMesh.bounds; |
|||
|
|||
return (-bounds.center.y + bounds.extents.y) * go.transform.localScale.y; |
|||
} |
|||
|
|||
private struct SphereBounds |
|||
{ |
|||
public Vector3 position; |
|||
public float radius; |
|||
|
|||
public SphereBounds(Vector3 p, float r) |
|||
{ |
|||
position = p; |
|||
radius = r; |
|||
} |
|||
|
|||
public bool Intersects(SphereBounds other) |
|||
{ |
|||
return Vector3.Distance(position, other.position) < (radius + other.radius); |
|||
} |
|||
} |
|||
|
|||
private static bool GetSphereBounds(GameObject go, out SphereBounds bounds) |
|||
{ |
|||
bounds = new SphereBounds(); |
|||
|
|||
if(go == null) |
|||
return false; |
|||
|
|||
Mesh mesh = null; |
|||
|
|||
MeshFilter mf = go.GetComponentInChildren<MeshFilter>(); |
|||
|
|||
if(mf != null && mf.sharedMesh != null) |
|||
{ |
|||
mesh = mf.sharedMesh; |
|||
} |
|||
else |
|||
{ |
|||
SkinnedMeshRenderer smr = go.GetComponentInChildren<SkinnedMeshRenderer>(); |
|||
|
|||
if(smr != null && smr.sharedMesh != null) |
|||
mesh = smr.sharedMesh; |
|||
} |
|||
|
|||
if(mesh != null) |
|||
{ |
|||
Bounds meshBounds = mf.sharedMesh.bounds; |
|||
bounds.position = mf.transform.TransformPoint(meshBounds.center - (Vector3.up * meshBounds.extents.y)); |
|||
bounds.radius = Mathf.Max(meshBounds.extents.x, meshBounds.extents.z); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Tests if go intersects with any painted objects. |
|||
*/ |
|||
private bool TestIntersection(GameObject go) |
|||
{ |
|||
SphereBounds bounds, it_bounds; |
|||
|
|||
if(!GetSphereBounds(go, out bounds)) |
|||
return false; |
|||
|
|||
int c = instances == null ? 0 : instances.Count; |
|||
|
|||
for(int i = 0; i < c; i++) |
|||
{ |
|||
if(GetSphereBounds(instances[i], out it_bounds) && bounds.Intersects(it_bounds)) |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public override void DrawGizmos(z_BrushTarget target, z_BrushSettings settings) |
|||
{ |
|||
base.DrawGizmos(target, settings); |
|||
|
|||
// SphereBounds bounds;
|
|||
|
|||
// foreach(GameObject go in instances)
|
|||
// {
|
|||
// if(!GetSphereBounds(go, out bounds))
|
|||
// continue;
|
|||
|
|||
// Handles.CircleCap(-1, bounds.position, Quaternion.Euler(Vector3.up * 90f), bounds.radius);
|
|||
// Handles.CircleCap(-1, bounds.position, Quaternion.Euler(Vector3.right * 90f), bounds.radius);
|
|||
// Handles.CircleCap(-1, bounds.position, Quaternion.Euler(Vector3.forward * 90f), bounds.radius);
|
|||
// }
|
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7afd235f90a2cb943996cef04118c5fa |
|||
timeCreated: 1447866851 |
|||
licenseType: Store |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||