Skip to content

feat: add IsLiveEditing API #904

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

Closed
wants to merge 8 commits into from
Closed
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
38 changes: 37 additions & 1 deletion Runtime/Scripts/BaseMeshSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,19 @@ static Transform FindOrCreateByPath(Transform parent, string path, Action<string
string[] names = path.Split('/');
if (names.Length <= 0)
return null;


static Transform FindFirstRoot(string objectName) {
GameObject[] roots = SceneManager.GetActiveScene().GetRootGameObjects();
foreach (GameObject go in roots) {
if (go.name != objectName)
continue;

return go.transform;
}

return null;
}

//if parent is null, search from root
Transform t = parent;
int tokenStartIdx = 0;
Expand Down Expand Up @@ -1830,6 +1842,30 @@ void AddClientObject(string path, out EntityRecord rec) {
};
m_clientObjects.Add(path, rec);
}

if (m_clientObjects.TryGetValue(path, out rec))
if (rec.go == null) {
m_clientObjects.Remove(path);
rec = null;
}

if (rec == null) {
var trans = FindOrCreateByPath(m_rootObject, path,
delegate(string parentPath) {
EntityRecord parentRec = null;
AddClientObject(parentPath, out parentRec);
if (parentRec.dataType == EntityType.Unknown)
parentRec.dataType = EntityType.Transform;
},
false);

rec = new EntityRecord {
go = trans.gameObject,
trans = trans,
recved = true
};
m_clientObjects.Add(path, rec);
}
}

private EntityRecord UpdateTransformEntity(TransformData data, MeshSyncPlayerConfig config) {
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/IDCCLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal interface IDCCLauncher : IDisposable {
void CloseDCCTool();

void DrawDCCMenu(BaseMeshSync player);

bool HasProcess { get; }
}
}
2 changes: 1 addition & 1 deletion Runtime/Scripts/MeshSyncServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public UnityEngine.Object DCCAsset {
get { return m_DCCAsset; }
internal set { m_DCCAsset = value; }
}

/// <summary>
/// True if this is currently being live-edited.
/// </summary>
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