42 if isinstance(parentnode, scene.Node)
and isinstance(childnode, scene.Node):
44 parentnode.children.remove(childnode)
45 child_mat = childnode.matrix
46 for child
in childnode.children:
47 if isinstance(child, scene.Node):
48 child.transforms = copy.deepcopy(childnode.transforms) + child.transforms
49 for t
in reversed(childnode.transforms):
50 child.matrix = numpy.dot(t.matrix, child.matrix)
51 parentnode.children.append(child)
52 elif isinstance(child, scene.GeometryNode):
55 for primitive
in child.geometry.primitives:
56 for _input
in primitive.getInputList().getList():
57 if _input[1] ==
"VERTEX":
58 position_ids.add(_input[2][1:])
59 elif _input[1] ==
"NORMAL":
60 normal_ids.add(_input[2][1:])
61 for position_id
in position_ids:
62 child.geometry.sourceById[position_id].data = ((child_mat[:3, :3].astype(
"float64").dot(child.geometry.sourceById[position_id].data.transpose())).transpose() + child_mat[:3, 3]).copy()
63 for normal_id
in normal_ids:
64 child.geometry.sourceById[normal_id].data = (child_mat[:3, :3].astype(
"float64").dot(child.geometry.sourceById[normal_id].data.transpose())).transpose().copy()
65 for primitive
in child.geometry.primitives:
66 primitive._vertex = primitive.sources[
'VERTEX'][0][4].data
67 primitive._normal = primitive.sources[
'NORMAL'][0][4].data
68 parentnode.children.append(child)
72 if isinstance(node, scene.Node):
74 for child
in node.children[:]:
75 if isinstance(child, scene.Node):
76 if child.id
in joints_dict:
84 for child
in node.children:
85 if isinstance(child, scene.Node):
97 node = mesh_.scene.nodes[0]
98 node.transforms = [scene.MatrixTransform(root_offset.copy().reshape(16, 1))] + node.transforms
99 node.matrix = numpy.dot(root_offset, node.matrix)
100 newnode = scene.Node(
"offset_link", children=[node])
101 newnode.xmlnode.set(
"sid",
"offset_link")
102 newnode.transforms = [scene.MatrixTransform(numpy.identity(4, dtype=numpy.float32).reshape(16, 1))]
103 mesh_.scene.nodes = [newnode]
106 joints_dict = dict(joints_)
111 joints_new = copy.deepcopy(joints_)
112 childlink_count = dict()
113 for joint
in joints_:
114 if joint[0]
in childlink_count.keys():
115 childlink_count[joint[0]] += 1
117 childlink_count[joint[0]] = 1
119 for childlinkid, count
in childlink_count.items():
121 parentnode, childnode =
find_parent_node(mesh_.scenes[0].nodes[0], childlinkid)
122 for i
in range(count - 1):
123 parentnode.children.remove(childnode)
124 newnode = scene.Node(childnode.id +
"_addition_null" + str(i), children=[childnode])
125 newnode.xmlnode.set(
"sid", childnode.id +
"_addition_null" + str(i))
126 newnode.transforms = childnode.transforms
127 newnode.matrix = childnode.matrix
128 childnode.transforms = []
129 childnode.matrix = numpy.identity(4, dtype=numpy.float32)
130 parentnode.children.append(newnode)
132 j = [s
for s
in joints_new
if s[0] == childlinkid][0]
133 j[0] +=
"_addition_null" + str(i)
136 if len(mesh_.scene.nodes[0].children) == 1:
137 mesh_.scene.nodes[0].id =
"visual0" 138 mesh_.scene.nodes[0].xmlnode.set(
"sid",
"visual0")
140 node = mesh_.scene.nodes[0]
141 newnode = scene.Node(
"visual0", children=[node])
142 newnode.xmlnode.set(
"sid",
"visual0")
143 mesh_.scene.nodes = [newnode]
144 mesh_.scene.nodes[0].children[0].id =
"base_link" 145 mesh_.scene.nodes[0].children[0].xmlnode.set(
"sid",
"base_link")
146 mesh_.scene.nodes[0].children[0].transforms = [scene.MatrixTransform(numpy.identity(4, dtype=numpy.float32).reshape(16, 1))]
147 mesh_.scene.nodes[0].children[0].matrix = numpy.identity(4, dtype=numpy.float32)
150 joints_[:] = joints_new
def find_parent_node(node, name)
def get_merged(node, joints_dict)
def mergenode_collada(mesh_, joints_, root_offset)
def mergenode(parentnode, childnode)