Copy face_ into facetexcoord_ if not specified and needed.

PiperOrigin-RevId: 601732448
Change-Id: Iffe01076db22201dba2611ea36174f808ae00c1e
This commit is contained in:
Alessio Quaglino
2024-01-26 04:53:37 -08:00
committed by Copybara-Service
parent 4f53d9a0d7
commit 076db5d366
2 changed files with 87 additions and 13 deletions
+12
View File
@@ -463,6 +463,12 @@ void mjCMesh::Compile(const mjVFS* vfs) {
throw mjCError(this, "texcoord must be a multiple of 2");
}
// check size if no face texcoord indices are given
if (usertexcoord_.size() != 2*nvert_ && userfacetexcoord_.empty()) {
throw mjCError(this,
"texcoord must be 2*nv if face texcoord indices are not provided in an OBJ file");
}
// copy from user
ntexcoord_ = (int)usertexcoord_.size()/2;
texcoord_ = VecToArray(usertexcoord_, !file_.empty());
@@ -570,6 +576,12 @@ void mjCMesh::Compile(const mjVFS* vfs) {
facetexcoord_ = VecToArray(userfacetexcoord_, !file_.empty());
}
// no facetexcoord: copy from faces
if (!facetexcoord_ && texcoord_) {
facetexcoord_ = (int*) mju_malloc(3*nface_*sizeof(int));
memcpy(facetexcoord_, face_, 3*nface_*sizeof(int));
}
// facenormal might not exist if usernormal was specified
if (!facenormal_) {
facenormal_ = (int*) mju_malloc(3*nface_*sizeof(int));