public void createProjectedDynamicDecal(Vector3 position, Quaternion rotation, Vector3 scale, Material mat, int layer, bool isCubeMap) { SceneData sd = gameObject.GetComponent <SceneData>(); if (sd == null) { Debug.Log("Error in function createProjectedDynamicDecal(), SceneData not found. No action taken"); return; } GameObject obj = new GameObject(); obj.name = "ProjectedDynamicDecal"; obj.tag = "ProjectedStaticDecal"; ProjectedStaticDecal decal = obj.AddComponent <ProjectedStaticDecal>(); obj.transform.position = position; obj.transform.rotation = rotation; obj.transform.localScale = scale; decal.material = mat; decal.layer = layer; decal.cubeMap = isCubeMap; decal.create(sd); pddList.Add(decal); pddBatcher.addDecal(decal); decal.updateMesh(); pddBatcher.updateBatch(); }
public void updateBatch() { // update the decals and respective geometry for (int j = 0; j < decals.Count; j++) { ProjectedStaticDecal decal = decals[j]; if (decal == null || decal.gameObject == null) { decals.RemoveAt(j); continue; } if (decal.isRtUpdateEnabled()) { decal.updateMesh(); } filler.reset(); decal.fillBatchData(filler); // we have our batched data, add it into overall batch if (filler.material != null) { // we already have this material, add to batch if (batch.ContainsKey(filler.material)) { BatchedGeometry m = batch[filler.material]; int offset = m.vertices.Count; m.vertices.AddRange(filler.vertices); // offset out indices to new vertex positions for (int i = 0; i < filler.indices.Count; i++) { m.indices.Add(filler.indices[i] + offset); } m.uv.AddRange(filler.uv); } else { // add a new key because key doesnt exist, and add to batch batch.Add(filler.material, new BatchedGeometry()); BatchedGeometry m = batch[filler.material]; int offset = m.vertices.Count; m.vertices.AddRange(filler.vertices); // offset our indices to new vertex positions for (int i = 0; i < filler.indices.Count; i++) { m.indices.Add(filler.indices[i] + offset); } m.uv.AddRange(filler.uv); } } } // batch all the updated decals and clear previous buffers foreach (BatchedGeometry b in batch.Values) { b.batch(); } }