Ejemplo n.º 1
0
        void Start()
        {
            //Read Position data from json file
            //TODO: Maybe Adding Network utility
            string  path       = "Assets/CharacterTest/ren.json";
            string  jsonString = File.ReadAllText(path);
            InkData character  = JsonUtility.FromJson <InkData>(jsonString);

            numberOfParticles = character.inks.Length / 3;

            // パーティクルのコンピュートバッファを作成
            //particleBuffer = new ComputeBuffer(NUM_PARTICLES, Marshal.SizeOf(typeof(ParticleData)));
            particleBuffer   = new ComputeBuffer(numberOfParticles, Marshal.SizeOf(typeof(ParticleData)));
            connectionBuffer = new ComputeBuffer(numberOfParticles, Marshal.SizeOf(typeof(ConnectionData)));

            // パーティクルの初期値を設定
            //var pData = new ParticleData[NUM_PARTICLES];
            var pData = new ParticleData[numberOfParticles];
            var cData = new ConnectionData[numberOfParticles];

            for (int i = 0; i < pData.Length; i++)
            {
                //pData[i].Velocity = Random.insideUnitSphere;
                //pData[i].Position = Random.insideUnitSphere;
                float vIndicator = Random.Range(0.0f, 1.0f);
                float zSpeed     = Random.Range(0.0f, 0.2f);
                if (vIndicator > 0.5)
                {
                    zSpeed = -1 * zSpeed;
                }
                pData[i].Velocity = new Vector3(0, -0.00001f, zSpeed);
                int xIndex = i * 3;
                int yIndex = i * 3 + 1;
                int zIndex = i * 3 + 2;
//                float xPos = character.inks[xIndex]/(float)100.0;
//                float yPos = character.inks[yIndex]/(float)100.0;
//                float zPos = character.inks[zIndex]/(float)100.0;
                float   xPos     = UnityEngine.Random.Range(0f, 100f);
                float   yPos     = UnityEngine.Random.Range(0f, 100f);
                float   zPos     = UnityEngine.Random.Range(0f, 100f);
                Vector3 position = new Vector3(yPos * 2, -xPos * 2, 0);
                pData[i].Position = position;
                // Set Up Connection Data
                cData[i].Start   = new Vector3(0, 0, 0);
                cData[i].End     = new Vector3(0, 0, 0);
                cData[i].Connect = 0;
            }
            // コンピュートバッファに初期値データをセット
            particleBuffer.SetData(pData);
            connectionBuffer.SetData(cData);

            pData = null;
            cData = null;
            // パーティクルをレンダリングするマテリアルを作成
            particleRenderMat           = new Material(SimpleParticleRenderShader);
            particleRenderMat.hideFlags = HideFlags.HideAndDontSave;

            lineRenderMat           = new Material(SimpleLineRenderShader);
            lineRenderMat.hideFlags = HideFlags.HideAndDontSave;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }