Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[For 0.18.x] fix: Spline fixes #901

Open
wants to merge 2 commits into
base: release_0.18
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plugin~/Src/mscore/msServerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ msAPI void msServerSendCurve(ms::Server* server, const char* path, int splineInd

auto curve = server->getOrCreatePendingEntity<ms::Curve>(path);

if (curve->splines.size() <= splineIndex) {
while (curve->splines.size() <= splineIndex) {
curve->splines.push_back(ms::CurveSpline::create());
}

Expand Down
Binary file modified Runtime/Plugins/x86_64/mscore.dll
Binary file not shown.
101 changes: 63 additions & 38 deletions Runtime/Scripts/BaseMeshSync.Modifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,66 +417,90 @@ private void UpdateProperties(SceneData scene) {

private EntityRecord UpdateCurveEntity(CurvesData data, MeshSyncPlayerConfig config) {
#if AT_USE_SPLINES
lock (splineLock)
{
TransformData dtrans = data.transform;
EntityRecord rec = UpdateTransformEntity(dtrans, config);
lock (splineLock) {
TransformData dtrans = data.transform;
EntityRecord rec = UpdateTransformEntity(dtrans, config);

GameObject go = rec.go;
Transform trans = go.transform;

GameObject go = rec.go;
Transform trans = go.transform;
SplineContainer splineContainer = rec.splineContainer;

SplineContainer splineContainer = rec.splineContainer;

if (splineContainer == null)
{
splineContainer = rec.splineContainer = Misc.GetOrAddComponent<SplineContainer>(trans.gameObject);
}
if (splineContainer == null) {
splineContainer = rec.splineContainer = Misc.GetOrAddComponent<SplineContainer>(trans.gameObject);
}

float3[] cos = null;
float3[] handles_left = null;
float3[] handles_right = null;
float3[] cos = null;
float3[] handles_left = null;
float3[] handles_right = null;

var numSplines = data.numSplines;
var numSplines = data.numSplines;

Spline.Changed -= SplineChanged;
Spline.Changed -= SplineChanged;

var newSplines = new List<Spline>();
// Try to reuse the same splines if the number of splines and knots has not changed:
bool useNewSplines = splineContainer.Splines.Count != numSplines;
if (!useNewSplines) {
for (int index = 0; index < numSplines; index++) {
if (splineContainer.Splines[index].Count != data.GetNumSplinePoints(index)) {
useNewSplines = true;
break;
}
}
}

var newSplines = new List<Spline>();

for (int index = 0; index < numSplines; index++)
{
var spline = new Spline();
for (int index = 0; index < numSplines; index++) {
Spline spline;
if (useNewSplines) {
spline = new Spline();
newSplines.Add(spline);
}
else {
spline = splineContainer.Splines[index];
}

spline.Closed = data.IsSplineClosed(index);
// Need to be in this mode to be consistent with blender:
spline.SetTangentMode(TangentMode.Broken);

var numPoints = data.GetNumSplinePoints(index);
m_tmpFloat3.Resize(numPoints);
spline.Closed = data.IsSplineClosed(index);

data.ReadSplineCos(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref cos);
var numPoints = data.GetNumSplinePoints(index);
m_tmpFloat3.Resize(numPoints);

data.ReadSplineHandlesLeft(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref handles_left);
data.ReadSplineCos(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref cos);

data.ReadSplineHandlesRight(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref handles_right);
data.ReadSplineHandlesLeft(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref handles_left);

for (int pointIndex = 0; pointIndex < cos.Length; pointIndex++)
{
var co = cos[pointIndex];
data.ReadSplineHandlesRight(index, m_tmpFloat3);
m_tmpFloat3.CopyTo(ref handles_right);

var knot = new BezierKnot(co, handles_left[pointIndex] - co, handles_right[pointIndex] - co, Quaternion.identity);
for (int pointIndex = 0; pointIndex < cos.Length; pointIndex++) {
var co = cos[pointIndex];

var knot = new BezierKnot(co, handles_left[pointIndex] - co, handles_right[pointIndex] - co,
Quaternion.identity);

if (useNewSplines) {
spline.Add(knot);
}
else {
spline.SetKnot(pointIndex, knot);
}
}
}

if (useNewSplines) {
splineContainer.Splines = newSplines;

Spline.Changed += SplineChanged;

return rec;
}

Spline.Changed += SplineChanged;

return rec;
}
#else
// If the curve was exported as a mesh before, delete this now, as it's handled as a curve:
TransformData dtrans = data.transform;
Expand All @@ -491,6 +515,7 @@ private EntityRecord UpdateCurveEntity(CurvesData data, MeshSyncPlayerConfig con
#if AT_USE_SPLINES
protected virtual void SplineChanged(Spline spline, int arg2, SplineModification arg3)
{
// Overriden in Server.
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/msNetworkAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public string screenshotPath {


#if AT_USE_SPLINES
public void SendCurve(string path, int splineIndex, int knotCount, bool closed, float3[] cos, float3[] handlesLeft, float3[] handlesRight)
public void SendCurve(string path, int splineIndex, int knotCount, bool closed, float3[] cos, float3[] handlesLeft, float3[] handlesRight)
{
msServerSendCurve(self, path, splineIndex, knotCount, closed, cos, handlesLeft, handlesRight);
}
Expand Down