0 支持
(180 ポイント)
GameObjectにアタッチされているMesh情報を同期させたいのですがやり方がわかりませんご教授お願いいたします。

Meshはローカルでマイフレーム更新されています。

回答 1

+1 支持
(3.8k ポイント)

Mesh情報について「頂点, 法線, UV, 平面のそれぞれの個数が変わらない」という前提条件付きですが、以下のような形でできるような気がします。(スクリプトを組んだ後、MonobitView の Observed Component Registration List への登録が必要です)

ただし、やったことはないです。
おそらく通信データ量として相当な情報量を送信することになるので、ネットワークがパンクする可能性も視野に入れないといけない気がします。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MonobitEngine;

public class Foo : MonobitEngine.MonoBehaviour
{
    // OnMonobitSerializeView で同期
    public void OnMonobitSerializeView(MonobitStream stream, MonobitMessageInfo info)
    {
        // メッシュの情報は下記から取得できる
        Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;

        if (stream.isWriting)
        {
            // 同期データの送信
            foreach (Vector3 pos in mesh.vertices)
            {
                stream.Enqueue(pos); // 頂点
            }
            foreach (Vector3 normal in mesh.normals)
            {
                stream.Enqueue(normal); // 法線
            }
            foreach (Vector2 uv in mesh.uv)
            {
                stream.Enqueue(uv); // UV(マルチテクスチャなら mesh.uv2 以降も個別に必要)
            }
            foreach (int triangle in mesh.triangles)
            {
                stream.Enqueue(triangle); // 三角形ID
            }
        }
        else
        {
            // 同期データの受信
            for (int i = 0; i < mesh.vertices.Length; ++i)
            {
                mesh.vertices[i] = (Vector3)stream.Dequeue(); // 頂点
            }
            for (int i = 0; i < mesh.normals.Length; ++i)
            {
                mesh.normals[i] = (Vector3)stream.Dequeue(); // 法線
            }
            for (int i = 0; i < mesh.uv.Length; ++i)
            {
                mesh.uv[i] = (Vector2)stream.Dequeue(); // UV
            }
            for (int i = 0; i < mesh.triangles.Length; ++i)
            {
                mesh.triangles[i] = (int)stream.Dequeue(); // 三角形ID
            }
        }
    }
}
 

...