Ejemplo n.º 1
0
    public override void Init(Transform tgtTransform = null)
    {
        //_marume = 10f;//Random.value * 3f;
        // if(Random.value<0.5f) _marume = 1000f;
        //Debug.Log("Init");
        _property = new MaterialPropertyBlock();
        _renderer = GetComponent <MeshRenderer>();

        _property.SetFloat("_ClipTh", 0.5f + Random.value * 0.4f);
        _property.SetFloat("_Naname", 30f + Random.value * 20f);


        _zRad    = Random.value * Mathf.PI * 2f;
        _zRadSpd = Random.value * 0.3f;

        _mesh = MeshUtil.CloneMesh(_meshSrc, "test");
        //_mesh = MeshUtil.GetNewMesh(_mesh,MeshTopology.Lines);

        _catmullResolution = Mathf.FloorToInt(3 + 2 * Random.value); //Params.Instance.catmullResolution;

        if (Random.value < 0.2f)
        {
            _catmullResolution = 3;
        }


        GetComponent <MeshFilter>().mesh = _mesh;

        //あとでやる

        /*
         * if(Params.Instance){
         *  _speed = 0.05f + Params.Instance.brushSpeedRandomness * Random.value;
         *  _masatsu = 0.1f + Params.Instance.brushMasatsuRandomness * Random.value;
         *
         * }else{
         *  _speed = 0.05f + 0.2f * Random.value;
         *  _masatsu = 0.1f + 0.8f * Random.value;
         * }*/
        _speed   = 0.02f + 0.10f * Random.value;
        _masatsu = 0.5f + 0.45f * Random.value;

        _mouse = new MouseUtil(
            _speed,   //speed
            _masatsu, //masatsu
            _catmullResolution,
            tgtTransform
            );
        _brushWidth = 0.03f + 0.10f * Random.value;
        //if(Random.value<0.5f) _brushWidth = 0.02f + 0.07f * Random.value;
        //_vertices = _mesh.vertices;
        //_indices = _mesh.triangles;
        //Debug.Log(_mesh.vertexCount);
    }
    void Start()
    {
        _mesh = MeshUtil.CloneMesh(_srcMesh, "test");
        //_mesh = MeshUtil.GetNewMesh(_mesh,MeshTopology.Lines);

        GetComponent <MeshFilter>().mesh = _mesh;

        _mouse     = new MouseUtil(0.1f + 0.1f * Random.value, 0.8f + 0.1f * Random.value, 3, null);
        _vertices  = _mesh.vertices;
        _binormals = new Vector3[_mesh.normals.Length];

        for (int i = 0; i < _vertices.Length; i++)
        {
            int idxX = i % 21;
            int idxY = Mathf.FloorToInt((float)i / 21f);

            float rx = (float)idxX / 20f;
            float ry = (float)idxY / 20f;

            _vertices[i] = new Vector3(
                1f * Mathf.Cos(-rx * Mathf.PI * 2f + Mathf.PI * 0.5f),
                1f * Mathf.Sin(-rx * Mathf.PI * 2f + Mathf.PI * 0.5f),
                ry
                );
        }
        _mesh.vertices = _vertices;
        _mesh.RecalculateNormals();
        _mesh.RecalculateTangents();

        _normals  = _mesh.normals;
        _tangents = _mesh.tangents;
        //_tangents   = new Vector3[_mesh.tangents.Length];
        var tangents = _mesh.tangents;


        /*
         * for(int i=0;i<_normals.Length;i++){
         *  //_normals[i] =
         *  var t = tangents[i];
         *  _tangents[i] = new Vector3(
         *      t.x,t.y,t.z
         *  );
         *  var tangent = tangents[i];
         *  var normal = _normals[i];
         *
         *  Debug.Log(i + " _ " + _normals.Length);
         *  _binormals[i] = Vector3.Cross(tangent, normal);
         * }*/
    }