예제 #1
0
        private void TraverseScene(Transform root, string parentPath)
        {
            foreach (Transform currentTransform in root)
            {
                if (currentTransform == SceneManager.BoundingBox)
                {
                    continue;
                }

                string path = parentPath;
                path += "/" + currentTransform.name;


                // Depending on its type (which controller we can find on it) create data objects to be serialized
                LightController lightController = currentTransform.GetComponent <LightController>();
                if (null != lightController)
                {
                    LightData lightData = new LightData();
                    SetCommonData(currentTransform, parentPath, path, lightController, lightData);
                    SetLightData(lightController, lightData);
                    SceneData.Current.lights.Add(lightData);
                    continue;
                }

                CameraController cameraController = currentTransform.GetComponent <CameraController>();
                if (null != cameraController)
                {
                    CameraData cameraData = new CameraData();
                    SetCommonData(currentTransform, parentPath, path, cameraController, cameraData);
                    SetCameraData(cameraController, cameraData);
                    SceneData.Current.cameras.Add(cameraData);
                    continue;
                }

                ColimatorController colimatorController = currentTransform.GetComponent <ColimatorController>();
                if (null != colimatorController)
                {
                    // Nothing to do here, ignore the object
                    continue;
                }

                // Do this one at the end, because other controllers inherits from ParametersController
                ParametersController controller = currentTransform.GetComponent <ParametersController>();
                ObjectData           data       = new ObjectData();
                SetCommonData(currentTransform, parentPath, path, controller, data);
                try
                {
                    SetObjectData(currentTransform, controller, data);
                    SceneData.Current.objects.Add(data);
                }
                catch (Exception e)
                {
                    Debug.Log("Failed to set object data: " + e.Message);
                }

                // Serialize children
                if (!data.isImported)
                {
                    TraverseScene(currentTransform, path);
                }
            }
        }
예제 #2
0
        public void FromBytes(byte[] buffer, ref int index)
        {
            for (int i = 0; i < 6; i++)
            {
                if (buffer[i] != headerBuffer[i])
                {
                    throw new Exception("Invalid VRtist file Header");
                }
            }
            index += 6;

            fileVersion = Converter.GetInt(buffer, ref index);
            if (fileVersion > version)
            {
                throw new Exception("File version mismatch, please update VRtist");
            }


            int objectsCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < objectsCount; i++)
            {
                ObjectData data = new ObjectData();
                data.FromBytes(buffer, ref index);
                objects.Add(data);
            }

            int lightsCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < lightsCount; i++)
            {
                LightData data = new LightData();
                data.FromBytes(buffer, ref index);
                lights.Add(data);
            }

            int camerasCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < camerasCount; i++)
            {
                CameraData data = new CameraData();
                data.FromBytes(buffer, ref index);
                cameras.Add(data);
            }

            skyData = new SkySettings
            {
                topColor    = Converter.GetColor(buffer, ref index),
                middleColor = Converter.GetColor(buffer, ref index),
                bottomColor = Converter.GetColor(buffer, ref index)
            };

            int animationsCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < animationsCount; i++)
            {
                AnimationData data = new AnimationData();
                data.FromBytes(buffer, ref index);
                animations.Add(data);
            }

            int rigCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < rigCount; i++)
            {
                RigData data = new RigData();
                data.FromBytes(buffer, ref index);
                rigs.Add(data);
            }

            fps          = Converter.GetFloat(buffer, ref index);
            startFrame   = Converter.GetInt(buffer, ref index);
            endFrame     = Converter.GetInt(buffer, ref index);
            currentFrame = Converter.GetInt(buffer, ref index);

            int constraintsCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < constraintsCount; i++)
            {
                ConstraintData data = new ConstraintData();
                data.FromBytes(buffer, ref index);
                constraints.Add(data);
            }

            int shotsCount = Converter.GetInt(buffer, ref index);

            for (int i = 0; i < shotsCount; i++)
            {
                ShotData data = new ShotData();
                data.FromBytes(buffer, ref index);
                shots.Add(data);
            }

            playerData = new PlayerData();
            playerData.FromBytes(buffer, ref index);
        }