Aframe API支持曲面图像。然而,除了曲线图像,我想制作弯曲的文字和平面。有人可以帮我解决这个问题吗?
我想我必须创建一个实体,但我不知道必须设置哪些属性。
答案 0 :(得分:2)
我使用https://github.com/mayognaise/aframe-html-shader创建弯曲文字。弯曲文本是一个部分圆柱体,使用repeat: -1 1
在内部渲染材料。
HTML着色器使用HTML为我们创建纹理,我们可以将其用于文本,然后将该纹理应用于圆柱体。不幸的是,我们必须手动应用repeat: -1 1
,因为该选项未公开。粗略的想法......
<!DOCTYPE html>
<html>
<head>
<title>Hello, WebVR! - A-Frame</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/0.6.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-html-shader@0.2.0/dist/aframe-html-shader.min.js">
</head>
<body>
<script>
AFRAME.registerComponent('update-repeat', {
dependencies: ['material'],
init: function () {
var texture = this.el.components.material.material.map;
texture.repeat = new THREE.Vector2(-1, 1);
texture.needsUpdate = true;
}
});
</script>
<div id="texture" style="width: 100%; height: 100%; position: fixed; left: 0; top: 0; z-index: -1; overflow: hidden">
<p style="position: relative; top: 20px; font-size: 72px">HELLO HELLO</p>
<p style="position: relative; top: 20px; font-size: 48px">curvy text</p>
</div>
<a-scene>
<a-entity geometry="primitive: cylinder; radius: 2; segmentsRadial: 48; thetaLength: -160; openEnded: true"
material="shader: html; target: #texture; side: double; width: 500; height: 300; transparent: true" update-repeat position="0 0 -4" rotation="0 -90 0"></a-entity>
<a-sky color="#FAFAFA"></a-sky>
</a-scene>
</body>
</html>
答案 1 :(得分:0)
只需使用带有src =“#canvas”的a-curvedimage。您可以在画布中生成所需的内容。
<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/1.0.3/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-assets>
<canvas id="myCanvas"></canvas>
</a-assets>
<a-curvedimage
src="#myCanvas"
radius="2"
theta-length="30"
rotation="0 160 0"
>
</a-curvedimage>
</a-scene>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#000"
ctx.font = "22px sans-serif";
ctx.fillText("Lorem ipsum dolor sit amet", 0, 30);
</script>
</body>
</html>