Beispiel #1
0
        private void GenerateCharacterAffectorFromData(InkData character)
        {
            Debug.Log(character.name);
            useAffector = 1;
            if (BoidAffectorBuffer != null)
            {
                BoidAffectorBuffer.Release();
            }
            AffectorCounts = character.inks.Length / 3;
            var affectorData = new BoidAffector[AffectorCounts];
            //TODO: Put it in a function
            float randomAngleX = UnityEngine.Random.Range(-50, 50);
            float randomAngleY = UnityEngine.Random.Range(-50, 50);

            Debug.Log(randomAngleX);
            Debug.Log(randomAngleY);
            Debug.Log("-------------------------------");
            for (int i = 0; i < AffectorCounts; i++)
            {
                int   xIndex = i * 3;
                int   yIndex = i * 3 + 1;
                int   zIndex = i * 3 + 2;
                float xPos   = character.inks[xIndex];
                float yPos   = character.inks[yIndex];
                //float zPos = character.inks[zIndex];
                Vector3 position = new Vector3(xPos, yPos, 50);
                //position = RotatePointAroundPivot(position, Vector3.zero, Quaternion.Euler(new Vector3(0, 135, 0)));
                Vector3 rotatedPosition = RotatePointAroundPivot(position, new Vector3(50, 50, 50), new Vector3(randomAngleX, randomAngleY, -90));
                var     affector        = new BoidAffector();
                affector.position = rotatedPosition;
                affector.force    = 0;
                affectorData[i]   = affector;
            }
            if (DrawingAffectors)
            {
                foreach (var affector in affectorData)
                {
                    var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    go.transform.localScale = new Vector3(1, 1, 1);
                    go.transform.position   = affector.position;
                }
            }
            //AffectorForce = 0.2f;

            _planeNormal = TestPlaneProjection.CalculatePlaneNormals(affectorData);
            Debug.Log(_planeNormal);
            Debug.Log("IIIIIIIIIIIIIIIIIIII");
            _planePoint = affectorData[89].position;
            StartMoveCamera(_planeNormal);
            BoidAffectorBuffer = new ComputeBuffer(AffectorCounts, Marshal.SizeOf(typeof(BoidAffector)));
            BoidAffectorBuffer.SetData(affectorData);
            affectorData = null;
            _startChangeAffectorDistance = true;
            AffectorDistance             = -2f;
        }
Beispiel #2
0
        private void GenerateCharacterAffectorFromPath(string path)
        {
            //path = "Assets/CharacterTest/ren.json";
            if (BoidAffectorBuffer != null)
            {
                BoidAffectorBuffer.Release();
            }
            string  jsonString = File.ReadAllText(path);
            InkData character  = JsonUtility.FromJson <InkData>(jsonString);

            AffectorCounts = character.inks.Length / 3;
            var affectorData = new BoidAffector[AffectorCounts];

            //TODO: Put it in a function
            for (int i = 0; i < AffectorCounts; i++)
            {
                int   xIndex = i * 3;
                int   yIndex = i * 3 + 1;
                int   zIndex = i * 3 + 2;
                float xPos   = character.inks[xIndex];
                float yPos   = character.inks[yIndex];
                //float zPos = character.inks[zIndex];
                Vector3 position        = new Vector3(xPos, yPos, 50);
                Vector3 rotatedPosition = RotatePointAroundPivot(position, new Vector3(50, 50, 50), new Vector3(25, 34, -90));
                var     affector        = new BoidAffector();
                affector.position = rotatedPosition;
                affector.force    = 0;
                affectorData[i]   = affector;
            }

            if (DrawingAffectors)
            {
                foreach (var affector in affectorData)
                {
                    var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    go.transform.localScale = new Vector3(1, 1, 1);
                    go.transform.position   = affector.position;
                }
            }

            _planeNormal = TestPlaneProjection.CalculatePlaneNormals(affectorData);
            _planePoint  = affectorData[89].position;
            Debug.Log(_planeNormal);
            Debug.Log("-------------------------------");
            //StartMoveCamera(_planeNormal);
            BoidAffectorBuffer = new ComputeBuffer(AffectorCounts, Marshal.SizeOf(typeof(BoidAffector)));
            BoidAffectorBuffer.SetData(affectorData);
            affectorData = null;
        }