Skip to content

adding 1d texture example for grid#139

Open
thomwolf wants to merge 9 commits intomainfrom
fix-textures
Open

adding 1d texture example for grid#139
thomwolf wants to merge 9 commits intomainfrom
fix-textures

Conversation

@thomwolf
Copy link
Member

@thomwolf thomwolf commented Jul 29, 2022

Adding a bit better support for textures and colors.

Typical example to assign a texture as a function of the height of a structured map:

proc_grid = sm.ProcgenGrid(specific_map=specific_map)

# Let's color our grid by height.
# We assign a simple 1D texture to the object and assing mesh texture coordinates from the height of each points of the mesh.
proc_grid.material.base_color_texture = sm.TEXTURE_1D_CMAP  # Set a simple 1D color map texture
height = proc_grid.mesh.points[:, 1, None]  # We get the height coordinates of the mesh points ( theY axis)
texture_coord = np.concatenate(
    [height, np.zeros_like(height)], axis=1
)  # Make texture coordinates (UV) by adding a zeros axis
proc_grid.mesh.active_t_coords = texture_coord  # Assign as point to texture mapping

scene += proc_grid

@thomwolf thomwolf requested a review from aliciafmachado July 29, 2022 13:16
@aliciafmachado
Copy link
Contributor

Changes look fine, but I'm getting some strange results in procgen_grid.py:

image

And it doesn't seem to be working with Unity.

@natolambert
Copy link
Contributor

Anything I can do to support this? I agree that textures will be fun. Let me poke around, as I was looking at a related script for #144

@natolambert
Copy link
Contributor

natolambert commented Aug 3, 2022

This is the color scale we should be getting:

COLORS_NO_GRAYSCALE = {
    "BLUE": BLUE,
    "CYAN": CYAN,
    "GREEN": GREEN,
    "MAGENTA": MAGENTA,
    "OLIVE": OLIVE,
    "PURPLE": PURPLE,
    "RED": RED,
    "TEAL": TEAL,
    "YELLOW": YELLOW,
}

Weird for it to jump from red to green (I was looking to see if one of the colors was mis-defined as blue in between red and green), but also the spacing is off.

For reference, if you take the x-axis, a similar pattern emerges (I think the steep part is hard to see because shadow)
Screen Shot 2022-08-03 at 11 50 14 AM
.

@natolambert
Copy link
Contributor

I'm really going deep on this, a good way to learn. Here's "greyscale" Our colors are definitely not alright
Screen Shot 2022-08-03 at 2 56 39 PM
.

@natolambert
Copy link
Contributor

@dylanebert mentioned it may be a gltf encoding issue, so I tried to export the scene and was given a cryptic warning and no output.

 2022-08-03 15:29:38.973 ( 128.648s) [           13DD4]       vtkPNGWriter.cxx:213   WARN| vtkPNGWriter (0x15eceb300): PNGWriter only supports unsigned char and unsigned short inputs

This may be a better thing for someone other than me to fix then, I'm a gltf noob.

@thomwolf
Copy link
Member Author

thomwolf commented Aug 4, 2022

Let me take a quick look to see if I can help!

@thomwolf
Copy link
Member Author

thomwolf commented Aug 6, 2022

Ok it's working fine now for structuredgrid.

For StructuredGrid and their child classes (procedural generation) I've added a add_texture_cmap_along_axis

The example procgen_grid.py shows three ways to add a cmap texture using this add_texture_cmap_along_axis method.
image
image
image

@aliciafmachado
Copy link
Contributor

Not working on my side: https://pastebin.com/zq5mAQq6
It seems like it has something to do with the show function in the pyvista engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants