升级obi

This commit is contained in:
2026-01-22 22:08:21 +08:00
parent 120b8cda26
commit 20f14322bc
1067 changed files with 149894 additions and 29583 deletions

View File

@@ -1,50 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
[ExecuteInEditMode]
public class SpiralCurve : MonoBehaviour {
public float radius = 0.25f;
public float radialStep = 0.8f;
public float heightStep = 0.04f;
public float points = 30;
public float rotationalMass = 1;
public float thickness = 1;
void Awake ()
namespace Obi.Samples
{
[ExecuteInEditMode]
public class SpiralCurve : MonoBehaviour
{
Generate();
}
public void Generate()
{
var rod = GetComponent<ObiRopeBase>();
if (rod == null) return;
public float radius = 0.25f;
public float radialStep = 0.8f;
public float heightStep = 0.04f;
public float points = 30;
var blueprint = rod.sourceBlueprint as ObiRopeBlueprintBase;
if (blueprint == null) return;
public float rotationalMass = 1;
public float thickness = 1;
blueprint.path.Clear();
float ang = 0;
float height = 0;
for (int i = 0; i < points; ++i)
void Awake()
{
Vector3 point = new Vector3(Mathf.Cos(ang) * radius, height, Mathf.Sin(ang) * radius);
// optimal handle length for circle approximation: 4/3 tan(pi/(2n))
Vector3 tangent = new Vector3(-point.z, heightStep, point.x).normalized * (4.0f / 3.0f) * Mathf.Tan(radialStep / 4.0f) * radius;
blueprint.path.AddControlPoint(point, -tangent, tangent, Vector3.up, 1, rotationalMass, thickness, 1, Color.white, "control point " + i);
ang += radialStep;
height += heightStep;
Generate();
}
blueprint.path.FlushEvents();
}
public void Generate()
{
var rod = GetComponent<ObiRopeBase>();
if (rod == null) return;
var blueprint = rod.sourceBlueprint as ObiRopeBlueprintBase;
if (blueprint == null) return;
blueprint.path.Clear();
float ang = 0;
float height = 0;
for (int i = 0; i < points; ++i)
{
Vector3 point = new Vector3(Mathf.Cos(ang) * radius, height, Mathf.Sin(ang) * radius);
// optimal handle length for circle approximation: 4/3 tan(pi/(2n))
Vector3 tangent = new Vector3(-point.z, heightStep, point.x).normalized * (4.0f / 3.0f) * Mathf.Tan(radialStep / 4.0f) * radius;
blueprint.path.AddControlPoint(point, -tangent, tangent, Vector3.up, 1, rotationalMass, thickness, 1, Color.white, "control point " + i);
ang += radialStep;
height += heightStep;
}
blueprint.path.FlushEvents();
}
}
}