Skip to content

Commit

Permalink
Add base support for 2D meshes in Godot, including Sprite -> Mesh2D c…
Browse files Browse the repository at this point in the history
…onversion.
  • Loading branch information
reduz committed Feb 21, 2018
1 parent 1c77fdc commit 9e3a1e5
Show file tree
Hide file tree
Showing 23 changed files with 6,114 additions and 67 deletions.
1 change: 1 addition & 0 deletions core/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ thirdparty_sources = [
"md5.cpp",
"pcg.cpp",
"triangulator.cpp",
"clipper.cpp",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env.add_source_files(env.core_sources, thirdparty_sources)
Expand Down
2 changes: 2 additions & 0 deletions core/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,8 @@ Variant::operator Vector3() const {

if (type == VECTOR3)
return *reinterpret_cast<const Vector3 *>(_data._mem);
else if (type == VECTOR2)
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
else
return Vector3();
}
Expand Down
40 changes: 40 additions & 0 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ void RasterizerCanvasGLES3::_draw_gui_primitive(int p_points, const Vector2 *p_v
storage->frame.canvas_draw_commands++;
}

static const GLenum gl_primitive[] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
GL_LINE_LOOP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN
};

void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip) {

int cc = p_item->commands.size();
Expand Down Expand Up @@ -735,6 +745,36 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
#endif

} break;
case Item::Command::TYPE_MESH: {

Item::CommandMesh *mesh = static_cast<Item::CommandMesh *>(c);
_set_texture_rect_mode(false);

RasterizerStorageGLES3::Texture *texture = _bind_canvas_texture(mesh->texture, mesh->normal_map);

if (texture) {
Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height);
state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size);
}

RasterizerStorageGLES3::Mesh *mesh_data = storage->mesh_owner.getornull(mesh->mesh);
if (mesh_data) {

for (int j = 0; j < mesh_data->surfaces.size(); j++) {
RasterizerStorageGLES3::Surface *s = mesh_data->surfaces[j];
// materials are ignored in 2D meshes, could be added but many things (ie, lighting mode, reading from screen, etc) would break as they are not meant be set up at this point of drawing
glBindVertexArray(s->array_id);

if (s->index_array_len) {
glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
} else {
glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
}

glBindVertexArray(0);
}
}
} break;
case Item::Command::TYPE_PARTICLES: {

Item::CommandParticles *particles_cmd = static_cast<Item::CommandParticles *>(c);
Expand Down
4 changes: 3 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#include "editor/plugins/shader_editor_plugin.h"
#include "editor/plugins/shader_graph_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/plugins/sprite_editor_plugin.h"
#include "editor/plugins/sprite_frames_editor_plugin.h"
#include "editor/plugins/style_box_editor_plugin.h"
#include "editor/plugins/texture_editor_plugin.h"
Expand Down Expand Up @@ -5671,6 +5672,7 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(AnimationTreeEditorPlugin(this)));
add_editor_plugin(memnew(MeshLibraryEditorPlugin(this)));
add_editor_plugin(memnew(StyleBoxEditorPlugin(this)));
add_editor_plugin(memnew(SpriteEditorPlugin(this)));
add_editor_plugin(memnew(ParticlesEditorPlugin(this)));
add_editor_plugin(memnew(ResourcePreloaderEditorPlugin(this)));
add_editor_plugin(memnew(ItemListEditorPlugin(this)));
Expand All @@ -5693,7 +5695,7 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this)));
add_editor_plugin(memnew(CurveEditorPlugin(this)));
add_editor_plugin(memnew(TextureEditorPlugin(this)));
add_editor_plugin(memnew(MeshEditorPlugin(this)));
add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor)));

This comment has been minimized.

Copy link
@groud

groud Feb 21, 2018

Member

There's two AudioBusesEditorPlugin now ?

add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor)));
add_editor_plugin(memnew(NavigationMeshEditorPlugin(this)));

Expand Down
Loading

0 comments on commit 9e3a1e5

Please sign in to comment.