Beispiel #1
0
        // Start is called before the first frame update
        void Awake()
        {
            mf = m_Model.GetComponent <MeshFilter>();
            Matrix4x4 localToWorld = transform.localToWorldMatrix;

            affectorData = new BoidAffector[mf.mesh.vertices.Length];
            //var affectorData = new BoidAffector[mf.mesh.vertices.Length];

            for (int i = 0; i < mf.mesh.vertices.Length; ++i)
            {
                Vector3 world_v = localToWorld.MultiplyPoint3x4(mf.mesh.vertices[i]);
                if (world_v.z < _areaCenter.z + _areaSize.z / 2 && world_v.z > _areaCenter.z - _areaSize.z / 2)
                {
                    m_Affector = Instantiate(Cube, world_v, this.transform.rotation);
                    //m_Affector.transform.parent = this.transform;
                    var affector = new BoidAffector();
                    affector.position   = world_v;
                    affector.force      = 0;
                    affectorData[count] = affector;
                    Debug.Log("between");
                    count++;
                }
                Debug.Log("count");
            }
            GroupResize(count, ref affectorData);
        }
 public void GroupResize(int Size, ref BoidAffector[] Group)
 {
     BoidAffector[] temp = new BoidAffector[Size];
     for (int c = 1; c < Mathf.Min(Size, Group.Length); c++)
     {
         temp[c] = Group[c];
     }
     Group = temp;
 }
Beispiel #3
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 #4
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;
        }
        void ColorCubeSpawner()
        {
            Color[] pixels = imageToRead.GetPixels();
            imageWall    = new GameObject[pixels.Length];
            affectorData = new BoidAffector[pixels.Length];


            for (int index = 0; index < pixels.Length; index++)
            {
                //Debug.Log("Color  " + pixels[index]);
                if (pixels[index].a >= 0.1)
                {
                    pos = new Vector3(index % imageToRead.width, index / imageToRead.width, 0);

                    //Debug.Log("jifdsaj");
                    var affector = new BoidAffector();
                    affector.position   = pos;
                    affector.force      = 0;
                    affectorData[count] = affector;
                    count++;
                }
            }
            GroupResize(count, ref affectorData);

            if (isSpawn)
            {
                for (int index = 0; index < pixels.Length; index++)
                {
                    //Debug.Log("Color  " + pixels[index]);
                    if (pixels[index].a >= 0.1)
                    {
                        imageWall[index] = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        imageWall[index].transform.position = new Vector3(index % imageToRead.width, index / imageToRead.width, 0);
                        imageWall[index].GetComponent <MeshRenderer>().material.color = pixels[index];
                        imageWall[index].transform.parent = this.transform;
                    }
                }
            }
        }