mirror of
https://github.com/godotengine/godot.git
synced 2024-11-23 12:43:43 +00:00
Improved Blender/Collada -colonly import creating collision shapes for empties
This commit is contained in:
parent
a0ac4293c1
commit
494847f0d1
@ -482,6 +482,24 @@ Transform Collada::_read_transform(XMLParser& parser) {
|
||||
return _read_transform_from_array(array);
|
||||
}
|
||||
|
||||
String Collada::_read_empty_draw_type(XMLParser& parser) {
|
||||
|
||||
String empty_draw_type = "";
|
||||
|
||||
if (parser.is_empty())
|
||||
return empty_draw_type;
|
||||
|
||||
while (parser.read()==OK) {
|
||||
if (parser.get_node_type() == XMLParser::NODE_TEXT) {
|
||||
empty_draw_type = parser.get_node_data();
|
||||
}
|
||||
else
|
||||
if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END)
|
||||
break; // end parsing text
|
||||
}
|
||||
return empty_draw_type;
|
||||
}
|
||||
|
||||
Variant Collada::_parse_param(XMLParser& parser) {
|
||||
|
||||
if (parser.is_empty())
|
||||
@ -1664,6 +1682,8 @@ Collada::Node* Collada::_parse_visual_scene_node(XMLParser& parser) {
|
||||
|
||||
Vector<Node::XForm> xform_list;
|
||||
Vector<Node*> children;
|
||||
|
||||
String empty_draw_type="";
|
||||
|
||||
Node *node=NULL;
|
||||
|
||||
@ -1771,7 +1791,9 @@ Collada::Node* Collada::_parse_visual_scene_node(XMLParser& parser) {
|
||||
|
||||
xform_list.push_back(xf);
|
||||
|
||||
} else if (section=="technique" || section=="extra") {
|
||||
} else if (section=="empty_draw_type") {
|
||||
empty_draw_type = _read_empty_draw_type(parser);
|
||||
} else if (section == "technique" || section=="extra") {
|
||||
|
||||
} else if (section!="node") {
|
||||
//usually what defines the type of node
|
||||
@ -1817,6 +1839,7 @@ Collada::Node* Collada::_parse_visual_scene_node(XMLParser& parser) {
|
||||
|
||||
node->name=name;
|
||||
node->id=id;
|
||||
node->empty_draw_type=empty_draw_type;
|
||||
|
||||
if (node->children.size()==1) {
|
||||
if (node->children[0]->noname && !node->noname) {
|
||||
|
@ -403,6 +403,7 @@ public:
|
||||
|
||||
String name;
|
||||
String id;
|
||||
String empty_draw_type;
|
||||
bool noname;
|
||||
Vector<XForm> xform_list;
|
||||
Transform default_transform;
|
||||
@ -635,6 +636,7 @@ private: // private stuff
|
||||
Vector<float> _read_float_array(XMLParser& parser);
|
||||
Vector<String> _read_string_array(XMLParser& parser);
|
||||
Transform _read_transform(XMLParser& parser);
|
||||
String _read_empty_draw_type(XMLParser& parser);
|
||||
|
||||
void _joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner);
|
||||
void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton=NULL);
|
||||
|
@ -355,6 +355,10 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
|
||||
p_parent->add_child(node);
|
||||
node->set_owner(scene);
|
||||
|
||||
if (p_node->empty_draw_type!="") {
|
||||
node->set_meta("empty_draw_type", Variant(p_node->empty_draw_type));
|
||||
}
|
||||
|
||||
for(int i=0;i<p_node->children.size();i++) {
|
||||
|
||||
Error err = _create_scene(p_node->children[i],node);
|
||||
|
@ -41,6 +41,10 @@
|
||||
#include "scene/3d/physics_body.h"
|
||||
#include "scene/3d/portal.h"
|
||||
#include "scene/3d/vehicle_body.h"
|
||||
#include "scene/resources/sphere_shape.h"
|
||||
#include <scene/resources/box_shape.h>
|
||||
#include <scene/resources/ray_shape.h>
|
||||
#include <scene/resources/plane_shape.h>
|
||||
#include "tools/editor/create_dialog.h"
|
||||
#include "os/os.h"
|
||||
|
||||
@ -1685,28 +1689,61 @@ Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>
|
||||
mi->set_baked_light_texture_id(layer);
|
||||
}
|
||||
|
||||
if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(name,"colonly") && p_node->cast_to<MeshInstance>()) {
|
||||
if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(name,"colonly")) {
|
||||
|
||||
if (isroot)
|
||||
return p_node;
|
||||
|
||||
if (p_node->cast_to<MeshInstance>()) {
|
||||
MeshInstance *mi = p_node->cast_to<MeshInstance>();
|
||||
Node * col = mi->create_trimesh_collision_node();
|
||||
ERR_FAIL_COND_V(!col,NULL);
|
||||
|
||||
MeshInstance *mi = p_node->cast_to<MeshInstance>();
|
||||
Node * col = mi->create_trimesh_collision_node();
|
||||
ERR_FAIL_COND_V(!col,NULL);
|
||||
|
||||
col->set_name(_fixstr(name,"colonly"));
|
||||
col->cast_to<Spatial>()->set_transform(mi->get_transform());
|
||||
p_node->replace_by(col);
|
||||
memdelete(p_node);
|
||||
p_node=col;
|
||||
|
||||
StaticBody *sb = col->cast_to<StaticBody>();
|
||||
CollisionShape *colshape = memnew( CollisionShape);
|
||||
colshape->set_shape(sb->get_shape(0));
|
||||
colshape->set_name("shape");
|
||||
sb->add_child(colshape);
|
||||
colshape->set_owner(p_node->get_owner());
|
||||
col->set_name(_fixstr(name,"colonly"));
|
||||
col->cast_to<Spatial>()->set_transform(mi->get_transform());
|
||||
p_node->replace_by(col);
|
||||
memdelete(p_node);
|
||||
p_node=col;
|
||||
|
||||
StaticBody *sb = col->cast_to<StaticBody>();
|
||||
CollisionShape *colshape = memnew( CollisionShape);
|
||||
colshape->set_shape(sb->get_shape(0));
|
||||
colshape->set_name("shape");
|
||||
sb->add_child(colshape);
|
||||
colshape->set_owner(p_node->get_owner());
|
||||
} else if (p_node->has_meta("empty_draw_type")) {
|
||||
String empty_draw_type = String(p_node->get_meta("empty_draw_type"));
|
||||
print_line(empty_draw_type);
|
||||
StaticBody *sb = memnew( StaticBody);
|
||||
sb->set_name(_fixstr(name,"colonly"));
|
||||
sb->cast_to<Spatial>()->set_transform(p_node->cast_to<Spatial>()->get_transform());
|
||||
p_node->replace_by(sb);
|
||||
memdelete(p_node);
|
||||
CollisionShape *colshape = memnew( CollisionShape);
|
||||
if (empty_draw_type == "CUBE") {
|
||||
BoxShape *boxShape = memnew( BoxShape);
|
||||
boxShape->set_extents(Vector3(1, 1, 1));
|
||||
colshape->set_shape(boxShape);
|
||||
colshape->set_name("BoxShape");
|
||||
} else if (empty_draw_type == "SINGLE_ARROW") {
|
||||
RayShape *rayShape = memnew( RayShape);
|
||||
rayShape->set_length(1);
|
||||
colshape->set_shape(rayShape);
|
||||
colshape->set_name("RayShape");
|
||||
sb->cast_to<Spatial>()->rotate_x(Math_PI / 2);
|
||||
} else if (empty_draw_type == "IMAGE") {
|
||||
PlaneShape *planeShape = memnew( PlaneShape);
|
||||
colshape->set_shape(planeShape);
|
||||
colshape->set_name("PlaneShape");
|
||||
} else {
|
||||
SphereShape *sphereShape = memnew( SphereShape);
|
||||
sphereShape->set_radius(1);
|
||||
colshape->set_shape(sphereShape);
|
||||
colshape->set_name("SphereShape");
|
||||
}
|
||||
sb->add_child(colshape);
|
||||
colshape->set_owner(sb->get_owner());
|
||||
}
|
||||
|
||||
} else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS &&_teststr(name,"col") && p_node->cast_to<MeshInstance>()) {
|
||||
|
||||
|
@ -1104,6 +1104,14 @@ class DaeExporter:
|
||||
|
||||
self.writel(S_NODES,il,'<instance_light url="#'+lightid+'"/>')
|
||||
|
||||
def export_empty_node(self,node,il):
|
||||
|
||||
self.writel(S_NODES,4,'<extra>')
|
||||
self.writel(S_NODES,5,'<technique profile="GODOT">')
|
||||
self.writel(S_NODES,6,'<empty_draw_type>'+node.empty_draw_type+'</empty_draw_type>')
|
||||
self.writel(S_NODES,5,'</technique>')
|
||||
self.writel(S_NODES,4,'</extra>')
|
||||
|
||||
|
||||
def export_curve(self,curve):
|
||||
|
||||
@ -1264,6 +1272,8 @@ class DaeExporter:
|
||||
self.export_camera_node(node,il)
|
||||
elif (node.type=="LAMP"):
|
||||
self.export_lamp_node(node,il)
|
||||
elif (node.type=="EMPTY"):
|
||||
self.export_empty_node(node,il)
|
||||
|
||||
for x in node.children:
|
||||
self.export_node(x,il)
|
||||
|
Loading…
Reference in New Issue
Block a user