简体   繁体   English

A帧随机发生器

[英]A-frame random generator

I need to create a random enviroment in a-frame using javascript. 我需要使用JavaScript在A框架中创建随机环境。

<a-entity id="tree" position="0 1 -3">
                <a-box  rotation="90 0 90" scale="1 1 3" color="#6e583f"></a-box>
                <a-box scale="2 2 2" position="0 2.3 0" color="#4bbd53"></a-box>
 </a-entity> 

This entity needs to be created on a random x and z position but i cant find the way to randomly do it and to make many of them with a single for cycle. 这个实体需要在一个随机的x和z位置上创建,但是我找不到随机执行的方法,并且用一个for循环来创建许多实体。

You can do all of this with a single custom component. 您可以使用单个自定义组件来完成所有这些操作。 You make an empty entity, and attach a single word (the name of your custom component), and inside the component, you can create an array of new entities, and add components to them, for geometry, position, material, etc. Then use Math.random() to randomize whatever attributes you like (x pos, z pos etc). 您可以创建一个空实体,并附加一个单词(自定义组件的名称),然后在组件内部可以创建一个新实体数组,并向其中添加组件(例如几何体,位置,材质等)。使用Math.random()随机化您喜欢的任何属性(x pos,z pos等)。

Here is an example glitch . 这是一个小故障示例

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

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