Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing solid 3D uvw textures #3627

Closed
danlooo opened this issue Feb 13, 2024 · 6 comments
Closed

Drawing solid 3D uvw textures #3627

danlooo opened this issue Feb 13, 2024 · 6 comments
Labels
feature request GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.

Comments

@danlooo
Copy link

danlooo commented Feb 13, 2024

Hello,

The texture of a mesh can be expressed as a 3D solid. For example, the OBJ file format allows having uvw coordinates besides of 2D uv ones. This is useful e.g. in complex meshes having a surface that can't be easily wrapped to a 2D texture uv plane.

Providing the texture as a Vector works. Seems that if I use a Matrix, the w coordinate is ignored. Using a 3D array results in an eror. Do I need to flatten a uvw texture into a vector with element order matching to those in msh.uv of mesh msh ?

using MeshIO, Downloads, FileIO, GLMakie

file = Downloads.download("https://raw.githubusercontent.com/JuliaIO/MeshIO.jl/master/test/testfiles/cube_uvw.obj", "shape.obj")
msh = load(file)

mesh(msh; color=1:8) # Vector works
mesh(msh; color=reshape(1:9, (3,3))) # Matrix works
mesh(msh; color=reshape(1:8, (2,2,2)))

The last command results in error

Error showing value of type Makie.FigureAxisPlot:
ERROR: MethodError: no method matching GLMakie.GLAbstraction.GLBuffer(::Array{Float32, 3})

Closest candidates are:
  GLMakie.GLAbstraction.GLBuffer(::Type{T}, ::Int64; buffertype, usage) where T<:Union{Real, ColorTypes.Colorant, StaticArraysCore.StaticArray{Tuple{N}, T, 1} where {N, T}}
   @ GLMakie ~/.julia/packages/GLMakie/yNddL/src/GLAbstraction/GLBuffer.jl:93
  GLMakie.GLAbstraction.GLBuffer(::GLMakie.GLAbstraction.GLBuffer)
   @ GLMakie ~/.julia/packages/GLMakie/yNddL/src/GLAbstraction/GLBuffer.jl:76
  GLMakie.GLAbstraction.GLBuffer(::DenseVector{T}; buffertype, usage) where T<:Union{Real, ColorTypes.Colorant, StaticArraysCore.StaticArray{Tuple{N}, T, 1} where {N, T}}
   @ GLMakie ~/.julia/packages/GLMakie/yNddL/src/GLAbstraction/GLBuffer.jl:52
  ...

with Mesh

julia> msh.uv
8-element Vector{Vec{3, Float32}}:
 [0.0, 0.0, 0.0]
 [1.0, 0.0, 0.0]
 [0.0, 1.0, 0.0]
 [0.0, 0.0, 1.0]
 [1.0, 1.0, 0.0]
 [0.0, 1.0, 1.0]
 [1.0, 0.0, 1.0]
 [1.0, 1.0, 1.0]

@SimonDanisch
Copy link
Member

I started this PR to support 3d arrays, but run out of time for tests + clean up:
#2274

@danlooo
Copy link
Author

danlooo commented Feb 13, 2024

@SimonDanisch thanks very much :) I'll look at the code and see if I can add some tests...

@danlooo
Copy link
Author

danlooo commented Feb 14, 2024

I could not find any other uvw examples besides the cube above I created manually. Seems thats uvw is not very popular. Mostly used to store pre-computed shading. If we set vt to just the positions v, we have a identity uvw map for sanity checks of the shader code:

mtllib cube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000

vt 1.000000 -1.000000 -1.000000
vt 1.000000 -1.000000 1.000000
vt -1.000000 -1.000000 1.000000
vt -1.000000 -1.000000 -1.000000
vt 1.000000 1.000000 -0.999999
vt 0.999999 1.000000 1.000001
vt -1.000000 1.000000 1.000000
vt -1.000000 1.000000 -1.000000

usemtl Material
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8

@ffreyer ffreyer added GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie. feature request labels Aug 27, 2024
@ffreyer
Copy link
Collaborator

ffreyer commented Feb 12, 2025

Can this be closed?

@asinghvi17
Copy link
Member

Mostly - the mesh uv interpolation seems to work, but I'm not sure how the uv coordinates relate to the data that's passed in. A volume plot seems to indicate something fishy is going on...will post a youtube link in a bit.

@asinghvi17
Copy link
Member

@danlooo danlooo closed this as completed Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request GLMakie This relates to GLMakie.jl, the OpenGL backend for Makie. WGLMakie This relates to WGLMakie.jl, the Web-based WebGL backend for Makie.
Projects
None yet
Development

No branches or pull requests

4 participants