简体   繁体   中英

VPython 7 Texture not loading from custom directory

I am working on a small project in VPython 7; Python 3.6 VPython 7; Python 3.6 , where textures need to be applied to my 3D objects. However, when I try loading the texture in, the object does not appear, until I place the texture in the Lib\\site packages\\vpython\\vpython_data folder, where it is loaded perfectly with no problems.

However, for my project, I need it to be in my chosen directory for easy organisation.

Let's call the directory C:\\Project with my texture Tex /Tex.jpg

textures.customTex= {'file':":Tex.jpg"} self.3DObject= sphere(pos=vector(0,0,0),radius = 1, texture=textures.Tex)

The above will work if the texture is the the /vpython_data directory.

However, when I try to load the same texture but in my directory:

textures.customTex= {'file':":C:\\Project\\Tex.jpg"} self.3DObject= sphere(pos=vector(0,0,0),radius = 1, texture=textures.Tex)

The above will not work.

My question is whether there if I am loading it in wrong, or whether there is simply no workaround this problem.

Thank you in advance

I don't quite understand your use of colons, but there is a problem. I did the experiment of putting an image at C:\\cabinet.jpg and executing

box(texture='C:\\cabinet.jpg')

This fails, and if you turn on the browser debugger you'll see this error message:

Not allowed to load local resource: file:///C:/cabinet.jpg

This is related to CORS issues, Cross-origin resource sharing.

On the other hand, it is possible to get an image from a "CORS-enabled" site. This works:

box(texture='https://s3.amazonaws.com/glowscript/textures/flower_texture.jpg ')

Thanks for reporting this, though, as I think I may see a way to make local files work.

Bruce Sherwood

PS It's better to post VPython questions to the VPython forum, where there are many more VPython users than are likely to see stackoverflow questions.

If you are running this in a Jupyter Notebook and the directory where the image exists is a subdirectory of the directory where the notebook is located then it will work. For instance if there is an images directory in the same directory as the notebook which contains Tex.jpg file then this will work.

self.3DObject= sphere(pos=vector(0,0,0),radius = 1, texture="images\\Tex.jpg")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM