Beispiel #1
0
        /**
         * GameObject go: GameObject to be mutated.
         * float mutationChance: float between 0 and 1, representing the probability that a node gets mutated.
         * float scaleMutationAmplitude: float representing by how much attributes of the node will be changed by the mutation.
         *      (e.g. 0.1 means that mutated attribute have a new value within 90% and 110% of the current one)
         * float rotationMutationAmplitude: max amount in degrees for mutation
         * */
        public SkeletonMutation(MeshedSkeleton skeleton, float mutationChance = 0.9f, float scaleMutationAmplitude = 0.8f, float lengthMutationAmplitude = 0.8f, float rotationMutationAmplitude = 50f)
        {
            this.skeleton                  = skeleton;
            this.gameObject                = skeleton.getOriginalSkeleton();
            this.mutationChance            = Mathf.Min(mutationChance, 1f);
            this.scaleMutationAmplitude    = scaleMutationAmplitude;
            this.lengthMutationAmplitude   = lengthMutationAmplitude;
            this.rotationMutationAmplitude = rotationMutationAmplitude;
            this.crossBreeds               = new List <MeshedSkeleton> ();

            this.mutant      = UnityEngine.Object.Instantiate(this.gameObject);
            this.mutant.name = "Mutation" + mutant.GetInstanceID().ToString();
            this.skeletonMutation(this.mutant);
        }
 // Use this for initialization
 void Start()
 {
     Debug.Log("start");
     meshIdToObject = new Dictionary <int, MeshedSkeleton> ();
     MeshedSkeleton ms = new MeshedSkeleton(this.gameObject.transform.parent.gameObject, this.gameObject.transform.localPosition, this.gameObject, meshIdToObject, false, false);
 }
Beispiel #3
0
        // Use this for initialization
        void Start()
        {
            GameObject container = new GameObject("MeshContainer");

            Debug.Log("starting");
            Debug.Log(this.gameObject.transform.position);
            container.transform.localPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
            this.gameObject.transform.SetParent(container.transform);
            this.gameObject.transform.localPosition = new Vector3(0, 0, 0);

            meshIdToObject = new Dictionary <int, MeshedSkeleton> ();
            GameObject leftLeg  = this.findChildWithName(this.gameObject, "LEFT_LEG");
            GameObject rightLeg = this.findChildWithName(this.gameObject, "RIGHT_LEG");
            GameObject leftArm  = this.findChildWithName(this.gameObject, "LEFT_ARM");
            GameObject rightArm = this.findChildWithName(this.gameObject, "RIGHT_ARM");

            float currRotation  = minRotation;
            float rotationDelta = 2f * (maxRotation - minRotation) / (1f * FRAMES_PER_FULL_MOVEMENT);

            float deltaSign = 1f;

            this.meshes = new List <GameObject> ();
            string guid = AssetDatabase.CreateFolder("Assets/Creatures/Resources/AnimatedMeshes", Mathf.Abs(container.GetInstanceID()).ToString());

            AssetDatabase.SaveAssets();
            string folderPath = AssetDatabase.GUIDToAssetPath(guid);

            for (int i = 0; i < FRAMES_PER_FULL_MOVEMENT; i++)
            {
                if (currRotation + rotationDelta > maxRotation)
                {
                    deltaSign = -1f;
                }

                currRotation += deltaSign * rotationDelta;
                //float currOffsetRotation =
                if (leftLeg != null)
                {
                    leftLeg.transform.localEulerAngles = new Vector3(currRotation, leftLeg.transform.localEulerAngles.y, leftLeg.transform.localEulerAngles.z);
                }
                if (rightLeg != null)
                {
                    rightLeg.transform.localEulerAngles = new Vector3(currRotation, rightLeg.transform.localEulerAngles.y, rightLeg.transform.localEulerAngles.z);
                }
                if (leftArm != null)
                {
                    leftArm.transform.localEulerAngles = new Vector3(currRotation, leftArm.transform.localEulerAngles.y, leftArm.transform.localEulerAngles.z);
                }
                if (rightArm != null)
                {
                    rightArm.transform.localEulerAngles = new Vector3(currRotation, rightArm.transform.localEulerAngles.y, rightArm.transform.localEulerAngles.z);
                }

                MeshedSkeleton ms   = new MeshedSkeleton(container, this.gameObject.transform.localPosition, this.gameObject, meshIdToObject, false, false);
                GameObject     mesh = ms.getMeshGameObject();
                mesh.transform.SetParent(container.transform);
                mesh.name = "MESH_" + i.ToString();
                if (i > 0)
                {
                    mesh.SetActive(false);
                }
                this.meshes.Add(mesh);

                AssetDatabase.CreateAsset(mesh.GetComponent <MeshFilter>().mesh, folderPath + "/RUN_" + i.ToString() + ".asset");
            }

            AssetDatabase.SaveAssets();

            container.AddComponent <Rigidbody> ();
            Rigidbody rb = container.GetComponent <Rigidbody> ();

            rb.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
        }