简体   繁体   English

VPython 7 纹理未从自定义目录加载

[英]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做一个小项目VPython 7; Python 3.6 VPython 7; Python 3.6 , where textures need to be applied to my 3D objects. VPython 7; Python 3.6 ,其中纹理需要应用于我的 3D 对象。 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.但是,当我尝试加载纹理时,对象不会出现,直到我将纹理放在Lib\\site packages\\vpython\\vpython_data文件夹中,在那里它被完美加载,没有任何问题。

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让我们用我的纹理 Tex /Tex.jpg调用目录C:\\Project

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.如果纹理是/vpython_data目录,则上述内容将起作用。

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我做了把图片放在 C:\\cabinet.jpg 并执行的实验

box(texture='C:\\cabinet.jpg')盒子(纹理='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不允许加载本地资源:file:///C:/cabinet.jpg

This is related to CORS issues, Cross-origin resource sharing.这与CORS问题,Cross-origin资源共享有关。

On the other hand, it is possible to get an image from a "CORS-enabled" site.另一方面,可以从“启用 CORS”的站点获取图像。 This works:这有效:

box(texture='https://s3.amazonaws.com/glowscript/textures/flower_texture.jpg ')框(纹理='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. PS 最好将 VPython 问题发布到 VPython 论坛,那里的 VPython 用户比看到 stackoverflow 问题的可能性要多得多。

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.如果您在 Jupyter Notebook 中运行它,并且图像所在的目录是 Notebook 所在目录的子目录,那么它将起作用。 For instance if there is an images directory in the same directory as the notebook which contains Tex.jpg file then this will work.例如,如果在包含 Tex.jpg 文件的笔记本所在的同一目录中有一个图像目录,那么这将起作用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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