This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
DRAFT: broadcast a dynamically-generated mesh #396
Open
ForrestTrepte
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
ForrestTrepte:draft/dynamicMesh
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ namespace Microsoft.MixedReality.SpectatorView | |
{ | ||
internal class MeshFilterBroadcaster : MeshRendererBroadcaster<MeshFilterService> | ||
{ | ||
// A unique integer value used to check that mesh data is correctly written and read. | ||
// TODO: After some time, if this is working reliably, this check could be removed. | ||
public const int CheckValue = 123454321; | ||
|
||
public static class MeshFilterChangeType | ||
{ | ||
public const byte Mesh = 0x8; | ||
|
@@ -27,11 +31,42 @@ protected override void WriteRenderer(BinaryWriter message, byte changeType) | |
if (HasFlag(changeType, MeshFilterChangeType.Mesh)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested whether this flag gets set when someone modifies the meshFilter.mesh on update/start? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I have verified that this worked with dynamically-generated meshes in my project, but I didn't take a close look at exactly how the dynamic meshes were created. I haven't tested changing a mesh after it has already been broadcast and I expect that changes after broadcast would not be detected. |
||
{ | ||
message.Write(assetId); | ||
|
||
if (assetId == AssetId.Empty) | ||
{ | ||
// This is a dynamic object that wasn't created from an asset. | ||
bool hasDynamicMesh = meshFilter.sharedMesh != null; | ||
message.Write(hasDynamicMesh); | ||
if (hasDynamicMesh) | ||
{ | ||
WriteDynamicMesh(message, meshFilter.sharedMesh); | ||
} | ||
} | ||
} | ||
|
||
base.WriteRenderer(message, changeType); | ||
} | ||
|
||
private void WriteDynamicMesh(BinaryWriter message, Mesh mesh) | ||
{ | ||
message.Write(CheckValue); | ||
message.Write(mesh.subMeshCount); | ||
message.Write(mesh.vertices); | ||
message.Write(mesh.uv); | ||
message.Write(mesh.uv2); | ||
message.Write(mesh.uv3); | ||
message.Write(mesh.uv4); | ||
message.Write(mesh.uv5); | ||
message.Write(mesh.uv6); | ||
message.Write(mesh.uv7); | ||
message.Write(mesh.uv8); | ||
message.Write(mesh.colors); | ||
message.Write(mesh.triangles); | ||
message.Write(CheckValue); | ||
|
||
Debug.Log($"MeshFilterBroadcaster.WriteDynamicMesh: {gameObject.name} written with {mesh.subMeshCount} subMeshCount, {mesh.vertices?.Length} vertices, {mesh.triangles?.Length} triangles"); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may need to be filter.mesh. It looks like filter.sharedMesh isn't suggested for writing meshes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find Unity's MeshFilter.mesh/sharedMesh confusing, so I'm not sure. I think the warning about writing is if you modify a mesh using filter.sharedMesh. For example, if you do filter.sharedMesh.vertices = new Vector3[] then you could be inadvertently modifying a mesh that is shared by other objects. In this case, we are not modifying the existing sharedMesh but instead are first creating a Mesh and then assigning that mesh to filter.sharedMesh.
Not sure if I'm making much sense here, but I'm not sure what the right way is to do this or if it even matters which property is used in this case. I expect that assigning to filter.mesh would also be fine.