Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript A帧:防止两个对象重叠。_Javascript_Virtual Reality_Aframe - Fatal编程技术网

Javascript A帧:防止两个对象重叠。

Javascript A帧:防止两个对象重叠。,javascript,virtual-reality,aframe,Javascript,Virtual Reality,Aframe,在这之后。我怎样才能使积木不在同一个地方繁殖 我可以想到两种方法: 创建一个坐标跟踪列表,我已经设置了一个框,如果交点匹配(或接近阈值),则阻止创建一个 检查十字线是否与边界框匹配(使用Threejs’Box3,我不知道如何使用) 有什么好办法吗?这是我对#2的回答: 我创建了一个数组。此数组将包含evt.detail.intersection.point的点。在插入新对象之前,我应用毕达哥拉斯(x点和z点),并将其与阈值进行比较。只有当它高于阈值时,我才允许它继续,并在其中存储新的点 整个代码

在这之后。我怎样才能使积木不在同一个地方繁殖

我可以想到两种方法:

  • 创建一个坐标跟踪列表,我已经设置了一个框,如果交点匹配(或接近阈值),则阻止创建一个
  • 检查十字线是否与边界框匹配(使用Threejs’Box3,我不知道如何使用) 有什么好办法吗?

    这是我对#2的回答: 我创建了一个数组。此数组将包含evt.detail.intersection.point的点。在插入新对象之前,我应用毕达哥拉斯(x点和z点),并将其与阈值进行比较。只有当它高于阈值时,我才允许它继续,并在其中存储新的点

    整个代码如下,并附有注释:

    我在这里使用了一些打字稿,我不会把它包括在内,这样它就可以接触到更多的读者

    为了分离代码,我用ES2015类包装了交叉点繁殖组件。我不知道通过ES2015创建a-Frame的原生方法

    这是主类“crossion spawn.js”

    script.js,其中包括两个类:

    import Lamp from './js/lamp/lamp';
    import IntersectionSpawn from './js/components/intersection-spawn';
    
    new IntersectionSpawn(new Lamp());
    
    现在是index.html:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
        <script src="https://rawgit.com/mayognaise/aframe-mouse-cursor-component/master/dist/aframe-mouse-cursor-component.min.js"></script>
        <script src="script.js"></script>
    </head>
    
    <body>
        <a-scene>
            <a-sky color="#ECECEC"></a-sky>
            <a-camera>
                <!-- We include the intersection-spawn in here:-->
                <a-cursor intersection-spawn="event: click;"></a-cursor>
            </a-camera>
        </a-scene>
    </body>
    
    </html>
    
    
    文件
    
    嗯,我刚刚做了。这可能不是所有解决方案中最漂亮的,但它正在发挥作用。如果还没有人对此发表评论,我肯定可以分享解决方案。我认为这两种方法都可以。对于较大的场景(1)将更具表现力。但在这成为一个问题之前,无需进行优化。:)请分享你的解决方案,我想知道你是如何做到的:)@piotradamilewski-Awesome-will。随便批评它。@DonMcCurdy:好了;)您可能会看到,在HTML中,我将脚本放在了头部。这是因为:请随时给我反馈:)
    import Lamp from './js/lamp/lamp';
    import IntersectionSpawn from './js/components/intersection-spawn';
    
    new IntersectionSpawn(new Lamp());
    
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
        <script src="https://rawgit.com/mayognaise/aframe-mouse-cursor-component/master/dist/aframe-mouse-cursor-component.min.js"></script>
        <script src="script.js"></script>
    </head>
    
    <body>
        <a-scene>
            <a-sky color="#ECECEC"></a-sky>
            <a-camera>
                <!-- We include the intersection-spawn in here:-->
                <a-cursor intersection-spawn="event: click;"></a-cursor>
            </a-camera>
        </a-scene>
    </body>
    
    </html>