コード例 #1
0
        // Use this for initialization
        void Awake()
        {
            //initialize
            buffer  = new InstanceData[instanceCountsq * instanceCountsq];
            imesher = new MeshInstancer();
            imesher.Initialize(max_parent_depth: 2, pathCount: 4);

            this.p = new PathArrayHelper(this.imesher);

            // load all the textures
            var keys = Texture2MeshType.Textures2MeshType(this.Textures, imesher.Default.shared_mesh, imesher.Default.shared_material);

            // create all the mesh types that we can use
            foreach (var key in keys)
            {
                imesher.AddNewMeshType(key.mesh_key, key.material_key);
            }

            //make parent object
            parent          = new InstanceData(imesher.Default);
            parent.position = position;
            parent.scale    = scale;
            parent.rotation = Quaternion.Euler(rotation);
            buffer[0]       = parent;

            float v        = this.VelocityRange;
            var   rangemax = keys.Count;

            for (int i = 0; i < instanceCountsq; i++)
            {
                for (int j = 0; j < instanceCountsq; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        continue;                                                                                                                    // skip parent
                    }
                    var tkey = Random.Range(1, rangemax);                                                                                            // get random texture
                    var newt = new InstanceData(imesher.GetMeshType(keys[tkey].mesh_key, keys[tkey].material_key));                                  // make instance data

                    newt.position      = new Vector3(i, 0, j);                                                                                       // assign position of instance
                    newt.parentID      = 0;                                                                                                          // parent to instance at index 0
                    newt.props_color32 = new Color32((byte)Random.Range(0, 256), (byte)Random.Range(0, 256), (byte)Random.Range(0, 256), (byte)255); // set random color

                    // create & assign path
                    Path path = new Path(path_length: 4, m: this.imesher, use_constants: true);
                    this.p.InitializePath(ref path);
                    this.p.SetPathConstants(path, new Vector3(Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f)), new Vector3(Random.Range(-v, v), Random.Range(-v, v), Random.Range(-v, v)), newt.rotation, newt.position);
                    this.p.UpdatePath(ref path);
                    newt.SetPath(path, this.imesher);

                    buffer[i * instanceCountsq + j] = newt; // assign in buffer
                }
            }

            imesher.InitializeSet(buffer);
            imesher.AppendMany(buffer);
            parent = buffer[0];
        }
コード例 #2
0
        // Use this for initialization
        void Start()
        {
            Mesh     mesh     = BaseMeshLibrary.CreateDefault();
            Material material = new Material(Shader.Find("Instanced/instancemeshdefault_Transparent"));

            material.enableInstancing = true;

            imesher = new MeshInstancer();

            imesher.Initialize(64, 64, override_mesh: BaseMeshLibrary.CreatePlane2Sides(), override_material: BaseMaterialLibrary.CreateDefault(), max_parent_depth: 1, num_skeleton_bones: 1);
            var keys = Texture2MeshType.Textures2MeshType(this.Textures, mesh, material);

            foreach (var key in keys)
            {
                imesher.AddNewMeshType(key.mesh_key, key.material_key);
            }

            imesher.FrustumCamera = frustum_culling ? GameObject.Find("Main Camera").GetComponent <Camera>() : null;

            var udat = keys.Where(x => x.material_key.mainTexture.name == "clear3").First();

            InstanceData d1 = new InstanceData(imesher.GetMeshType(udat.mesh_key, udat.material_key));

            d1.props_color32 = new Color32(0, 0, 255, 90);
            d1.position      = new Vector3(0.5f, 0, 0);
            d1.rotation      = Quaternion.Euler(-90, 0, 0);
            d1.props_color32 = Color.blue;
            imesher.Initialize(ref d1);
            imesher.Append(ref d1);

            InstanceData d2 = new InstanceData(imesher.GetMeshType(udat.mesh_key, udat.material_key));

            d2.props_color32 = new Color32(0, 0, 255, 90);
            d2.position      = new Vector3(0, 0, 0);
            d2.rotation      = Quaternion.Euler(-90, 0, 0);
            d2.props_color32 = Color.blue;
            imesher.Initialize(ref d2);
            imesher.Append(ref d2);

            InstanceData d3 = new InstanceData(imesher.GetMeshType(udat.mesh_key, udat.material_key));

            d3.props_color32 = new Color32(0, 0, 255, 90);
            d3.position      = new Vector3(-0.5f, 0, 0);
            d3.rotation      = Quaternion.Euler(-90, 0, 0);
            d3.props_color32 = Color.blue;
            imesher.Initialize(ref d3);
            imesher.Append(ref d3);
        }