0 votes

Im creating a voxel block and every time I set a texture it just produces a black square but if I set a colour without a texture it renders the colour, any help on how to resolve this, thank you.

here is the code`
extends Spatial

export (Resource) onready var defaulttexture
var mesh = Mesh.new()
var mat = SpatialMaterial.new()
var color = Color(0.0, 1, 0.0)
var index = 0
var UVs = PoolVector2Array(
[Vector2(0,0),#0 Done
Vector2(1,0),#1 Done
Vector2(1,1),#2 Done
Vector2(0,1),#3 Done
Vector2(1,0),#4 Done
Vector2(0,0),#5 Done
Vector2(1,1),#6 Done
Vector2(0,0)#7 Done
]
)
var voxel
verts = PoolVector3Array( [
Vector3(0,0,0),#0
Vector3(1,0,0),#1
Vector3(1,1,0),#2
Vector3(0,1,0),#3
Vector3(0,0,-1),#4
Vector3(1,0,-1),#5
Vector3(1,1,-1),#6
Vector3(0,1,-1)#7
] )
var voxel_tris = [
0,3,1,1,3,2]

func _ready():

mat.albedo_color = color
mat.set_texture(0,default_texture)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.set_material(mat)

for v in voxel_tris.size():
        index = v
        st.add_color(color)

        st.add_vertex(voxel_verts[voxel_tris[index]])
        st.generate_normals()
        st.add_uv(UVs[voxel_tris[index]])
st.commit(mesh)

$MeshInstance.mesh = mesh

`

Godot version 3.2.3
in Engine by (153 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.