0
私は、UnityのC#のEpForceDirectedGraph.csグラフに基づいて強制的なグラフの実装を書いていますが、最大4000個のノードしか必要としない1000ノードまでしか処理できません。私は数日間のコードを見てきましたが、それを高速化するためにとにかく見ることができません!見て、助けていただければ幸いです!私はこれらの機能を400回のノードで85回実行して、適切なグラフを生成します。これは、適用力関数が開始時に27,000,000回実行されていることを意味します。力の有向グラフの最適化
私はビルドターゲットとしてWebGLを使用していますので、マルチスレッドとSIMDが役に立たない可能性がありますが、私はこれらのツールを使用しています。
これらは、メインアプリケーションの機能です:最後に
* @Description applied coulombs law to determine the push force between 2 points as well as*
* the attraction to center and updating of the velocity and acceleration *
* *
* @parameters iTimeStep - the time since last frame *
************************************************************************************************/
protected override void applyNodeLaws(float iTimeStep)
{
for (int i = 0; i < graph.nodes.Count; i++)
{
//applies coulomb's law to each node
Point3D point1 = GetPoint(graph.nodes[i]);
for (int j = 0; j < graph.nodes.Count; j++)
{
Point3D point2 = GetPoint(graph.nodes[j]);
if (point1 != point2)
{
Vector3 d = point1.position - point2.position;
float distance = d.magnitude + 0.1f;
Vector3 direction = d.normalized;
point1.ApplyForce((direction * Repulsion)/(distance * 0.5f));
point2.ApplyForce((direction * Repulsion)/(distance * -0.5f));
}
}
//Applies centre attraction
Vector3 centreDirection = point1.position * -1.0f;
float displacement = centreDirection.magnitude;
centreDirection = centreDirection.normalized;
point1.ApplyForce(centreDirection * (Stiffness * displacement * 0.4f));
//converts acceleration to velocity
point1.velocity += (point1.acceleration * iTimeStep);
point1.velocity *= Damping;
point1.acceleration = Vector3.zero;
//applies velocity to position
point1.position += (point1.velocity * iTimeStep);
}
}
/************************************************************************************************
* @Description applied hookes law to determine the spring force between 2 points *
************************************************************************************************/
protected override void applyHookesLaw()
{
for (int i = 0; i < graph.edges.Count; i++)
{
Spring3D spring = GetSpring(graph.edges[i]);
Vector3 d = spring.point2.position - spring.point1.position;
float displacement = spring.Length - d.magnitude;
Vector3 direction = d.normalized;
spring.point1.ApplyForce(direction * (spring.K * displacement * -0.5f));
spring.point2.ApplyForce(direction * (spring.K * displacement * 0.5f));
}
}
GPGPUを調べる必要があります。https://mickyd.wordpress.com/2014/02/01/n-body-galaxy-simulation-using-compute-shaders-on-gpgpu-via-unity-3d/ – MickyD
こんにちはクイック返信をいただきありがとうございます。あなたのウェブサイトのプロジェクトへのリンクがダウンしています。 –
悲しいことに、それはUnityの古いバージョンのためであり、厄介なことにUnityは新しいバージョンで大きな変更を加える習慣があります。とにかく、私のブログには重要なコードがあります。私はあなたがそれを理解できることを願っています – MickyD