Coordinates in 3D

I have imported some images and I’d like to plot points on these images (the images are maps) to draw a path. Is there a way to get coordinates on these images so that I can easily place points on the maps?

You do not know the size of maps?

No, the images have a track on them, I need to place points or objects on these points. I can guess at each of the different coordinates but that would take a long time. Ideally I’d like the program to tell me the coordinates of any area when I mouse over it, similar to the capabilities of matplotlib when graphing 3D

Give an example of a code download maps, and then to determine how it can be done.

If the map is on a flat plane you can use this snippet to find where the mouse ray and plane intersect:

If the map is on a 2d gui element (or something alike) you just need the mouse pointer position in the window and where the frame showing the map is.

If the map is some sort of 3D object then you can either do typical collision detection or some sort of magic with a pixel sized buffer under the cursor.

This is what I’m working with, I need to get the coordinates of specific points on these maps. I’ve tried a few different things but the coordinates seem to be dependent on how close you are to the images. I need the exact coordinates. Any suggestions on what would work best?


How do you upload them? To answer you need to know on the mesh you upload them, or ???

I made a sketch of the code :arrow_right:

import direct.directbase.DirectStart

from panda3d.core import (CollisionTraverser,CollisionNode, 
                          CollisionHandlerQueue,CollisionRay,
                          BitMask32, Vec4, WindowProperties)
                          
from direct.gui.DirectGui import DirectEntry

from direct.directtools.DirectGeometry import LineNodePath

from camera import CamFree
camera_level = CamFree()

cursor = LineNodePath(render, 'up', 4, colorVec = Vec4(0, 1, 0, 1)) 
cursor.drawLines([((0, 0, 0), (0, 0, 1500))])      
cursor.create()

x = DirectEntry(pos = (-base.getAspectRatio()+0.05, 0, 0.9), width = 10, scale=.05, numLines = 1, focus = 0, initialText = "X")
y = DirectEntry(pos = (-base.getAspectRatio()+0.05, 0, 0.8), width = 10, scale=.05, numLines = 1, focus = 0, initialText = "Y")
z = DirectEntry(pos = (-base.getAspectRatio()+0.05, 0, 0.7), width = 10, scale=.05, numLines = 1, focus = 0, initialText = "Z")
  
def scan(task):
    if camera_level.keyMap['Mouse3'] == 0:
        if base.mouseWatcherNode.hasMouse():
            mpos = base.mouseWatcherNode.getMouse() 
            pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())   
            picker.traverse(render)     
            for i in xrange(pickerQ.getNumEntries()): 
                entry = pickerQ.getEntry(i)   
                xyz = entry.getSurfacePoint(render)
                cursor.setPos(xyz)
                if camera_level.keyMap['Mouse1'] == 1:
                    x.set(str(xyz[0]))
                    y.set(str(xyz[1]))
                    z.set(str(xyz[2]))
    return task.cont
            
            
taskMgr.add(scan, 'scan')

# Image size
height = 707
width = 999
            
tex = loader.loadTexture('auto.png')
map = loader.loadModel("map.egg")
map.setTexture(tex, 0)
map.setSy(height)
map.setSx(width)
map.reparentTo(render)

base.camera.setX(-height)
base.camera.setZ(width)
base.camera.lookAt(0, 0, 0)

picker = CollisionTraverser()
pickerQ = CollisionHandlerQueue()  
pickerCollN = CollisionNode('mouseRay')  
pickerCamN = base.camera.attachNewNode(pickerCollN)      
pickerCollN.setFromCollideMask(BitMask32.bit(1))
pickerCollN.setIntoCollideMask(BitMask32.allOff())   
pickerRay = CollisionRay()     
pickerCollN.addSolid(pickerRay)     
picker.addCollider(pickerCamN, pickerQ)

base.run()

You need the image set size. :bulb:

Demo:

Sourse:
GetCoord.7z (163 KB)

Control:
Hold down the right mouse button. Mouse1 - pick.
Move buttons : W - forward , S - backward , A - left , D - right , Q - up , E - down , Shift - Accelerate ,
mouse wheel - speed.

I hope you will be able to move forward. :stuck_out_tongue:

Sorry I’m fairly new to python and panda3d, when I try to implement that into my own code or running your example my python cannot find a camera module. I’ve tried using pip but that isn’t working for me and I’ve been searching for a zip file for it with no luck. Any information on how to get this module would be much appreciated.

Thanks!!

Is there a way to have my maps stacked like the previous picture I posted? I’ve tried stacking them by using setPos but just one layer appears.

They need to ask different setZ()

https://www.panda3d.org/manual/index.php/Common_State_Changes

I have set my Z positions to be different (12, 10, 8, etc.) but it seems as if it produces only one of the maps and every other level disappears. Do I have to change alpha to see the other levels?

You probably downloaded without individual object reference loadModel.

Necessary

map1 = loader.loadModel(“map1.egg”)
map1.setZ(12)

map2 = loader.loadModel(“map2.egg”)
map2.setZ(10)

map3 = loader.loadModel(“map3.egg”)
map3.setZ(8)

The following code is what I’m working with:

HELItex = loader.loadTexture(“out1.png”)
HELImap = loader.loadModel(“map.egg”)
HELImap.setTexture(HELItex, 0)
HELImap.setSy(height)
HELImap.setSx(width)
HELImap.setZ(12)
HELImap.reparentTo(render)

NAVtex = loader.loadTexture(“out2.png”)
NAVmap = loader.loadModel(“map2.egg”)
NAVmap.setTexture(NAVtex, 0)
NAVmap.setSy(height)
NAVmap.setSx(width)
NAVmap.setZ(14)
NAVmap.reparentTo(render)

base.camera.setX(-height)
base.camera.setZ(width)
base.camera.lookAt(0, 0, 0)

m = loader.loadModel(“point.egg”)
m.reparentTo(render)
m.setPos(517, 79, 13)
m.setScale(50, 50, 50)

Too small interval, set 12, 120, 220

Thanks so much, didn’t even think to try different spacing!