重新导入obi
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiAmbientForceZone : ObiExternalForce
|
||||
{
|
||||
|
||||
public override void ApplyForcesToActor(ObiActor actor)
|
||||
{
|
||||
|
||||
Matrix4x4 l2sTransform = actor.solver.transform.worldToLocalMatrix * transform.localToWorldMatrix;
|
||||
|
||||
Vector4 force = l2sTransform.MultiplyVector(Vector3.forward * (intensity + GetTurbulence(turbulence)));
|
||||
|
||||
if (actor.usesCustomExternalForces)
|
||||
{
|
||||
for (int i = 0; i < actor.activeParticleCount; ++i)
|
||||
actor.solver.wind[actor.solverIndices[i]] += force;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < actor.activeParticleCount; ++i)
|
||||
actor.solver.externalForces[actor.solverIndices[i]] += force;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.color = new Color(0,0.7f,1,1);
|
||||
|
||||
// arrow body:
|
||||
ObiUtils.DrawArrowGizmo(0.5f + GetTurbulence(1),0.2f,0.3f,0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f33b658b41e945e0bae1d3f0af0830e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 092f06332c018434b8c8ea86164ef4fd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Obi/Scripts/Common/Utils/Forces/ObiExternalForce.cs
Normal file
50
Assets/Obi/Scripts/Common/Utils/Forces/ObiExternalForce.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public abstract class ObiExternalForce : MonoBehaviour
|
||||
{
|
||||
|
||||
public float intensity = 0;
|
||||
public float turbulence = 0;
|
||||
public float turbulenceFrequency = 1;
|
||||
public float turbulenceSeed = 0;
|
||||
public ObiSolver[] affectedSolvers;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
foreach (ObiSolver solver in affectedSolvers)
|
||||
{
|
||||
if (solver != null)
|
||||
solver.OnBeginStep += Solver_OnStepBegin;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
foreach (ObiSolver solver in affectedSolvers)
|
||||
{
|
||||
if (solver != null)
|
||||
solver.OnBeginStep -= Solver_OnStepBegin;
|
||||
}
|
||||
}
|
||||
|
||||
void Solver_OnStepBegin(ObiSolver solver, float stepTime)
|
||||
{
|
||||
foreach (ObiActor actor in solver.actors)
|
||||
{
|
||||
if (actor != null)
|
||||
ApplyForcesToActor(actor);
|
||||
}
|
||||
}
|
||||
|
||||
protected float GetTurbulence(float turbulenceIntensity){
|
||||
return Mathf.PerlinNoise(Time.fixedTime * turbulenceFrequency,turbulenceSeed) * turbulenceIntensity;
|
||||
}
|
||||
|
||||
public abstract void ApplyForcesToActor(ObiActor actor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4978a525b6164476d96f5d28d8b309f8
|
||||
timeCreated: 1480349422
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ObiSphericalForceZone : ObiExternalForce
|
||||
{
|
||||
|
||||
public float radius = 5;
|
||||
public bool radial = true;
|
||||
|
||||
public override void ApplyForcesToActor(ObiActor actor)
|
||||
{
|
||||
|
||||
float sqrRadius = radius * radius;
|
||||
float finalIntensity = intensity + GetTurbulence(turbulence);
|
||||
|
||||
Matrix4x4 l2sTransform = actor.solver.transform.worldToLocalMatrix * transform.localToWorldMatrix;
|
||||
|
||||
Vector4 center = l2sTransform.MultiplyPoint3x4(Vector4.zero);
|
||||
Vector4 forward = l2sTransform.MultiplyVector(Vector3.forward);
|
||||
|
||||
// Calculate force intensity for each actor particle:
|
||||
for (int i = 0; i < actor.activeParticleCount; ++i){
|
||||
|
||||
Vector4 distanceVector = actor.solver.positions[actor.solverIndices[i]] - center;
|
||||
|
||||
float sqrMag = distanceVector.sqrMagnitude;
|
||||
float falloff = Mathf.Clamp01((sqrRadius - sqrMag) / sqrRadius);
|
||||
|
||||
Vector4 force;
|
||||
if (radial)
|
||||
force = distanceVector/(Mathf.Sqrt(sqrMag) + float.Epsilon) * falloff * finalIntensity;
|
||||
else
|
||||
force = forward * falloff * finalIntensity;
|
||||
|
||||
if (actor.usesCustomExternalForces)
|
||||
actor.solver.wind[actor.solverIndices[i]] += force;
|
||||
else
|
||||
actor.solver.externalForces[actor.solverIndices[i]] += force;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.color = new Color(0,0.7f,1,1);
|
||||
Gizmos.DrawWireSphere(Vector3.zero,radius);
|
||||
|
||||
float turb = GetTurbulence(1);
|
||||
|
||||
if (!radial){
|
||||
ObiUtils.DrawArrowGizmo(radius + turb,radius*0.2f,radius*0.3f,radius*0.2f);
|
||||
}else{
|
||||
Gizmos.DrawLine(new Vector3(0,0,-radius*0.5f)*turb,new Vector3(0,0,radius*0.5f)*turb);
|
||||
Gizmos.DrawLine(new Vector3(0,-radius*0.5f,0)*turb,new Vector3(0,radius*0.5f,0)*turb);
|
||||
Gizmos.DrawLine(new Vector3(-radius*0.5f,0,0)*turb,new Vector3(radius*0.5f,0,0)*turb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f05961933f21f46a683fc5d5beec4061
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: d7b67d3b64785476bb7520aa3190fee3, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user