Beispiel #1
0
        //!
        //! Use this for initialization
        //!
        void Awake()
        {
            updateAppearance = true;

            //cache reference to main Controller
            mainController = GameObject.Find("MainController").GetComponent <MainController>();

            //cache reference to animation timeline
            timeLineObject = GameObject.Find("GUI/Canvas/UI/TimeLine");
            if (timeLineObject == null)
            {
                Debug.LogError(string.Format("{0}: Cant Find TimeLine (GUI/Canvas/UI/TimeLine).", this.GetType()));
            }

            timeLine = timeLineObject.GetComponent <TimeLineWidget>();
            if (timeLine == null)
            {
                Debug.LogError(string.Format("{0}: No TimeLine script attached.", this.GetType()));
            }
            // assign callback for frame changes on timeline (on user drag)
            timeLine.Callback = this.setTime;

            //cache reference to keyframe Sphere container
            if (!frameSphereContainer)
            {
                frameSphereContainer = new GameObject("FrameSphereContainer");
                frameSphereContainer.transform.parent        = GameObject.Find("Scene").transform;
                frameSphereContainer.transform.localPosition = Vector3.zero;
                frameSphereContainer.transform.localRotation = Quaternion.identity;
                frameSphereContainer.transform.localScale    = Vector3.one;
            }

            // cache key prefab
            keySpherePrefab = Resources.Load <GameObject>("VPET/Prefabs/KeySphere");
            if (keySpherePrefab == null)
            {
                Debug.LogError(string.Format("{0}: Cant find Resources: KeySphere.", this.GetType()));
            }

            //cache reference to dragArea and deactivate it
            //dragArea = timeline.transform.GetChild(7).gameObject;
            //dragArea.SetActive(false);

            //cache Reference to animation data
            animData = AnimationData.Data;

            //initalize keyframe list
            keyframeSpheres = new List <GameObject>();

            //initalize animated scene objects list
            if (animatedObjects == null)
            {
                animatedObjects = new List <SceneObject>();
            }

            //initialize animation layers
            for (int i = 0; i < animationLayers.Length; ++i)
            {
                animationLayers[i] = new AnimationLayer();
            }

            //initalize lineRenderer
            lineRenderer               = gameObject.AddComponent <LineRenderer>();
            lineRenderer.material      = Resources.Load <Material>("VPET/Materials/LineRendererMaterial");
            lineRenderer.useWorldSpace = true;
            lineRenderer.positionCount = 0;
        }
        //!
        //! Saves Animation Data to a XML structure into a file
        //!
        public void OnApplicationQuit()
        {
            if (Save_Data_to_XML == false || AnimationData.Data.getAnimationClips(gameObject) == null)
            {
                return;
            }

            List <AnimationClip> clips = AnimationData.Data.getAnimationClips(gameObject);

            XML_AnimationData runtimeXMLData = new XML_AnimationData();

            List <XML_AnimationClip> XMLclipList = new List <XML_AnimationClip>();

            foreach (AnimationClip clip in clips)
            {
                XML_AnimationClip XMLclip = new XML_AnimationClip(gameObject.name + "_Amimation");
                foreach (string property in observedProperties)
                {
                    if (AnimationData.Data.getAnimationCurve(clip, property) != null)
                    {
                        List <XML_KeyFrame> XMLkeys = new List <XML_KeyFrame>();
                        foreach (Keyframe key in AnimationData.Data.getAnimationCurve(clip, property).keys)
                        {
                            XMLkeys.Add(new XML_KeyFrame(key.inTangent, key.outTangent, key.time, key.value, key.tangentMode));
                        }
                        XML_AnimationCurve XMLcurve = new XML_AnimationCurve(XMLkeys, AnimationData.WrapModeToString(AnimationData.Data.getAnimationCurve(clip, property).postWrapMode), AnimationData.WrapModeToString(AnimationData.Data.getAnimationCurve(clip, property).preWrapMode), "UnityEngine.Transform", property);
                        XMLclip.XML_AnimationCurves.Add(XMLcurve);
                    }
                }
                XMLclipList.Add(XMLclip);
            }
            runtimeXMLData.XML_AnimationClips = XMLclipList;
            AnimationData.Save(gameObject.name, runtimeXMLData);
        }
Beispiel #3
0
        //!
        //! Use this for initialization
        //!
        protected void Start()
        {
            target = this.transform;

            isPhysicsActive = false;

            serverAdapter = GameObject.Find("ServerAdapter").GetComponent <ServerAdapter>();

#if !SCENE_HOST
            animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>();
            mainController      = GameObject.Find("MainController").GetComponent <MainController>();
            sceneLoader         = GameObject.Find("SceneAdapter").GetComponent <SceneLoader>();

            //cache Reference to animation data
            animData = AnimationData.Data;
#endif

            //update initial parameters
            initialPosition = target.localPosition;
            initialRotation = target.localRotation;
            initialScale    = target.localScale;

            lastPosition = initialPosition;
            lastRotation = initialRotation;


            //generate colliding volumes
            if (generateBoxCollider)
            {
                //calculate bounds
                bounds = new Bounds(Vector3.zero, Vector3.zero);


                bool       hasBounds = false;
                Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>(true);
                foreach (Renderer render in renderers)
                {
                    if (!sceneLoader.isEditable(render.gameObject) || render.gameObject == this.gameObject)
                    {
                        if (hasBounds)
                        {
                            bounds.Encapsulate(render.bounds);
                        }
                        else
                        {
                            bounds    = render.bounds;
                            hasBounds = true;
                        }
                    }
                }

                boxCollider = this.gameObject.AddComponent <BoxCollider>();
#if !SCENE_HOST
                if (this is SceneObjectCamera)
                {
                    boxCollider.enabled = mainController.showCam;
                }
#endif



                // col.isTrigger = true; // not interacting
                if ((this is SceneObject) && !(this is SceneObjectLight))
                {
                    boxCollider.center              = new Vector3((bounds.center.x - this.transform.position.x) / this.transform.lossyScale.x, (bounds.center.y - this.transform.position.y) / this.transform.lossyScale.y, (bounds.center.z - this.transform.position.z) / this.transform.lossyScale.z);
                    boxCollider.size                = new Vector3(bounds.size.x / this.transform.lossyScale.x, bounds.size.y / this.transform.lossyScale.y, bounds.size.z / this.transform.lossyScale.z);
                    boxCollider.material            = new PhysicMaterial();
                    boxCollider.material.bounciness = 1.0f;
                }
            }
            if (this is SceneObject)
            {
                rigidbody = this.gameObject.AddComponent <Rigidbody>();

                rigidbody.mass = 100f;
                rigidbody.drag = 2.5f;

                // TODO: temporary
                rigidbody.useGravity  = true;
                rigidbody.isKinematic = true;
                globalKinematic       = true;
            }

#if !SCENE_HOST
            //Initalize animation loading if animation available
            AnimationSerializer asScript = target.gameObject.AddComponent <AnimationSerializer>();
            if (asScript.loadData())
            {
                //register the object in the animation Controller
                GameObject.Find("AnimationController").GetComponent <AnimationController>().registerAnimatedObject(gameObject.GetComponent <SceneObject>());
                gameObject.GetComponent <SceneObject>().setKinematic(true, false);
                updateAnimationCurves();
            }

            isPlayingAnimation = false;
#endif
        }
Beispiel #4
0
        //!
        //! Use this for initialization
        //!
        void Start()
        {
            if (transform.childCount > 0)
            {
                lightTarget = transform.GetChild(0);
                if (lightTarget != null)
                {
                    sourceLight = lightTarget.GetComponent <Light>();
                }
            }


            if (sourceLight)
            {
                target = this.transform;

                initialLightColor     = sourceLight.color;
                initialLightColor.a   = 0.25f;
                initialLightIntensity = sourceLight.intensity;

                if (sourceLight.type == LightType.Directional)
                {
                    isDirectionalLight = true;
                    lightGeo           = lightTarget.Find("Arrow");
                }
                else if (sourceLight.type == LightType.Spot)
                {
                    isSpotLight       = true;
                    initialLightRange = sourceLight.range;
                    initialSpotAngle  = sourceLight.spotAngle;
                    lightGeo          = lightTarget.Find("Cone");
                }
                else if (sourceLight.type == LightType.Point)
                {
                    isPointLight      = true;
                    initialLightRange = sourceLight.range;
                    lightGeo          = lightTarget.Find("Sphere");
                }
            }
            else
            {
                target = this.transform;
            }

            //initalize cached references
            serverAdapter = GameObject.Find("ServerAdapter").GetComponent <ServerAdapter>();


            //cache Reference to animation data
            animData = AnimationData.Data;

            //update initial parameters
            initialPosition = target.position;
            initialRotation = target.rotation;
            initialScale    = target.localScale;

            lastPosition = initialPosition;
            lastRotation = initialRotation;


            //generate colliding volumes
            if (generateBoxCollider)
            {
                //calculate bounds
                bounds = new Bounds(Vector3.zero, Vector3.zero);


                bool       hasBounds = false;
                Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer render in renderers)
                {
                    if (!sceneLoader.isEditable(render.gameObject) || render.gameObject == this.gameObject)
                    {
                        if (hasBounds)
                        {
                            bounds.Encapsulate(render.bounds);
                        }
                        else
                        {
                            bounds    = render.bounds;
                            hasBounds = true;
                        }
                    }
                }

                BoxCollider col = this.gameObject.AddComponent <BoxCollider>();

                // TODO: temporary
                col.isTrigger = true; // not interacting



                if (sourceLight)
                {
                    // BoxCollider col_lightquad = lightTarget.FindChild("LightQuad").GetComponent<BoxCollider>();
                    // col.size = col_lightquad.size;
                    // col.center = col_lightquad.center;
                    col.isTrigger = true; // not interacting
                    LightIcon iconScript = lightTarget.Find("LightQuad").GetComponent <LightIcon>();
                    iconScript.TargetCollider = col;
                    iconScript.TargetScale    = target.lossyScale; // target.localScale;
                }
                else
                {
                    col.center              = new Vector3((bounds.center.x - this.transform.position.x) / this.transform.lossyScale.x, (bounds.center.y - this.transform.position.y) / this.transform.lossyScale.y, (bounds.center.z - this.transform.position.z) / this.transform.lossyScale.z);
                    col.size                = new Vector3(bounds.size.x / this.transform.lossyScale.x, bounds.size.y / this.transform.lossyScale.y, bounds.size.z / this.transform.lossyScale.z);
                    col.material            = new PhysicMaterial();
                    col.material.bounciness = 1.0f;
                }

                //target.position = initialPosition;
                // target.localScale = initialScale;
                // target.rotation = initialRotation;
            }
            if (!isDirectionalLight && !isPointLight && !isSpotLight && this.name != "camera")
            {
                this.gameObject.AddComponent <Rigidbody>();
                this.gameObject.GetComponent <Rigidbody>().mass = 100.0f;
                this.gameObject.GetComponent <Rigidbody>().drag = 2.5f;


                // TODO: temporary
                this.gameObject.GetComponent <Rigidbody>().useGravity = false;
            }


            // get animator object to trigger mocap anims
            animatorObject = transform.GetComponent <AnimatorObject>();
            if (animatorObject == null)
            {
                animatorObject = transform.parent.GetComponent <AnimatorObject>();
            }
        }
Beispiel #5
0
        //!
        //! Use this for initialization
        //!
        void Start()
        {
            if (transform.childCount > 0)
            {
                lightTarget = transform.GetChild(0);
                if (lightTarget != null)
                {
                    sourceLight = lightTarget.GetComponent <Light>();
                }
            }

            // if (this.transform.parent.transform.GetComponent<Light>())

            if (sourceLight)
            {
                // target = this.transform.parent;
                target = this.transform;

                initialLightColor     = sourceLight.color;
                initialLightColor.a   = 0.25f;
                initialLightIntensity = sourceLight.intensity;

                if (sourceLight.type == LightType.Directional)
                {
                    isDirectionalLight = true;
                    lightGeo           = lightTarget.FindChild("Arrow");
                }
                else if (sourceLight.type == LightType.Spot)
                {
                    isSpotLight       = true;
                    initialLightRange = sourceLight.range;
                    initialSpotAngle  = sourceLight.spotAngle;
                    lightGeo          = lightTarget.FindChild("Cone");
                }
                else if (sourceLight.type == LightType.Point)
                {
                    isPointLight      = true;
                    initialLightRange = sourceLight.range;
                    lightGeo          = lightTarget.FindChild("Sphere");
                }
            }
            else
            {
                target = this.transform;
            }

            //initalize cached references
            animationController = GameObject.Find("AnimationController").GetComponent <AnimationController>();
            mainController      = GameObject.Find("MainController").GetComponent <MainController>();
            serverAdapter       = GameObject.Find("ServerAdapter").GetComponent <ServerAdapter>();
            undoRedoController  = GameObject.Find("UndoRedoController").GetComponent <UndoRedoController> ();

            //cache Reference to animation data
            animData = AnimationData.Data;

            //update initial parameters
            initialPosition = target.position;
            initialRotation = target.rotation;
            initialScale    = target.localScale;

            lastPosition = initialPosition;
            lastRotation = initialRotation;


            //generate colliding volumes
            if (generateBoxCollider)
            {
                //calculate bounds
                //target.position = new Vector3(-3000,-3000,-3000);
                //target.localScale = new Vector3(1, 1, 1);
                bounds = new Bounds(Vector3.zero, Vector3.zero);
                //set rotation to 0
                // this.transform.rotation = Quaternion.Euler(Vector3.zero);


                bool       hasBounds = false;
                Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer render in renderers)
                {
                    if (hasBounds)
                    {
                        bounds.Encapsulate(render.bounds);
                    }
                    else
                    {
                        bounds    = render.bounds;
                        hasBounds = true;
                    }
                }

                BoxCollider col = this.gameObject.AddComponent <BoxCollider>();

                if (sourceLight)
                {
                    // BoxCollider col_lightquad = lightTarget.FindChild("LightQuad").GetComponent<BoxCollider>();
                    // col.size = col_lightquad.size;
                    // col.center = col_lightquad.center;
                    LightIcon iconScript = lightTarget.FindChild("LightQuad").GetComponent <LightIcon>();
                    iconScript.TargetCollider = col;

                    iconScript.TargetScale = target.localScale;
                }
                else
                {
                    col.center              = new Vector3((bounds.center.x - this.transform.position.x) / this.transform.lossyScale.x, (bounds.center.y - this.transform.position.y) / this.transform.lossyScale.y, (bounds.center.z - this.transform.position.z) / this.transform.lossyScale.z);
                    col.size                = new Vector3(bounds.size.x / this.transform.lossyScale.x, bounds.size.y / this.transform.lossyScale.y, bounds.size.z / this.transform.lossyScale.z);
                    col.material            = new PhysicMaterial();
                    col.material.bounciness = 1.0f;
                }

                //target.position = initialPosition;
                // target.localScale = initialScale;
                // target.rotation = initialRotation;
            }
            if (!isDirectionalLight && !isPointLight && !isSpotLight && this.name != "camera")
            {
                this.gameObject.AddComponent <Rigidbody>();
                this.gameObject.GetComponent <Rigidbody>().mass = 100.0f;
                this.gameObject.GetComponent <Rigidbody>().drag = 2.5f;



                // this.gameObject.GetComponent<Rigidbody>().useGravity = false;
            }

            //Initalize animation loading if animation available
            AnimationSerializer asScript = target.gameObject.AddComponent <AnimationSerializer>();

            if (asScript.loadData())
            {
                //register the object in the animation Controller
                GameObject.Find("AnimationController").GetComponent <AnimationController>().registerAnimatedObject(gameObject.GetComponent <SceneObject>());
                gameObject.GetComponent <SceneObject>().setKinematic(true, false);
                updateAnimationCurves();
            }
        }