Skip to content

Commit 38a6eb7

Browse files
authored
Updates for R24.1
1 parent 0dc4b50 commit 38a6eb7

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

xrextras/src/aframe/components/hand-components.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ const handAttachmentComponent: ComponentDefinition = {
8484
},
8585
}
8686

87-
const handMesh = (modelGeometry, material, wireframe) => {
87+
const handMesh = (modelGeometry, material, wireframe, uvOrientation) => {
8888
let handKind = 2
89-
9089
const geometry = new THREE.BufferGeometry()
9190

9291
// Fill geometry with default vertices.
@@ -97,22 +96,15 @@ const handMesh = (modelGeometry, material, wireframe) => {
9796
const normals = new Float32Array(modelGeometry.pointsPerDetection * 3)
9897
geometry.setAttribute('normal', new THREE.BufferAttribute(normals, 3))
9998

100-
// // Add the UVs to the geometry.
101-
// const uvs = new Float32Array(modelGeometry.uvs.length * 2)
102-
// for (let i = 0; i < modelGeometry.uvs.length; ++i) {
103-
// uvs[i * 2] = modelGeometry.uvs[i].u
104-
// uvs[i * 2 + 1] = modelGeometry.uvs[i].v
105-
// }
106-
// geometry.setAttribute('uv', new THREE.BufferAttribute(uvs, 2))
99+
// Create and set UVs based on uvOrientation
107100

108-
// By default, using the right hand indices.
101+
// Instantiate both left and right hand indices as we use them at runtime
109102
const rightIndices = new Array(modelGeometry.rightIndices.length * 3)
110103
for (let i = 0; i < modelGeometry.rightIndices.length; ++i) {
111104
rightIndices[i * 3] = modelGeometry.rightIndices[i].a
112105
rightIndices[i * 3 + 1] = modelGeometry.rightIndices[i].b
113106
rightIndices[i * 3 + 2] = modelGeometry.rightIndices[i].c
114107
}
115-
geometry.setIndex(rightIndices)
116108

117109
const leftIndices = new Array(modelGeometry.leftIndices.length * 3)
118110
for (let i = 0; i < modelGeometry.leftIndices.length; ++i) {
@@ -121,6 +113,31 @@ const handMesh = (modelGeometry, material, wireframe) => {
121113
leftIndices[i * 3 + 2] = modelGeometry.leftIndices[i].c
122114
}
123115

116+
// Construct UVs based on hand mesh orientation
117+
let uv
118+
if (uvOrientation === 'left') {
119+
const leftUvs = new Float32Array(modelGeometry.leftUvs.length * 2)
120+
for (let i = 0; i < modelGeometry.pointsPerDetection; i++) {
121+
leftUvs[2 * i] = modelGeometry.leftUvs[i].u
122+
leftUvs[2 * i + 1] = modelGeometry.leftUvs[i].v
123+
}
124+
const leftUvBuffer = new THREE.BufferAttribute(leftUvs, 2)
125+
126+
uv = leftUvBuffer
127+
geometry.setIndex(leftIndices)
128+
} else if (uvOrientation === 'right') {
129+
const rightUvs = new Float32Array(modelGeometry.rightUvs.length * 2)
130+
for (let i = 0; i < modelGeometry.pointsPerDetection; i++) {
131+
rightUvs[2 * i] = modelGeometry.rightUvs[i].u
132+
rightUvs[2 * i + 1] = modelGeometry.rightUvs[i].v
133+
}
134+
const rightUvBuffer = new THREE.BufferAttribute(rightUvs, 2)
135+
136+
uv = rightUvBuffer
137+
geometry.setIndex(rightIndices)
138+
}
139+
geometry.setAttribute('uv', uv)
140+
124141
if (wireframe) {
125142
material.wireframe = true
126143
}
@@ -174,6 +191,7 @@ const handMeshComponent: ComponentDefinition = {
174191
schema: {
175192
'material-resource': {type: 'string'},
176193
'wireframe': {type: 'boolean', default: false},
194+
'uv-orientation': {type: 'string', default: 'right'},
177195
},
178196
init() {
179197
this.handMesh = null
@@ -191,7 +209,7 @@ const handMeshComponent: ComponentDefinition = {
191209
)
192210
}
193211

194-
this.handMesh = handMesh(detail, material, this.data.wireframe)
212+
this.handMesh = handMesh(detail, material, this.data.wireframe, this.data['uv-orientation'])
195213
this.el.setObject3D('mesh', this.handMesh.mesh)
196214

197215
this.el.emit('model-loaded')
@@ -248,15 +266,15 @@ const handOccluder = (modelGeometry, material, adjustment) => {
248266
rightIndices[i * 3 + 1] = modelGeometry.rightIndices[i].b
249267
rightIndices[i * 3 + 2] = modelGeometry.rightIndices[i].c
250268
}
251-
geometry.setIndex(rightIndices)
252-
253269
const leftIndices = new Array(modelGeometry.leftIndices.length * 3)
254270
for (let i = 0; i < modelGeometry.leftIndices.length; ++i) {
255271
leftIndices[i * 3] = modelGeometry.leftIndices[i].a
256272
leftIndices[i * 3 + 1] = modelGeometry.leftIndices[i].b
257273
leftIndices[i * 3 + 2] = modelGeometry.leftIndices[i].c
258274
}
259275

276+
geometry.setIndex(rightIndices)
277+
260278
const mesh = new THREE.Mesh(geometry, material)
261279

262280
const show = ({detail}) => {

xrextras/src/aframe/xr-primitives.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const xrPrimitives = () => {
215215
mappings: {
216216
'material-resource': 'xrextras-hand-mesh.material-resource',
217217
'wireframe': 'xrextras-hand-mesh.wireframe',
218+
'uv-orientation': 'xrextras-hand-mesh.uv-orientation',
218219
},
219220
}
220221

0 commit comments

Comments
 (0)