Fix flex textures for 3D grids.
Fixes #2013. PiperOrigin-RevId: 728673726 Change-Id: Idb2b6bf9e5392576d0b09f3e71dbea6f4636ae81
This commit is contained in:
committed by
Copybara-Service
parent
7f3bb062c3
commit
6a86247810
@@ -3011,6 +3011,7 @@ struct mjvSceneState_ {
|
||||
mjtNum* flex_node;
|
||||
mjtNum* flex_radius;
|
||||
float* flex_rgba;
|
||||
float* flex_texcoord;
|
||||
|
||||
int* hfield_pathadr;
|
||||
|
||||
|
||||
@@ -537,6 +537,7 @@ struct mjvSceneState_ {
|
||||
mjtNum* flex_node;
|
||||
mjtNum* flex_radius;
|
||||
float* flex_rgba;
|
||||
float* flex_texcoord;
|
||||
|
||||
int* hfield_pathadr;
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@
|
||||
XMJV( int, flex_bvhadr, nflex, 1 ) \
|
||||
XMJV( int, flex_bvhnum, nflex, 1 ) \
|
||||
XMJV( float, flex_rgba, nflex, 4 ) \
|
||||
X ( float, flex_texcoord, nflextexcoord, 2 ) \
|
||||
XMJV( float, flex_texcoord, nflextexcoord, 2 ) \
|
||||
X ( int, mesh_vertadr, nmesh, 1 ) \
|
||||
X ( int, mesh_vertnum, nmesh, 1 ) \
|
||||
X ( int, mesh_normaladr, nmesh, 1 ) \
|
||||
|
||||
@@ -7734,6 +7734,13 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
||||
),
|
||||
doc='',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='flex_texcoord',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='float'),
|
||||
),
|
||||
doc='',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='hfield_pathadr',
|
||||
type=PointerType(
|
||||
|
||||
@@ -597,7 +597,7 @@ int mjCFlexcomp::GridID(int ix, int iy, int iz) {
|
||||
// make grid
|
||||
bool mjCFlexcomp::MakeGrid(char* error, int error_sz) {
|
||||
int dim = def.Flex().spec.dim;
|
||||
bool hastex = texcoord.empty();
|
||||
bool needtex = texcoord.empty() && mjs_getString(def.spec.flex->material)[0];
|
||||
|
||||
// 1D
|
||||
if (dim == 1) {
|
||||
@@ -646,7 +646,7 @@ bool mjCFlexcomp::MakeGrid(char* error, int error_sz) {
|
||||
point.push_back(0);
|
||||
|
||||
// add texture coordinates, if not specified explicitly
|
||||
if (!hastex) {
|
||||
if (needtex) {
|
||||
texcoord.push_back(ix/(double)std::max(count[0]-1, 1));
|
||||
texcoord.push_back(iy/(double)std::max(count[1]-1, 1));
|
||||
}
|
||||
@@ -690,6 +690,12 @@ bool mjCFlexcomp::MakeGrid(char* error, int error_sz) {
|
||||
point.push_back(spacing[1]*(iy - 0.5*(count[1]-1)));
|
||||
point.push_back(spacing[2]*(iz - 0.5*(count[2]-1)));
|
||||
|
||||
// add texture coordinates, if not specified explicitly
|
||||
if (needtex) {
|
||||
texcoord.push_back(ix/(float)std::max(count[0]-1, 1));
|
||||
texcoord.push_back(iy/(float)std::max(count[1]-1, 1));
|
||||
}
|
||||
|
||||
// add elements
|
||||
if (ix < count[0]-1 && iy < count[1]-1 && iz < count[2]-1) {
|
||||
int vert[8] = {
|
||||
@@ -834,7 +840,7 @@ bool mjCFlexcomp::MakeSquare(char* error, int error_sz) {
|
||||
// make 3d box, ellipsoid or cylinder
|
||||
bool mjCFlexcomp::MakeBox(char* error, int error_sz) {
|
||||
double pos[3];
|
||||
bool needtex = texcoord.empty() && !std::string(mjs_getString(def.spec.flex->material)).empty();
|
||||
bool needtex = texcoord.empty() && mjs_getString(def.spec.flex->material)[0];
|
||||
|
||||
// set 3D
|
||||
def.spec.flex->dim = 3;
|
||||
|
||||
@@ -6338,6 +6338,7 @@ public unsafe struct model {
|
||||
public double* flex_node;
|
||||
public double* flex_radius;
|
||||
public float* flex_rgba;
|
||||
public float* flex_texcoord;
|
||||
public int* hfield_pathadr;
|
||||
public int* mesh_bvhadr;
|
||||
public int* mesh_bvhnum;
|
||||
|
||||
Reference in New Issue
Block a user