Esempio n. 1
0
 private void SetLightData(LightController controller, LightData data)
 {
     data.lightType    = controller.Type;
     data.intensity    = controller.Intensity;
     data.minIntensity = controller.minIntensity;
     data.maxIntensity = controller.maxIntensity;
     data.color        = controller.Color;
     data.castShadows  = controller.CastShadows;
     data.near         = controller.ShadowNearPlane;
     data.range        = controller.Range;
     data.minRange     = controller.minRange;
     data.maxRange     = controller.maxRange;
     data.outerAngle   = controller.OuterAngle;
     data.sharpness    = controller.Sharpness;
 }
Esempio n. 2
0
        private void LoadLight(LightData data)
        {
            GameObject lightPrefab = null;

            switch (data.lightType)
            {
            case LightType.Directional:
                lightPrefab = ResourceManager.GetPrefab(PrefabID.SunLight);
                break;

            case LightType.Spot:
                lightPrefab = ResourceManager.GetPrefab(PrefabID.SpotLight);
                break;

            case LightType.Point:
                lightPrefab = ResourceManager.GetPrefab(PrefabID.PointLight);
                break;
            }

            if (lightPrefab)
            {
                GameObject newPrefab = SceneManager.InstantiateUnityPrefab(lightPrefab);
                GameObject newObject = SceneManager.AddObject(newPrefab);

                if (data.parentPath.Length > 0)
                {
                    SceneManager.SetObjectParent(newObject, rootTransform.Find(data.parentPath).gameObject);
                }

                LoadCommonData(newObject, data);

                LightController controller = newObject.GetComponent <LightController>();
                controller.Intensity       = data.intensity;
                controller.minIntensity    = data.minIntensity;
                controller.maxIntensity    = data.maxIntensity;
                controller.Color           = data.color;
                controller.CastShadows     = data.castShadows;
                controller.ShadowNearPlane = data.near;
                controller.Range           = data.range;
                controller.minRange        = data.minRange;
                controller.maxRange        = data.maxRange;
                controller.OuterAngle      = data.outerAngle;
                controller.Sharpness       = data.sharpness;
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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);
        }