+2 votes

The source is here: https://github.com/imekon/godot-unofficial-demo-projects-v3, in the project mesh.

The main.gd file has this:

extends Spatial

onready var meshInstance = $Mesh

var angle = 0

func _ready():
    var material = SpatialMaterial.new()
    material.albedo_color = Color(1.0, 0.0, 0.0)
    createMesh(10, material)

func createMesh(size, material):
    var surfaceTool = SurfaceTool.new()

    surfaceTool.add_normal(Vector3(    0,     0,  1))

    surfaceTool.add_vertex(Vector3(-size, -size,  0))
    surfaceTool.add_vertex(Vector3( size,  size,  0))
    surfaceTool.add_vertex(Vector3( size, -size,  0))
    surfaceTool.add_vertex(Vector3(-size, -size,  0))
    surfaceTool.add_vertex(Vector3(-size,  size,  0))
    surfaceTool.add_vertex(Vector3( size,  size,  0))

    var mesh = surfaceTool.commit()
    meshInstance.mesh = mesh
    meshInstance.set_surface_material(0, material)

func _process(delta):
    angle += delta * 30
    meshInstance.rotation_degrees = Vector3(0, 0, angle)

It creates a white surface not red, and I'm not clear why.

in Engine by (259 points)

I can see red rectangle is rotating with your test code.
I'm testing with custom build v3.1.dev.dd4e593
would you try it with 3.0.1-official?

2 Answers

0 votes
material.albedo_color = Color(1.0, 0.0, 0.0, **1.0**)

Miss alpha channel. Test it

by (18 points)
edited by
+3 votes

I had the same problem until now - This works for me (Godot 3.0.2-stable)

var material = SpatialMaterial.new()
material.albedo_color = Color(0.8, 0.0, 0.0)
var st = SurfaceTool.new()
st.add_vertex(Vector3(5, 0, 0))
st.add_vertex(Vector3(0, 5, 0))
st.add_vertex(Vector3(5, 5, 0))
var mesh = Mesh.new()
var mesh_inst = MeshInstance.new()
mesh_inst.mesh = mesh

Mind, that you FIRST have to state SurfaceTool.begin(), and THEN SurfaceTool.set_material()
In this tutorial, they switched the lines (maybe worked in previous versions?)

by (20 points)
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 Frequently asked questions and 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 [email protected] with your username.