Dessiner des textures sur un terrain en temps réel

Questions à propos du scripting. Hors Shader, GUI, Audio et Mobile.
calypsomen
Messages : 45
Inscription : 26 Mars 2019 16:39

Dessiner des textures sur un terrain en temps réel

Message par calypsomen » 20 Fév 2023 19:39

Bonjour à tous,

Je recherche des méthodes possibles pour dessiner des textures sur un terrain en temps réel directement en jeu via un éditeur. Mon jeu utilise HDRP. J'ai essayé avec SetAlphamaps mais les textures ne sont pas affichées :(

Code : Tout sélectionner

float[,] alphaMap = terrainData.GetAlphamaps(
                    (int)((hitInfo.point.x / terrainData.size.x) * alphaMapWidth),
                    (int)((hitInfo.point.z / terrainData.size.z) * alphaMapHeight),
                    1, 1);

                // Modifier l'alpha map du terrain en fonction de la texture
                int textureIndex = this.textureIndex % numOfTextures;
                for (int i = 0; i < alphaMapWidth; i++)
                {
                    for (int j = 0; j < alphaMapHeight; j++)
                    {
                        float distance = Mathf.Sqrt((i - hitInfo.textureCoord.x * alphaMapWidth) * (i - hitInfo.textureCoord.x * alphaMapWidth) + (j - hitInfo.textureCoord.y * alphaMapHeight) * (j - hitInfo.textureCoord.y * alphaMapHeight));
                        if (distance < brushSize)
                        {
                            alphaMap[j, i, textureIndex] += Time.deltaTime;
                        }
                    }
                }
                terrainData.SetAlphamaps(
                    (int)((hitInfo.point.x / terrainData.size.x) * alphaMapWidth),
                    (int)((hitInfo.point.z / terrainData.size.z) * alphaMapHeight),
                    alphaMap);
Merci beaucoup par avance pour votre aide !

Avatar de l’utilisateur
jmhoubre
Messages : 851
Inscription : 05 Oct 2019 22:05

Re: Dessiner des textures sur un terrain en temps réel

Message par jmhoubre » 21 Fév 2023 01:09

Bonjour,
je ne sais pas si cela t'aidera, mais voici un tuto de CodeMonkey pour dessiner en jeu.

Répondre

Revenir vers « Scripting »