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));
}
}
}
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使えないからどうしたもんか。
Author And Source
この問題について(Unityでパーティクルからイーサンくんを生成してみる), 我々は、より多くの情報をここで見つけました https://qiita.com/renyama/items/feea699c347bad048ea4著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .