去掉obi,使用自写绳索

This commit is contained in:
2026-02-23 20:51:03 +08:00
parent cb636f862d
commit 91e2309eeb
2011 changed files with 2593 additions and 190578 deletions

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 4fc4d44dc6d334c2985875fc6f7b8cb1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +0,0 @@
namespace Obi
{
public interface IObiBrushMode
{
string name{get;}
bool needsInputValue{ get; }
void ApplyStamps(ObiBrushBase brush, bool modified);
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4c46364da0f1641c7ab84e12348a6a4b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,38 +0,0 @@
using UnityEngine;
namespace Obi
{
public class ObiColorPaintBrushMode : IObiBrushMode
{
ObiBlueprintColorProperty property;
public ObiColorPaintBrushMode(ObiBlueprintColorProperty property)
{
this.property = property;
}
public string name
{
get { return "Paint"; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
Color currentValue = property.Get(i);
Color delta = brush.weights[i] * brush.opacity * brush.speed * (property.GetDefault() - currentValue);
property.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1fd033c8f79b1494d8b8de5c8311f8c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,53 +0,0 @@
using UnityEngine;
namespace Obi
{
public class ObiColorSmoothBrushMode : IObiBrushMode
{
ObiBlueprintColorProperty property;
public ObiColorSmoothBrushMode(ObiBlueprintColorProperty property)
{
this.property = property;
}
public string name
{
get { return "Smooth"; }
}
public bool needsInputValue
{
get { return false; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
Color averageValue = Color.black;
float totalWeight = 0;
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
averageValue += property.Get(i) * brush.weights[i];
totalWeight += brush.weights[i];
}
}
averageValue /= totalWeight;
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
Color currentValue = property.Get(i);
Color delta = brush.opacity * brush.speed * (Color.Lerp(currentValue, averageValue, brush.weights[i]) - currentValue);
property.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a69a8a1614478445cbb770a5e123ab18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,36 +0,0 @@
namespace Obi
{
public class ObiFloatAddBrushMode : IObiBrushMode
{
ObiBlueprintFloatProperty property;
public ObiFloatAddBrushMode(ObiBlueprintFloatProperty property)
{
this.property = property;
}
public string name
{
get { return "Add"; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
float currentValue = property.Get(i);
float delta = brush.weights[i] * brush.opacity * brush.speed * property.GetDefault();
property.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8b39e10cedc94461083b3b19c3ddb343
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,42 +0,0 @@
namespace Obi
{
public class ObiFloatCopyBrushMode : IObiBrushMode
{
ObiBlueprintFloatProperty property;
public ObiBlueprintFloatProperty source;
public ObiFloatCopyBrushMode(ObiBlueprintFloatProperty property, ObiBlueprintFloatProperty source)
{
this.property = property;
this.source = source;
}
public string name
{
get { return "Copy"; }
}
public bool needsInputValue
{
get { return false; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
if (property != null && source != null)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
float currentValue = property.Get(i);
float sourceValue = source.Get(i);
float delta = brush.weights[i] * brush.opacity * brush.speed * (sourceValue - currentValue);
property.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 95bb470841f42415ab256cd64adb9242
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,37 +0,0 @@
namespace Obi
{
public class ObiFloatPaintBrushMode : IObiBrushMode
{
ObiBlueprintFloatProperty property;
public ObiFloatPaintBrushMode(ObiBlueprintFloatProperty property)
{
this.property = property;
}
public string name
{
get { return "Paint"; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
float currentValue = property.Get(i);
float delta = brush.weights[i] * brush.opacity * brush.speed * (property.GetDefault() - currentValue);
property.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: eb3d176006d404a508bef284d2701ab0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,55 +0,0 @@
using UnityEngine;
namespace Obi
{
public class ObiFloatSmoothBrushMode : IObiBrushMode
{
ObiBlueprintFloatProperty property;
public ObiFloatSmoothBrushMode(ObiBlueprintFloatProperty property)
{
this.property = property;
}
public string name
{
get { return "Smooth"; }
}
public bool needsInputValue
{
get { return false; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
var floatProperty = (ObiBlueprintFloatProperty)property;
float averageValue = 0;
float totalWeight = 0;
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
averageValue += floatProperty.Get(i) * brush.weights[i];
totalWeight += brush.weights[i];
}
}
averageValue /= totalWeight;
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > 0)
{
float currentValue = floatProperty.Get(i);
float delta = brush.opacity * brush.speed * (Mathf.Lerp(currentValue,averageValue,brush.weights[i]) - currentValue);
floatProperty.Set(i, currentValue + delta * (modified ? -1 : 1));
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 63dad56a994af4db7bb3449382022c54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,33 +0,0 @@
namespace Obi
{
public class ObiIntPaintBrushMode : IObiBrushMode
{
ObiBlueprintIntProperty property;
public ObiIntPaintBrushMode(ObiBlueprintIntProperty property)
{
this.property = property;
}
public string name
{
get { return "Paint"; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > (1 - brush.opacity))
{
property.Set(i, property.GetDefault());
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d8882849c81104cef80b3dfdab2021c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,39 +0,0 @@
namespace Obi
{
public class ObiMasterSlavePaintBrushMode : IObiBrushMode
{
ObiBlueprintIntProperty property;
public ObiMasterSlavePaintBrushMode(ObiBlueprintIntProperty property)
{
this.property = property;
}
public string name
{
get { return "Master/Slave paint"; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (!property.Masked(i) && brush.weights[i] > (1 - brush.opacity))
{
int currentValue = property.Get(i);
if (modified)
currentValue &= ~(int)(1 << property.GetDefault());
else currentValue |= (int)(1 << property.GetDefault());
property.Set(i, currentValue);
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 62f8e9adfc17440359a9b51005cd0948
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,33 +0,0 @@
namespace Obi
{
public class ObiSelectBrushMode : IObiBrushMode
{
ObiBlueprintSelected property;
string customName;
public ObiSelectBrushMode(ObiBlueprintSelected property, string customName = "Select")
{
this.property = property;
this.customName = customName;
}
public string name
{
get { return customName; }
}
public bool needsInputValue
{
get { return true; }
}
public void ApplyStamps(ObiBrushBase brush, bool modified)
{
for (int i = 0; i < brush.weights.Length; ++i)
{
if (brush.weights[i] > 0 && !property.Masked(i))
property.Set(i,!modified);
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9cea7ef42253f4d2b9b5a222521cdee8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,161 +0,0 @@
using UnityEngine;
using UnityEditor;
using System;
namespace Obi
{
public abstract class ObiBrushBase
{
static int particleBrushHash = "ObiBrushHash".GetHashCode();
public IObiBrushMode brushMode;
public float radius = 1;
public float innerRadius = 0.5f;
public float opacity = 1;
public float[] weights = new float[0];
public bool drag = true;
public float speed = 0.1f;
protected int controlID;
protected Action onStrokeStart;
protected Action onStrokeUpdate;
protected Action onStrokeEnd;
public float SqrRadius
{
get{ return radius * radius; }
}
public ObiBrushBase(Action onStrokeStart, Action onStrokeUpdate, Action onStrokeEnd)
{
this.onStrokeStart = onStrokeStart;
this.onStrokeUpdate = onStrokeUpdate;
this.onStrokeEnd = onStrokeEnd;
}
protected virtual float WeightFromDistance(float distance)
{
// anything outside the brush should have zero weight:
if (distance > radius)
return 0;
float t = Mathf.InverseLerp(innerRadius * radius, radius, distance);
return Mathf.SmoothStep(1, 0, t);
}
protected abstract void GenerateWeights(Vector3[] positions);
protected virtual void OnMouseDown(Vector3[] positions)
{
if (Event.current.button != 0 || (Event.current.modifiers & ~EventModifiers.Shift) != EventModifiers.None)
return;
GUIUtility.hotControl = controlID;
GenerateWeights(positions);
if (onStrokeStart != null)
onStrokeStart();
if (brushMode != null)
brushMode.ApplyStamps(this, (Event.current.modifiers & EventModifiers.Shift) != 0);
if (onStrokeUpdate != null)
onStrokeUpdate();
Event.current.Use();
}
protected virtual void OnMouseMove(Vector3[] positions)
{
}
protected virtual void OnMouseDrag(Vector3[] positions)
{
if (GUIUtility.hotControl == controlID && drag)
{
GenerateWeights(positions);
if (brushMode != null)
brushMode.ApplyStamps(this, (Event.current.modifiers & EventModifiers.Shift) != 0);
if (onStrokeUpdate != null)
onStrokeUpdate();
Event.current.Use();
}
}
protected virtual void OnMouseUp(Vector3[] positions)
{
if (GUIUtility.hotControl == controlID)
{
GUIUtility.hotControl = 0;
Event.current.Use();
if (onStrokeEnd != null)
onStrokeEnd();
}
}
protected virtual void OnRepaint()
{
}
public void DoBrush(Vector3[] positions)
{
Matrix4x4 cachedMatrix = Handles.matrix;
controlID = GUIUtility.GetControlID(particleBrushHash, FocusType.Passive);
Array.Resize(ref weights, positions.Length);
switch (Event.current.GetTypeForControl(controlID))
{
case EventType.MouseDown:
OnMouseDown(positions);
break;
case EventType.MouseMove:
OnMouseMove(positions);
SceneView.RepaintAll();
break;
case EventType.MouseDrag:
OnMouseDrag(positions);
break;
case EventType.MouseUp:
OnMouseUp(positions);
break;
case EventType.Repaint:
Handles.matrix = Matrix4x4.identity;
OnRepaint();
Handles.matrix = cachedMatrix;
break;
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 094253962d646436792561e708e62376
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,51 +0,0 @@
using System;
using UnityEngine;
[Serializable]
public struct ObiBrushMirrorSettings
{
[Flags]
public enum MirrorAxis
{
None = 0x0,
X = 0x1,
Y = 0x2,
Z = 0x4
}
public enum MirrorSpace
{
World = 0,
Camera = 1
}
public MirrorAxis axis;
public MirrorSpace space;
public Vector3 ToAxis()
{
uint m = (uint)axis;
bool xMirror = (m & (uint)MirrorAxis.X) > 0;
bool yMirror = (m & (uint)MirrorAxis.Y) > 0;
bool zMirror = (m & (uint)MirrorAxis.Z) > 0;
if (axis < 0 || ((int)axis > (int)MirrorAxis.X + (int)MirrorAxis.Y + (int)MirrorAxis.Z))
{
return Vector3.one;
}
Vector3 reflection = Vector3.one;
if (xMirror)
reflection.x = -1f;
if (yMirror)
reflection.y = -1f;
if (zMirror)
reflection.z = -1f;
return reflection;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d10a9257ac23248418439eb80e02a611
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,125 +0,0 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Obi
{
public class ObiRaycastBrush : ObiBrushBase
{
public Matrix4x4 raycastTransform = Matrix4x4.identity;
public Mesh raycastTarget = null;
public bool drawVolume = false;
private List<Ray> rays = new List<Ray>();
private List<ObiRaycastHit> hits = new List<ObiRaycastHit>();
public ObiBrushMirrorSettings mirror;
public ObiRaycastBrush(Mesh raycastTarget, Action onStrokeStart, Action onStrokeUpdate, Action onStrokeEnd) : base(onStrokeStart, onStrokeUpdate, onStrokeEnd)
{
radius = 0.1f;
this.raycastTarget = raycastTarget;
rays = new List<Ray>();
}
protected override void GenerateWeights(Vector3[] positions)
{
if (raycastTarget != null)
{
rays.Clear();
hits.Clear();
for (int i = 0; i < positions.Length; i++)
weights[i] = 0;
var vertices = raycastTarget.vertices;
var triangles = raycastTarget.triangles;
Ray mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
rays.Add(mouseRay);
ObiBrushMirrorSettings currentAxis = mirror;
if (mirror.axis != ObiBrushMirrorSettings.MirrorAxis.None)
{
for (int i = 0; i < 3; i++)
{
currentAxis.axis = (ObiBrushMirrorSettings.MirrorAxis)(1u << i);
if (((uint)mirror.axis & (1u << i)) < 1)
continue;
Vector3 mirrorVector = currentAxis.ToAxis();
if (currentAxis.space == ObiBrushMirrorSettings.MirrorSpace.World)
{
Vector3 center = raycastTarget.bounds.center;
rays.Add(new Ray(Vector3.Scale(mouseRay.origin - center, mirrorVector) + center,
Vector3.Scale(mouseRay.direction, mirrorVector)));
}
else
{
Transform t = SceneView.lastActiveSceneView.camera.transform;
Vector3 o = t.InverseTransformPoint(mouseRay.origin);
Vector3 d = t.InverseTransformDirection(mouseRay.direction);
rays.Add(new Ray(t.TransformPoint(Vector3.Scale(o, mirrorVector)),
t.TransformDirection(Vector3.Scale(d, mirrorVector))));
}
}
}
foreach (var ray in rays)
{
if (ObiMeshUtils.WorldRaycast(ray, raycastTransform, vertices, triangles, out ObiRaycastHit hit))
{
hit.position = raycastTransform.MultiplyPoint3x4(hit.position);
hit.normal = raycastTransform.MultiplyVector(hit.normal);
hits.Add(hit);
for (int i = 0; i < positions.Length; i++)
{
// get distance from hit position to particle position:
float weight = WeightFromDistance(Vector3.Distance(hit.position, positions[i]));
weights[i] = Mathf.Max(weights[i], weight);
}
}
}
}
}
protected override void OnMouseMove(Vector3[] positions)
{
base.OnMouseMove(positions);
GenerateWeights(positions);
}
protected override void OnRepaint()
{
base.OnRepaint();
if (raycastTarget != null)
{
Color brushColor = ObiEditorSettings.GetOrCreateSettings().brushColor;
foreach (var hit in hits)
{
if (hit != null && hit.triangle >= 0)
{
Handles.color = brushColor;
Handles.DrawLine(hit.position, hit.position + hit.normal.normalized * radius);
Handles.DrawWireDisc(hit.position, hit.normal, radius);
Handles.DrawWireDisc(hit.position, hit.normal, innerRadius * radius);
if (drawVolume)
{
Handles.color = new Color(brushColor.r, brushColor.g, brushColor.b, 0.2f);
Handles.SphereHandleCap(0, hit.position, Quaternion.identity, radius * 2, EventType.Repaint);
}
}
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d925323750dca4dcaa5cca91b18521b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Obi
{
public class ObiScreenSpaceBrush : ObiBrushBase
{
public ObiScreenSpaceBrush(Action onStrokeStart, Action onStrokeUpdate, Action onStrokeEnd) : base(onStrokeStart, onStrokeUpdate, onStrokeEnd)
{
radius = 32;
}
protected override float WeightFromDistance(float distance)
{
// anything outside the brush should have zero weight:
if (distance * EditorGUIUtility.pixelsPerPoint > radius)
return 0;
return 1;
}
protected override void GenerateWeights(Vector3[] positions)
{
for (int i = 0; i < positions.Length; i++)
{
// get particle position in gui space:
Vector2 pos = HandleUtility.WorldToGUIPoint(positions[i]);
// get distance from mouse position to particle position:
weights[i] = WeightFromDistance(Vector3.Distance(Event.current.mousePosition, pos));
}
}
protected override void OnRepaint()
{
base.OnRepaint();
Camera cam = Camera.current;
float depth = (cam.nearClipPlane + cam.farClipPlane) * 0.5f;
float ppp = EditorGUIUtility.pixelsPerPoint;
Vector2 mousePos = new Vector2(Event.current.mousePosition.x * ppp,
cam.pixelHeight - Event.current.mousePosition.y * ppp);
Handles.color = ObiEditorSettings.GetOrCreateSettings().brushColor;
Vector3 point = new Vector3(mousePos.x, mousePos.y, depth);
Vector3 wsPoint = cam.ScreenToWorldPoint(point);
var p1 = cam.ScreenToWorldPoint(new Vector3(1, 0, depth));
var p2 = cam.ScreenToWorldPoint(new Vector3(0, 0, depth));
float units = Vector3.Distance(p1, p2);
Handles.DrawWireDisc(wsPoint, cam.transform.forward, radius * units);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 38fc5288fb3c94ebeb7eaa88a3bc5119
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: