コード例 #1
0
ファイル: ObjectController.cs プロジェクト: arajar/Coherence
        internal void UpdateFromInterop(InteropSceneObject obj)
        {
            // Blender is z-up - swap z/y everywhere
            // TODO: But they could also change the up axis manually...
            InteropMatrix4x4 t = obj.transform;

            transform.position = new Vector3(t.m03, t.m23, t.m13);

            Vector3 forward;

            forward.x = t.m02;
            forward.y = t.m22;
            forward.z = t.m12;

            Vector3 up;

            up.x = t.m01;
            up.y = t.m21;
            up.z = t.m11;

            transform.rotation = Quaternion.LookRotation(forward, up);

            // Multiplying X by -1 to account for different axes.
            // TODO: Improve on.
            transform.localScale = new Vector4(
                new Vector4(t.m00, t.m10, t.m30, t.m20).magnitude * -1,
                new Vector4(t.m01, t.m11, t.m31, t.m21).magnitude,
                new Vector4(t.m02, t.m12, t.m32, t.m22).magnitude
                );

            if (obj.type == SceneObjectType.Mesh && mesh == null)
            {
                AddMesh($"Blender Mesh `{obj.name}`");
            }

            // Material name change
            if (Data.material != obj.material)
            {
                SetMaterial(obj.material);
            }

            Data = obj;
        }
コード例 #2
0
        private void UpdateObject(string name, InteropSceneObject iso)
        {
            var obj = GetObject(name);
            var needsReparenting = !iso.transform.parent.Equals(obj.Data.transform.parent);

            obj.UpdateFromInterop(iso);

            if (string.IsNullOrEmpty(iso.mesh))
            {
                obj.SetMesh(null);
            }
            else
            {
                obj.SetMesh(GetOrCreateMesh(iso.mesh));
            }

            if (needsReparenting)
            {
                ReparentObject(obj);
            }
        }
コード例 #3
0
        private ObjectController AddObject(string name, InteropSceneObject iso)
        {
            if (objectsContainer == null)
            {
                objectsContainer = new GameObject("Objects");
                objectsContainer.transform.parent = transform;
            }

            var prefab = CoherenceSettings.Instance.sceneObjectPrefab;
            var go     = prefab ? Instantiate(prefab) : new GameObject();

            go.name             = name;
            go.transform.parent = objectsContainer.transform;

            var controller = go.AddComponent <ObjectController>();

            objects[name] = controller;
            controller.UpdateFromInterop(iso);

            return(controller);
        }
コード例 #4
0
        internal void UpdateFromInterop(InteropSceneObject obj)
        {
            transform.position   = obj.transform.position.ToVector3();
            transform.rotation   = obj.transform.rotation.ToQuaternion();
            transform.localScale = obj.transform.scale.ToVector3();

            // Material name change
            if (Data.material != obj.material)
            {
                SetMaterial(obj.material);
            }

            if (obj.display != Data.display)
            {
                SetDisplayMode(obj.display);
            }

            // TODO: Mesh change should be here too but it's happening
            // in SyncManager.UpdateObject() because I don't have a
            // singleton of SyncManager to access the mesh factory from.

            Data = obj;
        }
コード例 #5
0
        private ObjectController AddObject(string name, InteropSceneObject iso)
        {
            if (objectsContainer == null)
            {
                objectsContainer = new GameObject("Objects")
                {
                    tag       = "EditorOnly",
                    hideFlags = HideFlags.NotEditable | HideFlags.DontSave
                };

                objectsContainer.transform.parent = transform;
            }

            // TODO: prefab per object type mapping

            var prefab     = CoherenceSettings.Instance.sceneObjectPrefab;
            var go         = prefab ? Instantiate(prefab) : new GameObject();
            var controller = go.AddComponent <ObjectController>();

            go.name = name;

            objects[name] = controller;
            controller.UpdateFromInterop(iso);

            Debug.Log($"Add object {name} with mesh {iso.mesh}");
            if (!string.IsNullOrEmpty(iso.mesh))
            {
                controller.SetMesh(GetOrCreateMesh(iso.mesh));
            }

            ReparentObject(controller);

            // Attach any orphaned objects that were waiting for this parent to be added.
            CheckOrphanedObjects();

            return(controller);
        }