我正在尝试使用一段简单的代码来呈现三维文字,但却收到错误XMLHttpRequest cannot load file:///Users/<name>/threejs/fonts/helvetiker_regular.typeface.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
var loader = new THREE.FontLoader();
loader.crossOrigin = '';
loader.load( 'fonts/helvetiker_regular.typeface.json', function ( font ) {
// your code here
var material = new THREE.MeshPhongMaterial({
color: 0xdddddd
});
var textGeom = new THREE.TextGeometry( 'Hello World!', {
font: '' // Must be lowercase!
});
var textMesh = new THREE.Mesh( textGeom, material );
scene.add( textMesh );
// Do some optional calculations. This is only if you need to get the
// width of the generated text
textGeom.computeBoundingBox();
textGeom.textWidth = textGeom.boundingBox.max.x - textGeom.boundingBox.min.x;
} );
这似乎是一个普遍的问题,只是通过谷歌搜索,但不明白我的代码有什么不同。
我甚至尝试按照http://blog.andrewray.me/creating-a-3d-font-in-three-js/跟随<script src="your-font.typeface.js"></script>
导入字体,但这对我来说也不起作用。我收到错误elvetiker_regular.typeface.json:1 Uncaught SyntaxError: Unexpected token :
我哪里错了?