浏览代码

Merge pull request #413 from marynate/PR-decouple-skeleton-mesh

Add 'mesh/skeleton' property to MeshInstance
reduz 11 年之前
父节点
当前提交
91e88f4b96
共有 3 个文件被更改,包括 42 次插入4 次删除
  1. 33 2
      scene/3d/mesh_instance.cpp
  2. 6 1
      scene/3d/mesh_instance.h
  3. 3 1
      scene/3d/visual_instance.cpp

+ 33 - 2
scene/3d/mesh_instance.cpp

@@ -113,6 +113,27 @@ Ref<Mesh> MeshInstance::get_mesh() const {
 	return mesh;
 	return mesh;
 }
 }
 
 
+void MeshInstance::_resolve_skeleton_path(){
+
+	if (skeleton_path.is_empty())
+		return;
+
+	Skeleton *skeleton=get_node(skeleton_path)?get_node(skeleton_path)->cast_to<Skeleton>():NULL;
+	if (skeleton)
+		VisualServer::get_singleton()->instance_attach_skeleton( get_instance(), skeleton->get_skeleton() );
+}
+
+void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) {
+
+	skeleton_path = p_skeleton;
+	if (!is_inside_scene())
+		return;
+	_resolve_skeleton_path();
+}
+
+NodePath MeshInstance::get_skeleton_path() {
+	return skeleton_path;
+}
 
 
 AABB MeshInstance::get_aabb() const {
 AABB MeshInstance::get_aabb() const {
 
 
@@ -192,22 +213,32 @@ void MeshInstance::create_convex_collision() {
 
 
 }
 }
 
 
+void MeshInstance::_notification(int p_what) {
+
+	if (p_what==NOTIFICATION_ENTER_SCENE) {
+		_resolve_skeleton_path();
+	}
+}
+
+
 void MeshInstance::_bind_methods() {
 void MeshInstance::_bind_methods() {
 	
 	
 	ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh);
 	ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh);
 	ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MeshInstance::get_mesh);
 	ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MeshInstance::get_mesh);
+	ObjectTypeDB::bind_method(_MD("set_skeleton_path","skeleton_path:NodePath"),&MeshInstance::set_skeleton_path);
+	ObjectTypeDB::bind_method(_MD("get_skeleton_path:NodePath"),&MeshInstance::get_skeleton_path);
 	ObjectTypeDB::bind_method(_MD("get_aabb"),&MeshInstance::get_aabb);
 	ObjectTypeDB::bind_method(_MD("get_aabb"),&MeshInstance::get_aabb);
 	ObjectTypeDB::bind_method(_MD("create_trimesh_collision"),&MeshInstance::create_trimesh_collision);
 	ObjectTypeDB::bind_method(_MD("create_trimesh_collision"),&MeshInstance::create_trimesh_collision);
 	ObjectTypeDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
 	ObjectTypeDB::set_method_flags("MeshInstance","create_trimesh_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
 	ObjectTypeDB::bind_method(_MD("create_convex_collision"),&MeshInstance::create_convex_collision);
 	ObjectTypeDB::bind_method(_MD("create_convex_collision"),&MeshInstance::create_convex_collision);
 	ObjectTypeDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
 	ObjectTypeDB::set_method_flags("MeshInstance","create_convex_collision",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR);
 	ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "mesh/mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh" ), _SCS("set_mesh"), _SCS("get_mesh"));
 	ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "mesh/mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh" ), _SCS("set_mesh"), _SCS("get_mesh"));
-	
-	
+	ADD_PROPERTY( PropertyInfo (Variant::NODE_PATH, "mesh/skeleton"), _SCS("set_skeleton_path"), _SCS("get_skeleton_path"));
 }
 }
 
 
 MeshInstance::MeshInstance()
 MeshInstance::MeshInstance()
 {
 {
+	skeleton_path=NodePath("..");
 }
 }
 
 
 
 

+ 6 - 1
scene/3d/mesh_instance.h

@@ -40,6 +40,7 @@ class MeshInstance : public GeometryInstance {
 	OBJ_TYPE( MeshInstance, GeometryInstance );
 	OBJ_TYPE( MeshInstance, GeometryInstance );
 	
 	
 	Ref<Mesh> mesh;
 	Ref<Mesh> mesh;
+	NodePath skeleton_path;
 
 
 	struct MorphTrack {
 	struct MorphTrack {
 
 
@@ -50,6 +51,7 @@ class MeshInstance : public GeometryInstance {
 
 
 	Map<StringName,MorphTrack> morph_tracks;
 	Map<StringName,MorphTrack> morph_tracks;
 
 
+	void _resolve_skeleton_path();
 
 
 protected:
 protected:
 
 
@@ -57,12 +59,15 @@ protected:
 	bool _get(const StringName& p_name,Variant &r_ret) const;
 	bool _get(const StringName& p_name,Variant &r_ret) const;
 	void _get_property_list( List<PropertyInfo> *p_list) const;
 	void _get_property_list( List<PropertyInfo> *p_list) const;
 
 
-	
+	void _notification(int p_what);
 	static void _bind_methods();
 	static void _bind_methods();
 public:
 public:
 
 
 	void set_mesh(const Ref<Mesh>& p_mesh);
 	void set_mesh(const Ref<Mesh>& p_mesh);
 	Ref<Mesh> get_mesh() const;
 	Ref<Mesh> get_mesh() const;
+
+	void set_skeleton_path(const NodePath& p_skeleton);
+	NodePath get_skeleton_path();
 	
 	
 	Node* create_trimesh_collision_node();
 	Node* create_trimesh_collision_node();
 	void create_trimesh_collision();
 	void create_trimesh_collision();

+ 3 - 1
scene/3d/visual_instance.cpp

@@ -65,10 +65,12 @@ void VisualInstance::_notification(int p_what) {
 
 
 				VisualServer::get_singleton()->instance_set_room(instance,room->get_instance());
 				VisualServer::get_singleton()->instance_set_room(instance,room->get_instance());
 			}
 			}
-			// CHECK SKELETON
+			// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
+			/*
 			Skeleton *skeleton=get_parent()?get_parent()->cast_to<Skeleton>():NULL;
 			Skeleton *skeleton=get_parent()?get_parent()->cast_to<Skeleton>():NULL;
 			if (skeleton)
 			if (skeleton)
 				VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
 				VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
+			*/
 
 
 			VisualServer::get_singleton()->instance_set_scenario( instance, get_world()->get_scenario() );
 			VisualServer::get_singleton()->instance_set_scenario( instance, get_world()->get_scenario() );