Пример #1
0
        /// <summary>
        /// Creates a game object for a new point light.
        /// </summary>
        /// <param name="entity_name">Entity name.</param>
        /// <param name="entity_parent_name">Entity parent name.</param>
        /// <param name="xform">Xform.</param>
        /// <param name="light_colour_ptr">Light colour ptr.</param>
        /// <param name="intensity">Intensity.</param>
        /// <param name="range">Range.</param>
        public static void PointLightAvailable(
            string entity_name,
            string entity_parent_name,
            System.IntPtr xform,
            System.IntPtr light_colour_ptr,
            float intensity,
            float range)
        {
            try
            {
                //Debug.Log (System.String.Format ("PointLight: {0} {1}", entity_name, entity_parent_name));

                var transform = GetXFormFromUnmanagedArray(xform);

                var colour = GetLightColour(light_colour_ptr);

                SceneTransmissionProtocolUtilities.CreatePointLight(
                    entity_name,
                    entity_parent_name,
                    transform,
                    colour,
                    intensity,
                    range
                    );
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
Пример #2
0
        /// <summary>
        /// Assigns a float array to an existing material's named parameter.
        /// </summary>
        /// <param name="entity_name">Entity name.</param>
        /// <param name="param_name">Parameter name.</param>
        /// <param name="num_elements">Number elements.</param>
        /// <param name="array">Array.</param>
        public static void MaterialSetFloatArray(
            string entity_name,
            string param_name,
            int num_elements,
            System.IntPtr array)
        {
            try
            {
                switch (param_name)
                {
                case "BaseColor":
                {
                    var color = GetColorFromArray(num_elements, array);
                    SceneTransmissionProtocolUtilities.MaterialSetAlbedo(entity_name, color);
                }
                break;

                case "EmissiveColor":
                {
                    var color = GetColorFromArray(num_elements, array);
                    SceneTransmissionProtocolUtilities.MaterialSetEmissive(entity_name, color);
                }
                break;

                default:
                    Debug.LogFormat("Unknown float array Material parameter '{0}'", param_name);
                    break;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
Пример #3
0
        public static GameObject CreateCamera(CameraData cameraData)
        {
            CameraProjectionType camType = (CameraProjectionType)cameraData.type;

            Debug.LogFormat("Camera - Token:{0}, Name:{1}, Projection Type:{2}, VerticalFov:{3}, AspectRatio:{4}, HorizontalMag:{5}, NearClip:{6}, FarClip:{7}", cameraData.entityToken, cameraData.displayName, camType, cameraData.verticalFov, cameraData.aspectRatio, cameraData.horizontalMag, cameraData.nearClip, cameraData.farClip);

            // Get transformation data
            var transform = MarshalData.GetXFormFromUnmanagedArray(cameraData.xform);

            // Create a new game object
            GameObject cameraInst = new GameObject(cameraData.displayName);

            // Set transformation
            SceneTransmissionProtocolUtilities.UpdateObjectHierarchy(cameraInst, null, transform);

            // Add camera component
            Camera camera = cameraInst.AddComponent <Camera>();

            SetCameraData(camera, cameraData);

            // Add token store
            PackageMapper.AddUniqueTokenStore(cameraInst, cameraData.entityToken);

            return(cameraInst);
        }
        public static GameObject CreateMeshInstance(MeshInstanceData meshInstanceData)
        {
            Debug.LogFormat("Mesh Instance - Token:{0}, Name:{1} Parent:{2}, Mesh:{3}", meshInstanceData.entityToken, meshInstanceData.displayName, meshInstanceData.entityParentToken, meshInstanceData.originalMesh);

            var transform = MarshalData.GetXFormFromUnmanagedArray(meshInstanceData.xform);

            // Find mesh prefab
            Object meshPrefabObj = PackageMapper.GetObjectFromToken(meshInstanceData.originalMesh);

            // Create a new game object
            GameObject meshInst = Object.Instantiate(meshPrefabObj as GameObject);

            // Remove the "(Clone)" string from name that Unity automatically adds when instantiating
            // and apply the actual display name of the instance
            meshInst.name = meshInstanceData.displayName;

            // Find instance parent
            Object parentObj = PackageMapper.GetObjectFromToken(meshInstanceData.entityParentToken);

            SceneTransmissionProtocolUtilities.UpdateObjectHierarchy(meshInst, parentObj as GameObject, transform);

            // Add token store
            PackageMapper.AddUniqueTokenStore(meshInst, meshInstanceData.entityToken);

            return(meshInst);
        }
Пример #5
0
        /// <summary>
        /// Creates a new Material (not a game object).
        /// </summary>
        /// <param name="entity_name">Entity name.</param>
        /// <param name="target">Target.</param>
        public static void MaterialAvailable(
            string entity_name,
            string target)
        {
            try
            {
                //Debug.Log (System.String.Format ("Material: {0} {1}", entity_name, target));

                SceneTransmissionProtocolUtilities.CreateMaterial(
                    entity_name,
                    target
                    );
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
        public static bool UpdateMeshInstance(MeshInstanceData meshInstanceData)
        {
            Debug.LogFormat("Mesh Instance Update - Token:{0}, Parent:{1}, Mesh:{2}", meshInstanceData.entityToken, meshInstanceData.entityParentToken, meshInstanceData.originalMesh);

            Object meshInstObj = PackageMapper.GetObjectFromToken(meshInstanceData.entityToken);
            var    meshInst    = meshInstObj as GameObject;

            var transform = MarshalData.GetXFormFromUnmanagedArray(meshInstanceData.xform);

            // Update the transformation of the item, ignore hierarchy updates for now
            // TODO: Work on hierarchy control systems
            Transform  parentTrs = meshInst.transform.parent;
            GameObject parent    = null;

            if (parentTrs)
            {
                parent = parentTrs.gameObject;
            }

            SceneTransmissionProtocolUtilities.UpdateObjectHierarchy(meshInst, parent, transform);

            // Update mesh filter
            Mesh mesh = PackageMapper.GetMeshFromToken(meshInstanceData.originalMesh);

            var meshFilter = meshInst.GetComponent <MeshFilter>();

            if (meshFilter)
            {
                meshFilter.sharedMesh = mesh;
            }

            // Update mesh renderer
            GameObject meshPrefab       = PackageMapper.GetObjectFromToken(meshInstanceData.originalMesh) as GameObject;
            var        meshRenderer     = meshPrefab.GetComponent <MeshRenderer>();
            var        meshInstRenderer = meshInst.GetComponent <MeshRenderer>();

            if (meshRenderer && meshInstRenderer)
            {
                meshInstRenderer.sharedMaterials = meshRenderer.sharedMaterials;
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Assigns a float value to an existing material's named parameter.
        /// </summary>
        /// <param name="entity_name">Entity name.</param>
        /// <param name="param_name">Parameter name.</param>
        /// <param name="value">Value.</param>
        public static void MaterialSetFloat(
            string entity_name,
            string param_name,
            float value)
        {
            try
            {
                switch (param_name)
                {
                case "Opacity":
                    SceneTransmissionProtocolUtilities.MaterialSetAlbedoOpacity(entity_name, value);
                    break;

                case "Roughness":
                    SceneTransmissionProtocolUtilities.MaterialSetGlossiness(entity_name, 1 - value);
                    break;

                case "Metalic":
                    SceneTransmissionProtocolUtilities.MaterialSetMetallic(entity_name, value);
                    break;

                case "IndexOfRefraction":
                case "Specular":
                case "SpecularRoughness":
                case "ClearCoat":
                case "ClearCoatRoughness":
                    Debug.LogFormat("No obvious setting for float Material parameter '{0}'", param_name);
                    break;

                default:
                    Debug.LogFormat("Unknown float Material parameter '{0}'", param_name);
                    break;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
Пример #8
0
        /// <summary>
        /// Delegate invoked when an unrecognised object is being handled.
        /// A game object is created, but only with a transform component.
        /// </summary>
        /// <param name="entity_name">Entity name.</param>
        /// <param name="entity_parent_name">Entity parent name.</param>
        /// <param name="xform">Xform.</param>
        public static void OtherAvailable(
            string entity_name,
            string entity_parent_name,
            System.IntPtr xform)
        {
            try
            {
                //Debug.Log (System.String.Format ("Other: {0} {1}", entity_name, entity_parent_name));

                var transform = GetXFormFromUnmanagedArray(xform);

                SceneTransmissionProtocolUtilities.CreateEmptyGameObject(
                    entity_name,
                    entity_parent_name,
                    transform
                    );
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
Пример #9
0
        public static bool UpdateCamera(CameraData cameraData)
        {
            CameraProjectionType camType = (CameraProjectionType)cameraData.type;

            Debug.LogFormat("Camera Update - Token:{0}, Name:{1}, Projection Type:{2}, VerticalFov:{3}, AspectRatio:{4}, HorizontalMag:{5}, NearClip:{6}, FarClip:{7}", cameraData.entityToken, cameraData.displayName, camType, cameraData.verticalFov, cameraData.aspectRatio, cameraData.horizontalMag, cameraData.nearClip, cameraData.farClip);

            // Get transformation data
            var transform = MarshalData.GetXFormFromUnmanagedArray(cameraData.xform);

            // Get camera game object
            GameObject cameraInst = PackageMapper.GetObjectFromToken(cameraData.entityToken) as GameObject;

            if (cameraInst)
            {
                // Set transformation
                SceneTransmissionProtocolUtilities.UpdateObjectHierarchy(cameraInst, null, transform);

                // Get camera component
                Camera camera = cameraInst.GetComponent <Camera>();

                if (camera)
                {
                    SetCameraData(camera, cameraData);
                }
                else
                {
                    Debug.LogErrorFormat("Camera Update error! Camera component not found! Token:{0}");
                    return(false);
                }
            }
            else
            {
                Debug.LogErrorFormat("Camera Update error! Camera game object not found! Token:{0}");
                return(false);
            }

            return(true);
        }
Пример #10
0
 private static void ImportIntoNewScene()
 {
     SceneTransmissionProtocolUtilities.CreateNewScene();
     Import();
 }