02-04-2024, 08:53 PM
Hi st,
So this little example shows an image on a 3D square (2 triangles)
The image does appear upside down, this is all about the texture coordinates. I can't see a definative definition, but if we look at https://learn.microsoft.com/en-us/dotnet...oordinates
We see:
This suggests that 3D coordinate -1,-1,0 is mapped to image 0,1 and 1,1,0 is mapped to 1,0.
Therefore in the Y direction (up down) -1 maps to 1 and 1 maps to 0; i.e. inverted - this just looks like a convention, so we should probably change the mapping in code, which then shows image correct way up.
Note that using the pre-defined 3D shapes this has been set up correctly, for example:
So this little example shows an image on a 3D square (2 triangles)
Code:
LDNetwork.SetSSL()
flickr = LDUtilities.FixFlickr()
imageURL = Flickr.GetRandomPicture("Car")
tmpFile = File.GetTemporaryFilePath()
LDNetwork.DownloadFile(tmpFile,imageURL)
image = ImageList.LoadImage(tmpFile)
File.DeleteFile(tmpFile)
view3D = LD3DView.AddView(GraphicsWindow.Width,GraphicsWindow.Height,"True")
LD3DView.AutoControl("True","True",2,1)
LD3DView.AddAmbientLight(view3D,"White")
square = LD3DView.AddGeometry(view3D,"-0.5 -0.5 0.5:0.5 -0.5 0.5:0.5 0.5 0.5:0.5 0.5 0.5:-0.5 0.5 0.5:-0.5 -0.5 0.5","0 1 2 3 4 5","","Red","D")
LD3DView.AddImage(view3D,square,"0 0:1 0:1 1:1 1:0 1:0 0",image,"D")
LD3DView.TranslateGeometry(view3D,square,0,0,8)
The image does appear upside down, this is all about the texture coordinates. I can't see a definative definition, but if we look at https://learn.microsoft.com/en-us/dotnet...oordinates
We see:
Code:
Positions="-1 -1 0 1 -1 0 -1 1 0 1 1 0"
Normals="0 0 1 0 0 1 0 0 1 0 0 1"
TextureCoordinates="0 1 1 1 0 0 1 0 "
TriangleIndices="0 1 2 1 3 2" />
This suggests that 3D coordinate -1,-1,0 is mapped to image 0,1 and 1,1,0 is mapped to 1,0.
Therefore in the Y direction (up down) -1 maps to 1 and 1 maps to 0; i.e. inverted - this just looks like a convention, so we should probably change the mapping in code, which then shows image correct way up.
Code:
LD3DView.AddImage(view3D,square,"0 1:1 1:1 0:1 0:0 0:0 1",image,"D")
Note that using the pre-defined 3D shapes this has been set up correctly, for example:
Code:
LDNetwork.SetSSL()
flickr = LDUtilities.FixFlickr()
imageURL = Flickr.GetRandomPicture("Car")
tmpFile = File.GetTemporaryFilePath()
LDNetwork.DownloadFile(tmpFile,imageURL)
image = ImageList.LoadImage(tmpFile)
File.DeleteFile(tmpFile)
view3D = LD3DView.AddView(GraphicsWindow.Width,GraphicsWindow.Height,"True")
LD3DView.AutoControl("True","True",2,1)
LD3DView.AddAmbientLight(view3D,"White")
'square = LD3DView.AddGeometry(view3D,"-0.5 -0.5 0.5:0.5 -0.5 0.5:0.5 0.5 0.5:0.5 0.5 0.5:-0.5 0.5 0.5:-0.5 -0.5 0.5","0 1 2 3 4 5","","Red","D")
'LD3DView.AddImage(view3D,square,"0 1:1 1:1 0:1 0:0 0:0 1",image,"D")
cube = LD3DView.AddCube(view3D,1,"Red","D")
LD3DView.AddImage(view3D,cube,"",image,"D")
LD3DView.TranslateGeometry(view3D,cube,0,0,8)