Skip to content

Commit 15fbe6a

Browse files
author
Roberto De Ioris
authored
Merge pull request #4 from OlafHaag/master
check for existence of joint channel when getting frames
2 parents 615cea1 + cab2474 commit 15fbe6a

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

bvh.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,17 @@ def get_joint_channels_index(self, joint_name):
141141
index += int(joint['CHANNELS'][0])
142142
raise LookupError('joint not found')
143143

144+
def get_joint_channel_index(self, joint, channel):
145+
channels = self.joint_channels(joint)
146+
if channel in channels:
147+
channel_index = channels.index(channel)
148+
else:
149+
channel_index = -1
150+
return channel_index
151+
144152
def frame_joint_channel(self, frame_index, joint, channel, value=None):
145153
joint_index = self.get_joint_channels_index(joint)
146-
channel_index = self.joint_channels(joint).index(channel)
154+
channel_index = self.get_joint_channel_index(joint, channel)
147155
if channel_index == -1 and value is not None:
148156
return value
149157
return float(self.frames[frame_index][joint_index + channel_index])
@@ -152,7 +160,7 @@ def frame_joint_channels(self, frame_index, joint, channels, value=None):
152160
values = []
153161
joint_index = self.get_joint_channels_index(joint)
154162
for channel in channels:
155-
channel_index = self.joint_channels(joint).index(channel)
163+
channel_index = self.get_joint_channel_index(joint, channel)
156164
if channel_index == -1 and value is not None:
157165
values.append(value)
158166
else:
@@ -169,7 +177,7 @@ def frames_joint_channels(self, joint, channels, value=None):
169177
for frame in self.frames:
170178
values = []
171179
for channel in channels:
172-
channel_index = self.joint_channels(joint).index(channel)
180+
channel_index = self.get_joint_channel_index(joint, channel)
173181
if channel_index == -1 and value is not None:
174182
values.append(value)
175183
else:

0 commit comments

Comments
 (0)