private void Start()
        {
            if (Edition.IsDecalSystemFree)
            {
                Debug.Log("This demo only works with Decal System Pro.");
                enabled = false;
            }
            else
            {
                // Instantiate the prefab and get its decals instance.
                m_DecalsInstance = Instantiate(m_DecalsPrefab) as DS_Decals;

                if (m_DecalsInstance == null)
                {
                    Debug.LogError("The decals prefab does not contain a DS_Decals instance!");
                }
                else
                {
                    // Create the decals mesh and the cutter that are needed to compute the projections.
                    // We also cache the world to decals matrix.
                    m_DecalsMesh = new DecalsMesh(m_DecalsInstance);
                    m_DecalsMesh.PreserveProjectedUVArrays = true;
                    m_DecalsMeshCutter    = new DecalsMeshCutter();
                    m_WorldToDecalsMatrix = m_DecalsInstance.CachedTransform.worldToLocalMatrix;

                    StartCoroutine(UpdateUVRectangleIndices());
                }
            }
        }
 // Move on to the next uv rectangle index. We call this method after each projection. In practice
 // you certainly don't do that, but pick an appropriate one depending on the surface that was hit.
 private void NextUVRectangleIndex(DS_Decals a_DecalsInstance)
 {
     m_UVRectangleIndex = m_UVRectangleIndex + 1;
     if (m_UVRectangleIndex >= a_DecalsInstance.CurrentUvRectangles.Length) {
         m_UVRectangleIndex = 7;
     }
 }
 // Move on to the next uv rectangle index. We call this method after each projection. In practice
 // you certainly don't do that, but pick an appropriate one depending on the surface that was hit.
 private void NextUVRectangleIndex(DS_Decals a_DecalsInstance)
 {
     m_UVRectangleIndex = m_UVRectangleIndex + 1;
     if (m_UVRectangleIndex >= a_DecalsInstance.CurrentUvRectangles.Length)
     {
         m_UVRectangleIndex = 7;
     }
 }
    // Move on to the next uv rectangle index.
    private void NextUVRectangleIndex(DS_Decals a_Decals)
    {
        m_UVRectangleIndex = m_UVRectangleIndex + 1;

        if (m_UVRectangleIndex >= a_Decals.uvRectangles.Length)
        {
            m_UVRectangleIndex = 7;
        }
    }
        private void Start()
        {
            // Instantiate the prefab and get its decals instance.
            m_DecalsInstance = Instantiate (m_DecalsPrefab) as DS_Decals;

            if (m_DecalsInstance == null) {
                Debug.LogError ("The decals prefab does not contain a DS_Decals instance!");
            } else {

                    // Create the decals mesh and the cutter that are needed to compute the projections.
                    // We also cache the world to decals matrix.
                m_DecalsMesh = new DecalsMesh (m_DecalsInstance);
                m_DecalsMeshCutter = new DecalsMeshCutter ();
                m_WorldToDecalsMatrix = m_DecalsInstance.CachedTransform.worldToLocalMatrix;
            }
        }
    private void Start()
    {
        // Instantiate the prefab and get its decals instance.
        GameObject l_Instance = Instantiate (decalsPrefab) as GameObject;
        m_Decals = l_Instance.GetComponentInChildren <DS_Decals> ();

        if (m_Decals == null) {
            Debug.LogError ("The 'decalsPrefab' does not contain a 'DS_Decals' instance!");
        } else {

                // Create the decals mesh (intermediate mesh data) for our decals instance.
                // Further we need a decals mesh cutter instance and the world to decals matrix.
            m_DecalsMesh = new DecalsMesh (m_Decals);
            m_DecalsMeshCutter = new DecalsMeshCutter ();
            m_WorldToDecalsMatrix = m_Decals.CachedTransform.worldToLocalMatrix;
        }
    }
        private void Start()
        {
            // Instantiate the prefab and get its decals instance.
            m_DecalsInstance = Instantiate(m_DecalsPrefab) as DS_Decals;

            if (m_DecalsInstance == null)
            {
                Debug.LogError("The decals prefab does not contain a DS_Decals instance!");
            }
            else
            {
                // Create the decals mesh and the cutter that are needed to compute the projections.
                // We also cache the world to decals matrix.
                m_DecalsMesh          = new DecalsMesh(m_DecalsInstance);
                m_DecalsMeshCutter    = new DecalsMeshCutter();
                m_WorldToDecalsMatrix = m_DecalsInstance.CachedTransform.worldToLocalMatrix;
            }
        }
Beispiel #8
0
    private void Start()
    {
        // Instantiate the prefab and get its decals instance.
        GameObject l_Instance = Instantiate(decalsPrefab) as GameObject;

        m_Decals = l_Instance.GetComponentInChildren <DS_Decals> ();

        if (m_Decals == null)
        {
            Debug.LogError("The 'decalsPrefab' does not contain a 'DS_Decals' instance!");
        }
        else
        {
            // Create the decals mesh (intermediate mesh data) for our decals instance.
            // Further we need a decals mesh cutter instance and the world to decals matrix.
            m_DecalsMesh          = new DecalsMesh(m_Decals);
            m_DecalsMeshCutter    = new DecalsMeshCutter();
            m_WorldToDecalsMatrix = m_Decals.CachedTransform.worldToLocalMatrix;
        }
    }
        private void Start()
        {
            // Instantiate the prefab and get its decals instance.
            m_DecalsInstance = Instantiate(m_DecalsPrefab) as DS_Decals;

            // Make sure the decals move with this dynamic object.
            m_DecalsInstance.transform.parent        = transform;
            m_DecalsInstance.transform.localPosition = Vector3.zero;
            m_DecalsInstance.transform.localScale    = Vector3.one;

            if (m_DecalsInstance == null)
            {
                Debug.LogError("The decals prefab does not contain a DS_Decals instance!");
            }
            else
            {
                // Create the decals mesh and the cutter that are needed to compute the projections.
                m_DecalsMesh       = new DecalsMesh(m_DecalsInstance);
                m_DecalsMeshCutter = new DecalsMeshCutter();
            }
        }
Beispiel #10
0
        private void Start()
        {
            if (Edition.IsDecalSystemFree) {
                Debug.Log ("This demo only works with Decal System Pro.");
                enabled = false;
            } else {

                    // Instantiate the prefab and get its decals instance.
                m_DecalsInstance = Instantiate (m_DecalsPrefab) as DS_Decals;
                m_DecalsInstance.UseVertexColors = true;

                if (m_DecalsInstance == null) {
                    Debug.LogError ("The decals prefab does not contain a DS_Decals instance!");
                } else {

                        // Create the decals mesh and the cutter that are needed to compute the projections.
                        // We also cache the world to decals matrix.
                    m_DecalsMesh = new DecalsMesh (m_DecalsInstance);
                    m_DecalsMeshCutter = new DecalsMeshCutter ();
                    m_WorldToDecalsMatrix = m_DecalsInstance.CachedTransform.worldToLocalMatrix;
                }
            }
        }
    private void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Ray        l_Ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.0f));
            RaycastHit l_RaycastHit;

            // Terrains have no uv2, so we just skip them.
            if
            (Physics.Raycast(l_Ray, out l_RaycastHit, Mathf.Infinity) &&
             l_RaycastHit.collider as TerrainCollider == null)
            {
                // Collider hit.

                // Make sure there are not too many decals instances.
                if (m_DecalsInstances.Count >= 50)
                {
                    m_DecalsInstances.RemoveAt(0);
                }


                // Instantiate the prefab and get its decals instance.
                GameObject l_Instance = Instantiate(decalsPrefab) as GameObject;
                DS_Decals  l_Decals   = l_Instance.GetComponentInChildren <DS_Decals> ();

                // Reuse the decals mesh, but be sure to initialize it always for the current
                // decals instance.
                m_DecalsMesh.Initialize(l_Decals);

                // Calculate the position and rotation for the new decal projector.
                Vector3    l_ProjectorPosition = l_RaycastHit.point - (decalProjectorOffset * l_Ray.direction.normalized);
                Vector3    l_ForwardDirection  = Camera.main.transform.up;
                Vector3    l_UpDirection       = -Camera.main.transform.forward;
                Quaternion l_ProjectorRotation = Quaternion.LookRotation(l_ForwardDirection, l_UpDirection);

                // Randomize the rotation.
                Quaternion l_RandomRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f);
                l_ProjectorRotation = l_ProjectorRotation * l_RandomRotation;


                // We hit a collider. Next we have to find the mesh that belongs to the collider.
                // That step depends on how you set up your mesh filters and collider relative to
                // each other in the game objects. It is important to have a consistent way in order
                // to have a simpler implementation.

                MeshCollider l_MeshCollider = l_RaycastHit.collider.GetComponent <MeshCollider> ();
                MeshFilter   l_MeshFilter   = l_RaycastHit.collider.GetComponent <MeshFilter> ();
                MeshRenderer l_MeshRenderer = l_RaycastHit.collider.GetComponent <MeshRenderer> ();

                if (l_MeshCollider != null || l_MeshFilter != null)
                {
                    Mesh l_Mesh = null;
                    if (l_MeshCollider != null)
                    {
                        // Mesh collider was hit. Just use the mesh data from that one.
                        l_Mesh = l_MeshCollider.sharedMesh;
                    }
                    else if (l_MeshFilter != null)
                    {
                        // Otherwise take the data from the shared mesh.
                        l_Mesh = l_MeshFilter.sharedMesh;
                    }

                    if (l_Mesh != null)
                    {
                        // Create the decal projector.
                        DecalProjector l_DecalProjector = new DecalProjector(l_ProjectorPosition, l_ProjectorRotation, decalProjectorScale, cullingAngle, meshOffset, m_UVRectangleIndex, m_UVRectangleIndex);

                        // All the mesh data that is now added to the decals mesh
                        // will belong to this projector.
                        m_DecalsMesh.AddProjector(l_DecalProjector);

                        // Get the required matrices.
                        Matrix4x4 l_WorldToMeshMatrix = l_RaycastHit.collider.renderer.transform.worldToLocalMatrix;
                        Matrix4x4 l_MeshToWorldMatrix = l_RaycastHit.collider.renderer.transform.localToWorldMatrix;

                        // Add the mesh data to the decals mesh, cut and offset it before we pass it
                        // to the decals instance to be displayed.
                        m_DecalsMesh.Add(l_Mesh, l_WorldToMeshMatrix, l_MeshToWorldMatrix);
                        m_DecalsMeshCutter.CutDecalsPlanes(m_DecalsMesh);
                        m_DecalsMesh.OffsetActiveProjectorVertices();
                        l_Decals.UpdateDecalsMeshes(m_DecalsMesh);

                        // Lightmapping
                        l_Decals.DecalsMeshRenderers [0].MeshRenderer.lightmapIndex        = l_MeshRenderer.lightmapIndex;
                        l_Decals.DecalsMeshRenderers [0].MeshRenderer.lightmapTilingOffset = l_MeshRenderer.lightmapTilingOffset;

                        // For the next hit, use a new uv rectangle. Usually, you would select the uv rectangle
                        // based on the surface you have hit.
                        NextUVRectangleIndex(l_Decals);
                    }
                }
            }
        }
    }
        private void Start()
        {
            // Instantiate the prefab and get its decals instance.
            m_DecalsInstance = Instantiate (m_DecalsPrefab) as DS_Decals;

                // Make sure the decals move with this dynamic object.
            m_DecalsInstance.transform.parent = transform;
            m_DecalsInstance.transform.localPosition = Vector3.zero;
            m_DecalsInstance.transform.localScale = Vector3.one;

            if (m_DecalsInstance == null) {
                Debug.LogError ("The decals prefab does not contain a DS_Decals instance!");
            } else {

                    // Create the decals mesh and the cutter that are needed to compute the projections.
                m_DecalsMesh = new DecalsMesh (m_DecalsInstance);
                m_DecalsMeshCutter = new DecalsMeshCutter ();
            }
        }