mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
-Added proper access to depth texture from shader
-Split Mesh into Mesh (abstrat class) and ArrayMesh, to allow to proper mesh primitives, as well as streamable meshes in the future.
This commit is contained in:
parent
5f5d629c8a
commit
5bf810b5db
@ -747,6 +747,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
|
||||
actions[VS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom";
|
||||
actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv";
|
||||
actions[VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture";
|
||||
actions[VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_buffer";
|
||||
actions[VS::SHADER_SPATIAL].renames["SIDE"] = "side";
|
||||
|
||||
actions[VS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n";
|
||||
|
@ -72,7 +72,7 @@ struct ColladaImport {
|
||||
|
||||
Map<String, NodeMap> node_map; //map from collada node to engine node
|
||||
Map<String, String> node_name_map; //map from collada node to engine node
|
||||
Map<String, Ref<Mesh> > mesh_cache;
|
||||
Map<String, Ref<ArrayMesh> > mesh_cache;
|
||||
Map<String, Ref<Curve3D> > curve_cache;
|
||||
Map<String, Ref<Material> > material_cache;
|
||||
Map<Collada::Node *, Skeleton *> skeleton_map;
|
||||
@ -88,7 +88,7 @@ struct ColladaImport {
|
||||
Error _create_scene(Collada::Node *p_node, Spatial *p_parent);
|
||||
Error _create_resources(Collada::Node *p_node);
|
||||
Error _create_material(const String &p_material);
|
||||
Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes = Vector<Ref<Mesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false);
|
||||
Error _create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes = Vector<Ref<ArrayMesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false);
|
||||
Error load(const String &p_path, int p_flags, bool p_force_make_tangents = false);
|
||||
void _fix_param_animation_tracks();
|
||||
void create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks);
|
||||
@ -591,7 +591,7 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c
|
||||
}
|
||||
}
|
||||
|
||||
Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) {
|
||||
Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) {
|
||||
|
||||
bool local_xform_mirror = p_local_xform.basis.determinant() < 0;
|
||||
|
||||
@ -1530,7 +1530,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
|
||||
String meshid;
|
||||
Transform apply_xform;
|
||||
Vector<int> bone_remap;
|
||||
Vector<Ref<Mesh> > morphs;
|
||||
Vector<Ref<ArrayMesh> > morphs;
|
||||
|
||||
print_line("mesh: " + String(mi->get_name()));
|
||||
|
||||
@ -1621,9 +1621,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
|
||||
|
||||
String meshid = names[i];
|
||||
if (collada.state.mesh_data_map.has(meshid)) {
|
||||
Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh));
|
||||
Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
|
||||
Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<Mesh> >(), true);
|
||||
Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<ArrayMesh> >(), true);
|
||||
ERR_FAIL_COND_V(err, err);
|
||||
|
||||
morphs.push_back(mesh);
|
||||
@ -1648,7 +1648,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
|
||||
meshid = ng->source;
|
||||
}
|
||||
|
||||
Ref<Mesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
if (mesh_cache.has(meshid)) {
|
||||
mesh = mesh_cache[meshid];
|
||||
} else {
|
||||
@ -1656,7 +1656,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
|
||||
//bleh, must ignore invalid
|
||||
|
||||
ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA);
|
||||
mesh = Ref<Mesh>(memnew(Mesh));
|
||||
mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
|
||||
mesh->set_name(meshdata.name);
|
||||
Error err = _create_mesh_surfaces(morphs.size() == 0, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, morph, morphs, false, use_mesh_builtin_materials);
|
||||
|
@ -89,7 +89,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s
|
||||
FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ);
|
||||
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
|
||||
|
||||
Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh));
|
||||
Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
Map<String, Ref<Material> > name_map;
|
||||
|
||||
bool generate_normals = p_options["generate/normals"];
|
||||
|
@ -137,7 +137,7 @@ static String _fixstr(const String &p_what, const String &p_str) {
|
||||
return p_what;
|
||||
}
|
||||
|
||||
Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map) {
|
||||
Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map) {
|
||||
|
||||
// children first..
|
||||
for (int i = 0; i < p_node->get_child_count(); i++) {
|
||||
@ -175,7 +175,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true);
|
||||
if (mi->get_mesh().is_valid()) {
|
||||
|
||||
Ref<Mesh> m = mi->get_mesh();
|
||||
Ref<ArrayMesh> m = mi->get_mesh();
|
||||
for (int i = 0; i < m->get_surface_count(); i++) {
|
||||
|
||||
Ref<SpatialMaterial> fm = m->surface_get_material(i);
|
||||
@ -194,7 +194,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
|
||||
MeshInstance *mi = p_node->cast_to<MeshInstance>();
|
||||
|
||||
Ref<Mesh> m = mi->get_mesh();
|
||||
Ref<ArrayMesh> m = mi->get_mesh();
|
||||
|
||||
if (m.is_valid()) {
|
||||
|
||||
@ -275,7 +275,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
|
||||
if (mi->get_mesh().is_valid()) {
|
||||
|
||||
Ref<Mesh> m = mi->get_mesh();
|
||||
Ref<ArrayMesh> m = mi->get_mesh();
|
||||
for (int i = 0; i < m->get_surface_count(); i++) {
|
||||
|
||||
Ref<SpatialMaterial> fm = m->surface_get_material(i);
|
||||
@ -325,7 +325,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
|
||||
/*if (mi->get_mesh().is_valid()) {
|
||||
|
||||
Ref<Mesh> m = mi->get_mesh();
|
||||
Ref<ArrayMesh> m = mi->get_mesh();
|
||||
for(int i=0;i<m->get_surface_count();i++) {
|
||||
|
||||
Ref<SpatialMaterial> fm = m->surface_get_material(i);
|
||||
@ -477,7 +477,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
|
||||
MeshInstance *mi = p_node->cast_to<MeshInstance>();
|
||||
|
||||
Ref<Mesh> mesh = mi->get_mesh();
|
||||
Ref<ArrayMesh> mesh = mi->get_mesh();
|
||||
ERR_FAIL_COND_V(mesh.is_null(), NULL);
|
||||
NavigationMeshInstance *nmi = memnew(NavigationMeshInstance);
|
||||
|
||||
@ -655,7 +655,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
|
||||
|
||||
MeshInstance *mi = p_node->cast_to<MeshInstance>();
|
||||
|
||||
Ref<Mesh> mesh = mi->get_mesh();
|
||||
Ref<ArrayMesh> mesh = mi->get_mesh();
|
||||
if (!mesh.is_null()) {
|
||||
|
||||
if (_teststr(mesh->get_name(), "col")) {
|
||||
@ -972,7 +972,7 @@ static String _make_extname(const String &p_str) {
|
||||
return ext_name;
|
||||
}
|
||||
|
||||
void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes) {
|
||||
void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes) {
|
||||
|
||||
List<PropertyInfo> pi;
|
||||
|
||||
@ -1005,7 +1005,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
|
||||
}
|
||||
} else {
|
||||
|
||||
Ref<Mesh> mesh = p_node->get(E->get().name);
|
||||
Ref<ArrayMesh> mesh = p_node->get(E->get().name);
|
||||
|
||||
if (mesh.is_valid()) {
|
||||
|
||||
@ -1018,7 +1018,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
|
||||
String ext_name = p_base_path + "." + _make_extname(mesh->get_name()) + ".msh";
|
||||
if (FileAccess::exists(ext_name)) {
|
||||
//if exists, use it
|
||||
Ref<Mesh> existing = ResourceLoader::load(ext_name);
|
||||
Ref<ArrayMesh> existing = ResourceLoader::load(ext_name);
|
||||
p_meshes[mesh] = existing;
|
||||
} else {
|
||||
|
||||
@ -1059,7 +1059,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
|
||||
}
|
||||
|
||||
if (!p_make_meshes) {
|
||||
p_meshes[mesh] = Ref<Mesh>(); //save it anyway, so it won't be checked again
|
||||
p_meshes[mesh] = Ref<ArrayMesh>(); //save it anyway, so it won't be checked again
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1192,7 +1192,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
|
||||
float anim_optimizer_angerr = p_options["animation/optimizer/max_angular_error"];
|
||||
float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"];
|
||||
|
||||
Map<Ref<Mesh>, Ref<Shape> > collision_map;
|
||||
Map<Ref<ArrayMesh>, Ref<Shape> > collision_map;
|
||||
|
||||
scene = _fix_node(scene, scene, collision_map);
|
||||
|
||||
@ -1230,7 +1230,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
|
||||
|
||||
if (external_materials || external_meshes) {
|
||||
Map<Ref<Material>, Ref<Material> > mat_map;
|
||||
Map<Ref<Mesh>, Ref<Mesh> > mesh_map;
|
||||
Map<Ref<ArrayMesh>, Ref<ArrayMesh> > mesh_map;
|
||||
_make_external_resources(scene, p_source_file.get_basename(), external_materials, external_meshes, mat_map, mesh_map);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include "io/resource_import.h"
|
||||
#include "scene/resources/animation.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/shape.h"
|
||||
|
||||
class Material;
|
||||
@ -100,9 +101,9 @@ public:
|
||||
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
|
||||
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
|
||||
|
||||
void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes);
|
||||
void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes);
|
||||
|
||||
Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map);
|
||||
Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map);
|
||||
|
||||
void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all);
|
||||
void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep);
|
||||
|
@ -3055,8 +3055,8 @@ void SpatialEditor::_init_indicators() {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
move_gizmo[i] = Ref<Mesh>(memnew(Mesh));
|
||||
rotate_gizmo[i] = Ref<Mesh>(memnew(Mesh));
|
||||
move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
|
||||
Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
|
||||
mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
|
@ -330,13 +330,13 @@ private:
|
||||
bool grid_enable[3]; //should be always visible if true
|
||||
bool grid_enabled;
|
||||
|
||||
Ref<Mesh> move_gizmo[3], rotate_gizmo[3];
|
||||
Ref<ArrayMesh> move_gizmo[3], rotate_gizmo[3];
|
||||
Ref<SpatialMaterial> gizmo_color[3];
|
||||
Ref<SpatialMaterial> gizmo_hl;
|
||||
|
||||
int over_gizmo_handle;
|
||||
|
||||
Ref<Mesh> selection_box;
|
||||
Ref<ArrayMesh> selection_box;
|
||||
RID indicators;
|
||||
RID indicators_instance;
|
||||
RID cursor_mesh;
|
||||
@ -472,8 +472,8 @@ public:
|
||||
float get_rotate_snap() const { return snap_rotate->get_text().to_double(); }
|
||||
float get_scale_snap() const { return snap_scale->get_text().to_double(); }
|
||||
|
||||
Ref<Mesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
|
||||
Ref<Mesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
|
||||
Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
|
||||
Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
|
||||
|
||||
void update_transform_gizmo();
|
||||
|
||||
|
@ -79,7 +79,7 @@ void EditorSpatialGizmo::Instance::create_instance(Spatial *p_base) {
|
||||
VS::get_singleton()->instance_set_layer_mask(instance, 1 << SpatialEditorViewport::GIZMO_EDIT_LAYER); //gizmos are 26
|
||||
}
|
||||
|
||||
void EditorSpatialGizmo::add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard, const RID &p_skeleton) {
|
||||
void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const RID &p_skeleton) {
|
||||
|
||||
ERR_FAIL_COND(!spatial_node);
|
||||
Instance ins;
|
||||
@ -100,7 +100,7 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat
|
||||
ERR_FAIL_COND(!spatial_node);
|
||||
Instance ins;
|
||||
|
||||
Ref<Mesh> mesh = memnew(Mesh);
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
Array a;
|
||||
a.resize(Mesh::ARRAY_MAX);
|
||||
|
||||
@ -162,7 +162,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material,
|
||||
uv.push_back(Vector2(0, 1));
|
||||
uv.push_back(Vector2(1, 1));
|
||||
|
||||
Ref<Mesh> mesh = memnew(Mesh);
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
Array a;
|
||||
a.resize(Mesh::ARRAY_MAX);
|
||||
a[Mesh::ARRAY_VERTEX] = vs;
|
||||
@ -219,7 +219,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
|
||||
ERR_FAIL_COND(!spatial_node);
|
||||
Instance ins;
|
||||
|
||||
Ref<Mesh> mesh = memnew(Mesh);
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
#if 1
|
||||
|
||||
Array a;
|
||||
@ -1029,7 +1029,7 @@ CameraSpatialGizmo::CameraSpatialGizmo(Camera *p_camera) {
|
||||
|
||||
void MeshInstanceSpatialGizmo::redraw() {
|
||||
|
||||
Ref<Mesh> m = mesh->get_mesh();
|
||||
Ref<ArrayMesh> m = mesh->get_mesh();
|
||||
if (!m.is_valid())
|
||||
return; //none
|
||||
|
||||
@ -1248,7 +1248,7 @@ void SkeletonSpatialGizmo::redraw() {
|
||||
*/
|
||||
}
|
||||
|
||||
Ref<Mesh> m = surface_tool->commit();
|
||||
Ref<ArrayMesh> m = surface_tool->commit();
|
||||
add_mesh(m, false, skel->get_skeleton());
|
||||
}
|
||||
|
||||
@ -2511,7 +2511,7 @@ void NavigationMeshSpatialGizmo::redraw() {
|
||||
if (lines.size())
|
||||
add_lines(lines, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_edge_material : SpatialEditorGizmos::singleton->navmesh_edge_material_disabled);
|
||||
add_collision_triangles(tmesh);
|
||||
Ref<Mesh> m = memnew(Mesh);
|
||||
Ref<ArrayMesh> m = memnew(ArrayMesh);
|
||||
Array a;
|
||||
a.resize(Mesh::ARRAY_MAX);
|
||||
a[0] = tmeshfaces;
|
||||
@ -3213,7 +3213,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
|
||||
|
||||
//position 3D Shared mesh
|
||||
|
||||
pos3d_mesh = Ref<Mesh>(memnew(Mesh));
|
||||
pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
{
|
||||
|
||||
PoolVector<Vector3> cursor_points;
|
||||
@ -3246,7 +3246,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() {
|
||||
pos3d_mesh->surface_set_material(0, mat);
|
||||
}
|
||||
|
||||
listener_line_mesh = Ref<Mesh>(memnew(Mesh));
|
||||
listener_line_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
{
|
||||
|
||||
PoolVector<Vector3> cursor_points;
|
||||
|
@ -59,7 +59,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo {
|
||||
struct Instance {
|
||||
|
||||
RID instance;
|
||||
Ref<Mesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
RID skeleton;
|
||||
bool billboard;
|
||||
bool unscaled;
|
||||
@ -97,7 +97,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo {
|
||||
|
||||
protected:
|
||||
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false);
|
||||
void add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID());
|
||||
void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID());
|
||||
void add_collision_segments(const Vector<Vector3> &p_lines);
|
||||
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
|
||||
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1);
|
||||
@ -454,8 +454,8 @@ public:
|
||||
Ref<SpatialMaterial> shape_material;
|
||||
Ref<Texture> handle_t;
|
||||
|
||||
Ref<Mesh> pos3d_mesh;
|
||||
Ref<Mesh> listener_line_mesh;
|
||||
Ref<ArrayMesh> pos3d_mesh;
|
||||
Ref<ArrayMesh> listener_line_mesh;
|
||||
static SpatialEditorGizmos *singleton;
|
||||
|
||||
Ref<TriangleMesh> test_cube_tm;
|
||||
|
@ -973,7 +973,7 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater
|
||||
return mc;
|
||||
}
|
||||
|
||||
void GIProbe::_plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
|
||||
void GIProbe::_plot_mesh(const Transform &p_xform, Ref<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) {
|
||||
|
||||
for (int i = 0; i < p_mesh->get_surface_count(); i++) {
|
||||
|
||||
@ -1067,7 +1067,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
|
||||
|
||||
MeshInstance *mi = p_at_node->cast_to<MeshInstance>();
|
||||
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) {
|
||||
Ref<Mesh> mesh = mi->get_mesh();
|
||||
Ref<ArrayMesh> mesh = mi->get_mesh();
|
||||
if (mesh.is_valid()) {
|
||||
|
||||
Rect3 aabb = mesh->get_aabb();
|
||||
@ -1094,7 +1094,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
|
||||
for (int i = 0; i < meshes.size(); i += 2) {
|
||||
|
||||
Transform mxf = meshes[i];
|
||||
Ref<Mesh> mesh = meshes[i + 1];
|
||||
Ref<ArrayMesh> mesh = meshes[i + 1];
|
||||
if (!mesh.is_valid())
|
||||
continue;
|
||||
|
||||
@ -1317,7 +1317,7 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) {
|
||||
print_line("leaf voxels: " + itos(p_baker->leaf_voxel_count));
|
||||
mm->set_instance_count(p_baker->leaf_voxel_count);
|
||||
|
||||
Ref<Mesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
mesh.instance();
|
||||
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ private:
|
||||
struct PlotMesh {
|
||||
Ref<Material> override_material;
|
||||
Vector<Ref<Material> > instance_materials;
|
||||
Ref<Mesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
Transform local_xform;
|
||||
};
|
||||
|
||||
@ -173,7 +173,7 @@ private:
|
||||
Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color);
|
||||
Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker);
|
||||
void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const Rect3 &p_aabb, Baker *p_baker);
|
||||
void _plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);
|
||||
void _plot_mesh(const Transform &p_xform, Ref<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material);
|
||||
void _find_meshes(Node *p_at_node, Baker *p_baker);
|
||||
void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker);
|
||||
|
||||
|
@ -152,7 +152,7 @@ bool Listener::_can_gizmo_scale() const {
|
||||
}
|
||||
|
||||
RES Listener::_get_gizmo_geometry() const {
|
||||
Ref<Mesh> mesh = memnew(Mesh);
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
|
||||
}
|
||||
}
|
||||
|
||||
debug_mesh = Ref<Mesh>(memnew(Mesh));
|
||||
debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
|
||||
Array arr;
|
||||
arr.resize(Mesh::ARRAY_MAX);
|
||||
|
@ -44,7 +44,7 @@ class NavigationMesh : public Resource {
|
||||
Vector<int> indices;
|
||||
};
|
||||
Vector<Polygon> polygons;
|
||||
Ref<Mesh> debug_mesh;
|
||||
Ref<ArrayMesh> debug_mesh;
|
||||
|
||||
struct _EdgeKey {
|
||||
|
||||
|
@ -266,7 +266,7 @@ void RayCast::_create_debug_shape() {
|
||||
line_material->set_albedo(Color(1.0, 0.8, 0.6));
|
||||
}
|
||||
|
||||
Ref<Mesh> mesh = memnew(Mesh);
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
|
||||
MeshInstance *mi = memnew(MeshInstance);
|
||||
mi->set_mesh(mesh);
|
||||
@ -287,7 +287,7 @@ void RayCast::_update_debug_shape() {
|
||||
if (!mi->get_mesh().is_valid())
|
||||
return;
|
||||
|
||||
Ref<Mesh> mesh = mi->get_mesh();
|
||||
Ref<ArrayMesh> mesh = mi->get_mesh();
|
||||
if (mesh->get_surface_count() > 0)
|
||||
mesh->surface_remove(0);
|
||||
|
||||
|
@ -839,12 +839,12 @@ Ref<Material> SceneTree::get_debug_collision_material() {
|
||||
return collision_material;
|
||||
}
|
||||
|
||||
Ref<Mesh> SceneTree::get_debug_contact_mesh() {
|
||||
Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
|
||||
|
||||
if (debug_contact_mesh.is_valid())
|
||||
return debug_contact_mesh;
|
||||
|
||||
debug_contact_mesh = Ref<Mesh>(memnew(Mesh));
|
||||
debug_contact_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
|
||||
Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
|
||||
/*mat->set_flag(Material::FLAG_UNSHADED,true);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "io/networked_multiplayer_peer.h"
|
||||
#include "os/main_loop.h"
|
||||
#include "os/thread_safe.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/resources/world.h"
|
||||
#include "scene/resources/world_2d.h"
|
||||
#include "self_list.h"
|
||||
@ -169,7 +170,7 @@ private:
|
||||
Color debug_collision_contact_color;
|
||||
Color debug_navigation_color;
|
||||
Color debug_navigation_disabled_color;
|
||||
Ref<Mesh> debug_contact_mesh;
|
||||
Ref<ArrayMesh> debug_contact_mesh;
|
||||
Ref<Material> navigation_material;
|
||||
Ref<Material> navigation_disabled_material;
|
||||
Ref<Material> collision_material;
|
||||
@ -406,7 +407,7 @@ public:
|
||||
Ref<Material> get_debug_navigation_material();
|
||||
Ref<Material> get_debug_navigation_disabled_material();
|
||||
Ref<Material> get_debug_collision_material();
|
||||
Ref<Mesh> get_debug_contact_mesh();
|
||||
Ref<ArrayMesh> get_debug_contact_mesh();
|
||||
|
||||
int get_collision_debug_contact_count() { return collision_debug_contacts; }
|
||||
|
||||
|
@ -523,11 +523,12 @@ void register_scene_types() {
|
||||
ClassDB::register_virtual_class<Shader>();
|
||||
|
||||
#ifndef _3D_DISABLED
|
||||
ClassDB::register_class<Mesh>();
|
||||
ClassDB::register_class<QuadMesh>();
|
||||
ClassDB::register_virtual_class<Mesh>();
|
||||
ClassDB::register_class<ArrayMesh>();
|
||||
ClassDB::register_virtual_class<Material>();
|
||||
ClassDB::register_class<SpatialMaterial>();
|
||||
ClassDB::add_compatibility_class("FixedSpatialMaterial", "SpatialMaterial");
|
||||
ClassDB::add_compatibility_class("Mesh", "ArrayMesh");
|
||||
SceneTree::add_idle_callback(SpatialMaterial::flush_changes);
|
||||
SpatialMaterial::init_shaders();
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,10 +38,13 @@
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
class Mesh : public Resource {
|
||||
|
||||
class Mesh : public Resource {
|
||||
GDCLASS(Mesh, Resource);
|
||||
RES_BASE_EXTENSION("msh");
|
||||
|
||||
mutable Ref<TriangleMesh> triangle_mesh; //cached
|
||||
protected:
|
||||
void _clear_triangle_mesh();
|
||||
|
||||
public:
|
||||
enum {
|
||||
@ -111,6 +114,34 @@ public:
|
||||
BLEND_SHAPE_MODE_RELATIVE = VS::BLEND_SHAPE_MODE_RELATIVE,
|
||||
};
|
||||
|
||||
virtual int get_surface_count() const = 0;
|
||||
virtual int surface_get_array_len(int p_idx) const = 0;
|
||||
virtual int surface_get_array_index_len(int p_idx) const = 0;
|
||||
virtual Array surface_get_arrays(int p_surface) const = 0;
|
||||
virtual uint32_t surface_get_format(int p_idx) const = 0;
|
||||
virtual PrimitiveType surface_get_primitive_type(int p_idx) const = 0;
|
||||
virtual Ref<Material> surface_get_material(int p_idx) const = 0;
|
||||
virtual int get_blend_shape_count() const = 0;
|
||||
virtual StringName get_blend_shape_name(int p_index) const = 0;
|
||||
|
||||
PoolVector<Face3> get_faces() const;
|
||||
Ref<TriangleMesh> generate_triangle_mesh() const;
|
||||
|
||||
Ref<Shape> create_trimesh_shape() const;
|
||||
Ref<Shape> create_convex_shape() const;
|
||||
|
||||
Ref<Mesh> create_outline(float p_margin) const;
|
||||
|
||||
virtual Rect3 get_aabb() const = 0;
|
||||
|
||||
Mesh();
|
||||
};
|
||||
|
||||
class ArrayMesh : public Mesh {
|
||||
|
||||
GDCLASS(ArrayMesh, Mesh);
|
||||
RES_BASE_EXTENSION("msh");
|
||||
|
||||
private:
|
||||
struct Surface {
|
||||
String name;
|
||||
@ -124,8 +155,6 @@ private:
|
||||
Vector<StringName> blend_shapes;
|
||||
Rect3 custom_aabb;
|
||||
|
||||
mutable Ref<TriangleMesh> triangle_mesh;
|
||||
|
||||
void _recompute_aabb();
|
||||
|
||||
protected:
|
||||
@ -177,21 +206,15 @@ public:
|
||||
Rect3 get_aabb() const;
|
||||
virtual RID get_rid() const;
|
||||
|
||||
Ref<Shape> create_trimesh_shape() const;
|
||||
Ref<Shape> create_convex_shape() const;
|
||||
|
||||
Ref<Mesh> create_outline(float p_margin) const;
|
||||
|
||||
void center_geometry();
|
||||
void regen_normalmaps();
|
||||
|
||||
PoolVector<Face3> get_faces() const;
|
||||
Ref<TriangleMesh> generate_triangle_mesh() const;
|
||||
Mesh();
|
||||
ArrayMesh();
|
||||
|
||||
~Mesh();
|
||||
~ArrayMesh();
|
||||
};
|
||||
|
||||
#if 0
|
||||
class QuadMesh : public Mesh {
|
||||
|
||||
GDCLASS(QuadMesh, Mesh)
|
||||
@ -206,6 +229,8 @@ public:
|
||||
QuadMesh();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
VARIANT_ENUM_CAST(Mesh::ArrayType);
|
||||
VARIANT_ENUM_CAST(Mesh::PrimitiveType);
|
||||
VARIANT_ENUM_CAST(Mesh::BlendShapeMode);
|
||||
|
@ -38,7 +38,7 @@ void MeshDataTool::clear() {
|
||||
format = 0;
|
||||
}
|
||||
|
||||
Error MeshDataTool::create_from_surface(const Ref<Mesh> &p_mesh, int p_surface) {
|
||||
Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface) {
|
||||
|
||||
ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
||||
@ -179,7 +179,7 @@ Error MeshDataTool::create_from_surface(const Ref<Mesh> &p_mesh, int p_surface)
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error MeshDataTool::commit_to_surface(const Ref<Mesh> &p_mesh) {
|
||||
Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
|
||||
|
||||
ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER);
|
||||
Array arr;
|
||||
@ -309,7 +309,7 @@ Error MeshDataTool::commit_to_surface(const Ref<Mesh> &p_mesh) {
|
||||
if (w.size())
|
||||
arr[Mesh::ARRAY_WEIGHTS] = w;
|
||||
|
||||
Ref<Mesh> ncmesh = p_mesh;
|
||||
Ref<ArrayMesh> ncmesh = p_mesh;
|
||||
int sc = ncmesh->get_surface_count();
|
||||
ncmesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr);
|
||||
ncmesh->surface_set_material(sc, material);
|
||||
|
@ -78,8 +78,8 @@ protected:
|
||||
|
||||
public:
|
||||
void clear();
|
||||
Error create_from_surface(const Ref<Mesh> &p_mesh, int p_surface);
|
||||
Error commit_to_surface(const Ref<Mesh> &p_mesh);
|
||||
Error create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface);
|
||||
Error commit_to_surface(const Ref<ArrayMesh> &p_mesh);
|
||||
|
||||
int get_format() const;
|
||||
|
||||
|
@ -49,14 +49,14 @@ void Shape::add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Mesh> Shape::get_debug_mesh() {
|
||||
Ref<ArrayMesh> Shape::get_debug_mesh() {
|
||||
|
||||
if (debug_mesh_cache.is_valid())
|
||||
return debug_mesh_cache;
|
||||
|
||||
Vector<Vector3> lines = _gen_debug_mesh_lines();
|
||||
|
||||
debug_mesh_cache = Ref<Mesh>(memnew(Mesh));
|
||||
debug_mesh_cache = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
|
||||
if (!lines.empty()) {
|
||||
//make mesh
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define SHAPE_H
|
||||
|
||||
#include "resource.h"
|
||||
class Mesh;
|
||||
class ArrayMesh;
|
||||
|
||||
class Shape : public Resource {
|
||||
|
||||
@ -40,7 +40,7 @@ class Shape : public Resource {
|
||||
RES_BASE_EXTENSION("shp");
|
||||
RID shape;
|
||||
|
||||
Ref<Mesh> debug_mesh_cache;
|
||||
Ref<ArrayMesh> debug_mesh_cache;
|
||||
|
||||
protected:
|
||||
_FORCE_INLINE_ RID get_shape() const { return shape; }
|
||||
@ -50,7 +50,7 @@ protected:
|
||||
public:
|
||||
virtual RID get_rid() const { return shape; }
|
||||
|
||||
Ref<Mesh> get_debug_mesh();
|
||||
Ref<ArrayMesh> get_debug_mesh();
|
||||
|
||||
void add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p_xform);
|
||||
|
||||
|
@ -224,13 +224,13 @@ void SurfaceTool::add_index(int p_index) {
|
||||
index_array.push_back(p_index);
|
||||
}
|
||||
|
||||
Ref<Mesh> SurfaceTool::commit(const Ref<Mesh> &p_existing) {
|
||||
Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing) {
|
||||
|
||||
Ref<Mesh> mesh;
|
||||
Ref<ArrayMesh> mesh;
|
||||
if (p_existing.is_valid())
|
||||
mesh = p_existing;
|
||||
else
|
||||
mesh = Ref<Mesh>(memnew(Mesh));
|
||||
mesh.instance();
|
||||
|
||||
int varr_len = vertex_array.size();
|
||||
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
|
||||
void create_from(const Ref<Mesh> &p_existing, int p_surface);
|
||||
void append_from(const Ref<Mesh> &p_existing, int p_surface, const Transform &p_xform);
|
||||
Ref<Mesh> commit(const Ref<Mesh> &p_existing = Ref<Mesh>());
|
||||
Ref<ArrayMesh> commit(const Ref<ArrayMesh> &p_existing = Ref<ArrayMesh>());
|
||||
|
||||
SurfaceTool();
|
||||
};
|
||||
|
@ -105,6 +105,7 @@ ShaderTypes::ShaderTypes() {
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECIAL"] = ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DISCARD"] = ShaderLanguage::TYPE_BOOL;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DEPTH_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["POINT_COORD"] = ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SIDE"] = ShaderLanguage::TYPE_FLOAT;
|
||||
|
Loading…
Reference in New Issue
Block a user