function te_pose(bmw) {
let v1 = (_.find(bmw, { desc: 'Head'}))
let v2 = (_.find(bmw, { desc: 'Clavicles'}))
let v = parametricPointVector(v1, v2, 0.544)
Object.assign(v1, {...v})
let bones = draw_order.map( (joint) => {
const joint0 = bmw.find((item) => item.desc === equilivants[joint[0]] )
const joint1 = bmw.find((item) => item.desc === equilivants[joint[1]])
const boneColour = joint[2]
return {x0:joint0.x, y0:joint0.y, z0:joint0.z, desc0:joint0.desc,
x1:joint1.x, y1:joint1.y, z1:joint1.z, desc1:joint1.desc,
bone_colour: boneColour , type: 'bone'}
})
let joints = _.uniq(_.flattenDeep(draw_order))
.filter((el) => !el.startsWith('#'))
.map(joint_name => {
let joint = _.find(bmw, {desc:equilivants[joint_name]})
return {x0:joint.x, y0:joint.y, z0:joint.z,
jointColour:jointColour[_.findKey(equilivants, (value) => value === joint.desc)],
type:'joint',
desc:joint.desc }
})
let whereB = _.findIndex(bones, obj => obj.desc0 === obj.desc1);
let off_x = (bones[whereB].x0 - scaledHead.nose.x) // work out nose, eyes and ears offset.
let off_y = (bones[whereB].y0 - scaledHead.nose.y) // bmwalker x,y - pose default x,y
bones[whereB].x0 = scaledHead.nose.x + off_x
bones[whereB].y0 = scaledHead.nose.y + off_y
bones[whereB].z0 += scaledHead.nose.z
bones[whereB].jc0 = scaledHead.nose.jc
bones[whereB].desc0 = "nose"
bones[whereB].x1 = scaledHead.right_eye.x + off_x
bones[whereB].y1 = scaledHead.right_eye.y + off_y
bones[whereB].z1 = scaledHead.right_eye.z
bones[whereB].jc1 = scaledHead.right_eye.jc
bones[whereB].desc1 = "right_eye"
bones[whereB].bone_colour = "#330099"
// nose
let whereJ = _.findIndex(joints, obj => obj.desc === 'Head')
joints[whereJ].jointColour = jointColour.nose
joints[whereJ].x0 = bones[whereB].x0
joints[whereJ].y0 = bones[whereB].y0
joints[whereJ].z0 += scaledHead.nose.z
joints[whereJ].desc = "nose"
// right eye
whereJ = _.findIndex(joints, obj => obj.desc === 'Head')
joints[whereJ].jointColour = jointColour.right_eye
joints[whereJ].x0 = bones[whereB].x1
joints[whereJ].y0 = bones[whereB].y1
joints[whereJ].z0 = scaledHead.right_eye.z
joints[whereJ].desc = "right_eye"
//--- Right Ear * dup name
whereB = _.findIndex(bones, obj => obj.desc0 === obj.desc1)
bones[whereB].x0 = scaledHead.right_eye.x + off_x
bones[whereB].y0 = scaledHead.right_eye.y + off_y
bones[whereB].z0 = scaledHead.right_eye.z
bones[whereB].jc0 = scaledHead.right_eye.jc
bones[whereB].desc0 = "right_eye"
bones[whereB].x1 = scaledHead.right_ear.x + off_x
bones[whereB].y1 = scaledHead.right_ear.y + off_y
bones[whereB].z1 = scaledHead.right_ear.z
bones[whereB].jc1 = scaledHead.right_ear.jc
bones[whereB].desc1 = "right_ear"
bones[whereB].bone_colour = "#660099"
// right ear
whereJ = _.findIndex(joints, obj => obj.desc === 'Head')
joints[whereJ].jointColour = jointColour.right_ear
joints[whereJ].x0 = bones[whereB].x1
joints[whereJ].y0 = bones[whereB].y1
joints[whereJ].z0 = bones[whereB].z1
joints[whereJ].desc = "right_ear"
//--- Left Eyebrow
whereB = _.findIndex(bones, obj => obj.desc0 === obj.desc1)
bones[whereB].x0 = scaledHead.nose.x + off_x
bones[whereB].y0 = scaledHead.nose.y + off_y
bones[whereB].z0 = scaledHead.nose.z
bones[whereB].jc0 = scaledHead.nose.jc
bones[whereB].desc0 = "nose"
bones[whereB].x1 = scaledHead.left_eye.x + off_x
bones[whereB].y1 = scaledHead.left_eye.y + off_y
bones[whereB].z1 = scaledHead.left_eye.z
bones[whereB].jc1 = scaledHead.left_eye.jc
bones[whereB].desc1 = "left_eye"
bones[whereB].bone_colour = "#990099"
// left eye
whereJ = _.findIndex(joints, obj => obj.desc === 'Head');
joints[whereJ].jointColour = jointColour.left_eye
joints[whereJ].x0 = bones[whereB].x1
joints[whereJ].y0 = bones[whereB].y1
joints[whereJ].z0 = bones[whereB].z1
joints[whereJ].desc = "left_eye"
//--- Left Ear * dup name
whereB = _.findIndex(bones, obj => obj.desc0 === obj.desc1);
bones[whereB].x0 = scaledHead.left_eye.x + off_x
bones[whereB].y0 = scaledHead.left_eye.y + off_y
bones[whereB].z0 = scaledHead.left_eye.z
bones[whereB].jc0 = scaledHead.left_eye.jc
bones[whereB].desc0 = "left_eye"
bones[whereB].x1 = scaledHead.left_ear.x + off_x
bones[whereB].y1 = scaledHead.left_ear.y + off_y
bones[whereB].z1 = scaledHead.left_ear.z
bones[whereB].jc1 = scaledHead.left_ear.jc
bones[whereB].desc1 = "left_ear"
bones[whereB].bone_colour = "#990066"
// left ear
whereJ = _.findIndex(joints, obj => obj.desc === 'Head');
joints[whereJ].jointColour = jointColour.left_ear
joints[whereJ].x0 = bones[whereB].x1
joints[whereJ].y0 = bones[whereB].y1
joints[whereJ].z0 = bones[whereB].z1
joints[whereJ].desc = "left_ear"
let them_bones = [...bones,...joints]
return _.orderBy(them_bones, [ (obj) => _.min([obj.z0, obj.z1 !== undefined ? obj.z1 : obj.z0])]); // sort the bones by depth
}