通过子集全脸顶点和索引数据在 R 中绘制面部表面网格的右半部分时遇到错误

Error encountered while plotting right half of facial surface mesh in R by subsetting full face vertices and indices data

我有人脸的顶点和索引数据 here. I have a 一年前根据这些数据绘制 3D 面部表面网格。现在,我只想绘制右半边和面部中部的顶点,而忽略左侧的顶点。根据我之前的情节,我尝试了以下代码:

library(tidyverse)
library(readxl)
library(rgl)

vb <- read_excel("...\vb.xlsx", sheet = "Sheet1", col_names = F)
it <- read_excel("...\it.xlsx", sheet = "Sheet1", col_names = F)

# Extract vertices for the right side
lm_right_ind <- which(vb[,1] < 0)
vb_mat_right <- t(vb[lm_right_ind, ])
vb_mat_right <- rbind(vb_mat_right, 1)
rownames(vb_mat_right) <- c("xpts", "ypts", "zpts", "")
vertices1_right <- c(vb_mat_right)

# Extract `it` whose rows do not contain vertices on the left side
# Left-side vertices have vb[,1] greater than 0
lm_left_ind <- which(vb[,1] > 0)

leftContain <- NULL

for (i in 1: dim(it)[1]) {
   if (T %in% (it[i,] %in% lm_left_ind)) {
          leftContain[i] <- i
    } else {leftContain[i] <- NA}
}

leftContain <- leftContain[!is.na(leftContain)]
# Remove indices that involve left-side vertices
it_rightMid <- it[-leftContain,]

it_mat_right <- t(as.matrix(it_rightMid))
rownames(it_mat_right) <- NULL

indices_right <- c(it_mat_right)

# Plot
try1_right <- tmesh3d(vertices = vertices1_right, indices = indices_right, homogeneous = TRUE, 
             material = NULL, normals = NULL, texcoords = NULL)

# Use addNormals to smooth the plot. See my Whosebug question:
# 
try12_right <- addNormals(try1_right)

shade3d(try12_right, col="#add9ec", specular = "#202020", alpha = 0.8)

我在尝试获取 try12_right 时遇到错误: Error in v[, it[3, i]] : subscript out of bounds.

我做的和我之前的情节完全一样,但为什么这里出了问题?谢谢。

下面是一个使用裁剪平面从网格对象左侧切出的示例:

library(rgl)
open3d()
root <- currentSubscene3d()
newSubscene3d("inherit", "inherit", "inherit", parent = root) # Clipping limited to this subscene
shade3d(addNormals(subdivision3d(icosahedron3d(), 2)), col = "pink")
clipplanes3d(a = 1, b = 0, c = 0, d = 0)
useSubscene3d(root)
decorate3d()

对子场景的摆弄将剪裁限制为仅阴影球体,而不是图片中的所有其他内容。

这会产生以下输出:

没有别的就简单了:

library(rgl)
open3d()
shade3d(addNormals(subdivision3d(icosahedron3d(), 2)), col = "pink")
clipplanes3d(a = 1, b = 0, c = 0, d = 0)

产生