We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Point (0,0) in LD3DView image mapping
#2
Hi st,

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)
[-] The following 2 users Like litdev's post:
  • AbsoluteBeginner, stevantosic
Reply


Messages In This Thread
RE: Point (0,0) in LD3DView image mapping - by litdev - 02-04-2024, 08:53 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)