Unityでパーティクルからイーサンくんを生成してみる


こんなん

three.jsでできたんでUnityでもできるだろ〜なと思ってたらできました。

なおFPSは10で、実用性がない模様。

shaderに頂点データ送る必要ある。

コード

qiita.csharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MakingMeshParticle : MonoBehaviour {

    [SerializeField]
    private GameObject cube,character;

    List<GameObject> cubes = new List<GameObject>();
    List<Vector3> cubesTransform = new List<Vector3>();

    Mesh mesh{set {this.mesh= value;} get{return character.GetComponent <SkinnedMeshRenderer> ().sharedMesh;}}

    // Use this for initialization

    Vector3[] normals ;
    void Start () {

        Vector3[] vertices = mesh.vertices;
        normals = mesh.normals;


        mesh.vertices = vertices;

        for(int i =0;i<vertices.Length; i++){
            cubes.Add((GameObject)Instantiate (cube, vertices[i], Quaternion.identity));
            cubes [i].GetComponent<Renderer> ().material.color = Color.black;
            cubesTransform.Add (vertices [i]);
        }

    }

    // Update is called once per frame

    float n =0;
    void Update () {

        for(int i =1;i<cubes.Count; i++){
            cubes [i].transform.position = Vector3.Lerp(cubesTransform[i] ,new Vector3(Vector3.Magnitude(cubesTransform[i])*Mathf.Sin(i*100+Time.time),0,Mathf.Cos(i*100+Time.time)) ,Mathf.Sin(Time.time));
        }
    }
}

頂点のデータ配列を用意して、その値をgameobjectの位置情報に入れ込む。

僕のMacbookAirでもいい感じで動かしたいから、computeShader使えないからどうしたもんか。