本文整理汇总了C++中MeshInstance::set_owner方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshInstance::set_owner方法的具体用法?C++ MeshInstance::set_owner怎么用?C++ MeshInstance::set_owner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshInstance
的用法示例。
在下文中一共展示了MeshInstance::set_owner方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memnew
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
List<Ref<Mesh> > meshes;
Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, Vector3(1, 1, 1), r_missing_deps);
if (err != OK) {
if (r_err) {
*r_err = err;
}
return NULL;
}
Spatial *scene = memnew(Spatial);
for (List<Ref<Mesh> >::Element *E = meshes.front(); E; E = E->next()) {
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(E->get());
mi->set_name(E->get()->get_name());
scene->add_child(mi);
mi->set_owner(scene);
}
if (r_err) {
*r_err = OK;
}
return scene;
}
示例2: create_debug_tangents
void MeshInstance::create_debug_tangents() {
Vector<Vector3> lines;
Vector<Color> colors;
Ref<Mesh> mesh = get_mesh();
if (!mesh.is_valid())
return;
for (int i = 0; i < mesh->get_surface_count(); i++) {
Array arrays = mesh->surface_get_arrays(i);
Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
if (norms.size() == 0)
continue;
Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
if (tangents.size() == 0)
continue;
for (int j = 0; j < verts.size(); j++) {
Vector3 v = verts[j];
Vector3 n = norms[j];
Vector3 t = Vector3(tangents[j * 4 + 0], tangents[j * 4 + 1], tangents[j * 4 + 2]);
Vector3 b = (n.cross(t)).normalized() * tangents[j * 4 + 3];
lines.push_back(v); //normal
colors.push_back(Color(0, 0, 1)); //color
lines.push_back(v + n * 0.04); //normal
colors.push_back(Color(0, 0, 1)); //color
lines.push_back(v); //tangent
colors.push_back(Color(1, 0, 0)); //color
lines.push_back(v + t * 0.04); //tangent
colors.push_back(Color(1, 0, 0)); //color
lines.push_back(v); //binormal
colors.push_back(Color(0, 1, 0)); //color
lines.push_back(v + b * 0.04); //binormal
colors.push_back(Color(0, 1, 0)); //color
}
}
if (lines.size()) {
Ref<SpatialMaterial> sm;
sm.instance();
sm->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
sm->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
sm->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
Ref<ArrayMesh> am;
am.instance();
Array a;
a.resize(Mesh::ARRAY_MAX);
a[Mesh::ARRAY_VERTEX] = lines;
a[Mesh::ARRAY_COLOR] = colors;
am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
am->surface_set_material(0, sm);
MeshInstance *mi = memnew(MeshInstance);
mi->set_mesh(am);
mi->set_name("DebugTangents");
add_child(mi);
#ifdef TOOLS_ENABLED
if (this == get_tree()->get_edited_scene_root())
mi->set_owner(this);
else
mi->set_owner(get_owner());
#endif
}
}
示例3: memnew
//.........这里部分代码省略.........
if (what == "off")
surf_tool->add_smooth_group(false);
else
surf_tool->add_smooth_group(true);
} else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh
//groups are too annoying
if (surf_tool->get_vertex_array().size()) {
//another group going on, commit it
if (normals.size() == 0) {
surf_tool->generate_normals();
}
if (generate_tangents && uvs.size()) {
surf_tool->generate_tangents();
}
surf_tool->index();
print_line("current material library " + current_material_library + " has " + itos(material_map.has(current_material_library)));
print_line("current material " + current_material + " has " + itos(material_map.has(current_material_library) && material_map[current_material_library].has(current_material)));
if (material_map.has(current_material_library) && material_map[current_material_library].has(current_material)) {
surf_tool->set_material(material_map[current_material_library][current_material]);
}
mesh = surf_tool->commit(mesh);
if (current_material != String()) {
mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename());
} else if (current_group != String()) {
mesh->surface_set_name(mesh->get_surface_count() - 1, current_group);
}
print_line("Added surface :" + mesh->surface_get_name(mesh->get_surface_count() - 1));
surf_tool->clear();
surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
}
if (l.begins_with("o ") || f->eof_reached()) {
MeshInstance *mi = memnew(MeshInstance);
mi->set_name(name);
mi->set_mesh(mesh);
scene->add_child(mi);
mi->set_owner(scene);
mesh.instance();
current_group = "";
current_material = "";
}
if (f->eof_reached()) {
break;
}
if (l.begins_with("o ")) {
name = l.substr(2, l.length()).strip_edges();
}
if (l.begins_with("usemtl ")) {
current_material = l.replace("usemtl", "").strip_edges();
}
if (l.begins_with("g ")) {
current_group = l.substr(2, l.length()).strip_edges();
}
} else if (l.begins_with("mtllib ")) { //parse material
current_material_library = l.replace("mtllib", "").strip_edges();
if (!material_map.has(current_material_library)) {
Map<String, Ref<SpatialMaterial> > lib;
Error err = _parse_material_library(current_material_library, lib, r_missing_deps);
if (err == ERR_CANT_OPEN) {
String dir = p_path.get_base_dir();
err = _parse_material_library(dir.plus_file(current_material_library), lib, r_missing_deps);
}
if (err == OK) {
material_map[current_material_library] = lib;
}
}
}
}
/*
TODO, check existing materials and merge?
//re-apply materials if exist
for(int i=0;i<mesh->get_surface_count();i++) {
String n = mesh->surface_get_name(i);
if (name_map.has(n))
mesh->surface_set_material(i,name_map[n]);
}
*/
return scene;
}