美文网首页
38three.js傅里叶变换

38three.js傅里叶变换

作者: 狂暴机甲 | 来源:发表于2018-07-12 21:20 被阅读0次
图片.png
<pre id="line1"><!DOCTYPE html>  <html lang="en">  <head>  <meta charset="UTF-8">  <title>01 three.js Fourier transform</title>  <script type="text/javascript" src="[../js/three.js](view-source:https://scqilin.github.io/mycodes/threejs02/js/three.js)"></script>  <script type="text/javascript" src="[../js/Detector.js](view-source:https://scqilin.github.io/mycodes/threejs02/js/Detector.js)"></script>  <script type="text/javascript" src="[../js/controls/OrbitControls.js](view-source:https://scqilin.github.io/mycodes/threejs02/js/controls/OrbitControls.js)"></script>  <style type="text/css"> body{margin: 0;overflow: hidden} </style>  </head>  <body>  <div id="webgl-output"></div>  <script type="text/javascript"> if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
    function init() {
        var scene,camera,renderer,light,controls;
        var clock = new THREE.Clock();
        var spheres = [];
        var spheres1 = [];
        var spheresa,spheresb,cube1;
        var times = 0;
        var stoptem = 1;
        drawScene();

        function drawScene() {
            iniScene();
            iniLight();
            orbitControls();
            windowResize();
            //cube1 = cubeDr(2,0,2,0);
            //var cube2 = cubeDr(2,0,15,0);
            //drawline(cube1,cube2);
            //iniPlane();
            //spheresa = cubeSphere(1,8,5,5,0);
            //spheresb = cubeSphere(1,8,0,5,0);

            //spheresa.add(spheresb);

            /*for(var i =0;i<3;i++){
                spheres[i] = cubeSphere(0.5,8,i,10*Math.cos(i/20),10*Math.sin(i/20));
                spheres1[i] = cubeSphere(0.5,8,i+0,20*Math.cos(i/20),20*Math.sin(i/20));

                //console.log(spheres[i].position);
                //console.log(spheres[i].children[0].position);
                drawline(spheres[i],spheres1[i]);
            }*/
            render();
        }
        //场景
        function iniScene() {
            scene = new THREE.Scene();
            camera = new THREE.OrthographicCamera(window.innerWidth/-16,window.innerWidth/16,
                window.innerHeight/16, window.innerHeight/-16,-200,1000);
            renderer = new THREE.WebGLRenderer();
            camera.position.set(0,20,0);
            //camera.lookAt(scene.position);
            renderer.setClearColor(0xffffff);
            //renderer.shadowMap.enabled = true;

            renderer.setSize(window.innerWidth,window.innerHeight);
            scene.add(new THREE.AxesHelper(100));
            document.getElementById('webgl-output').appendChild(renderer.domElement);
            window.addEventListener('click',onDocumentMouseDown,false);
            function onDocumentMouseDown(event) {
                stoptem ++;
            }
        }
        //灯光
        function iniLight() {
            light = new THREE.AmbientLight(0x666666);
            scene.add(light);

            light = new THREE.DirectionalLight(0x888888);
            light.position.set(0,40,0);

            //light.castShadow = true;
            //light.shadow.mapSize.height = 1024;
            //light.shadow.mapSize.width = 1024;
            light.shadow.camera.near = 2;
            light.shadow.camera.far = 100;
            light.shadow.camera.top = 100;
            light.shadow.camera.bottom = -100;
            light.shadow.camera.left = -100;
            light.shadow.camera.right = 100;
            //scene.add(new THREE.CameraHelper( light.shadow.camera ));
            scene.add(light);

            /*light = new THREE.HemisphereLight( 0xffffff,0x444444,0.6 );
            light.position.set( 0, 200, 0 );
            scene.add( light );*/
        }
        //地面 和 辅助网格
        function iniPlane() {
            var planeGeo = new THREE.PlaneGeometry(200,200);
            var planeMat = new THREE.MeshPhongMaterial( { color: 0x999999} );
            var plane = new THREE.Mesh(planeGeo,planeMat);
            plane.receiveShadow = true;
            plane.position.y = -21.03;
            plane.rotation.x = -0.5*Math.PI;
            scene.add(plane);

            var grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
            grid.material.transparent = true;
            grid.position.y = -21;
            grid.material.opacity = 0.3;
            scene.add( grid );
        }
        //立方体
        function cubeDr(a,x,y,z) {
            var cubeGeo = new THREE.BoxGeometry(a,a,a);
            var cubeMat = new THREE.MeshPhongMaterial({
                color:0xfff000*Math.random(),
            });
            var cube = new THREE.Mesh(cubeGeo,cubeMat);
            cube.position.set(x,y,z);
            //cube.castShadow = true;
            scene.add(cube);
            //console.log(cube);
            return cube;
        }
        //小球
        function cubeSphere(r,a,x,y,z) {
            var cubeGeo = new THREE.SphereBufferGeometry(r,a);
            var cubeMat = new THREE.MeshPhongMaterial({
                color:0xff0fff*Math.random(),
            });
            var sphere = new THREE.Mesh(cubeGeo,cubeMat);
            sphere.position.set(x,y,z);
            //sphere.castShadow = true;
            scene.add(sphere);
            return sphere;
        }
        //添加射线
        function drawline(point1,point2) {
            var points = [];
            points.push(new THREE.Vector3(point1.position.x, point1.position.y, point1.position.z));
            points.push(new THREE.Vector3(point2.position.x, point2.position.y, point2.position.z));
            var mat = new THREE.MeshLambertMaterial({color: 0xff0000, transparent: true, opacity: 0.6});
            var tubeGeometry = new THREE.TubeGeometry(new THREE.CatmullRomCurve3(points), 64, 0.1);
            var tube = new THREE.Mesh(tubeGeometry, mat);
            scene.add(tube);
        }
        //相机轨道控制器
        function orbitControls() {
            controls = new THREE.OrbitControls(camera,renderer.domElement);
            //自转
            //controls.autoRotate = true;
            //controls.autoRotateSpeed = 0.2;
            //阻尼 阻尼系数
            controls.enableDamping = true;
            controls.dampingFactor = 0.4;
            //缩放
            controls.enableZoom = true;
            controls.minDistance = 5;
            controls.maxDistance = 1000;
            //右键拖拽
            controls.enablePan = true;
            //controls.minPolarAngle = Math.PI/2; // radians
            //controls.maxPolarAngle = Math.PI/2; // radians
        }
        //改变窗口大小
        function windowResize() {
            window.addEventListener( 'resize', onWindowResize, false );
            function onWindowResize() {
                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(window.innerWidth, window.innerHeight);
            }
        }
        //渲染动画
        function render() {

            var delta = clock.getDelta();
            requestAnimationFrame(render);
            renderer.render(scene,camera);
            controls.update(delta); //不能在里面写clock.getDelta()
            if(stoptem%3 == 1){
                times ++;
                spheres[times] = cubeSphere(0.6,2,times/3,10*Math.cos(times/20),10*Math.sin(times/20));
                spheres1[times] = cubeSphere(0.3,2,times/3,
                    10*Math.cos(times/20)+4*Math.cos(times/10)+3*Math.sin(times/5),
                    10*Math.sin(times/20)+4*Math.sin(times/10)+3*Math.cos(times/5)
                );
                //drawline(spheres[times],);
                //drawline(spheres[times],spheres1[times]);
                //controls.target =new THREE.Vector3(times+10/3,50,0);
                camera.position.set(times/3,10,0);
                controls.target.set(times/3,10,0);
                if(times>=150){
                    scene.remove(spheres[times-150]);
                    scene.remove(spheres1[times-150]);
                }
            }

        }

    }
    window.onload = init; </script>  </body>  </html></pre>

相关文章

  • 38three.js傅里叶变换

  • 无标题文章

    傅里叶变换的本质是什么? 傅里叶变换的公式为 可以把傅里叶变换也成另外一种形式: 可以看出,傅里叶变换的本质是内积...

  • 2018Android实验室CV培训总结

    Android实验室CV培训 傅里叶变换(空间域 -> 频率域) 什么是傅里叶变换? 维基百科: 傅里叶变换(法语...

  • 离散傅里叶变换 DFT

    离散傅里叶变换 DFT 周期 离散信号 (离散时间傅里叶变换:非周期,离散;傅里叶变换:非周期,连续;傅里叶级数:...

  • 快速傅里叶变换和离散傅里叶变换

    快速傅里叶变换(FFT) 离散傅里叶变换(DFT) 基础理论是傅里叶变换的分离形式,和采样定理(香菜定理) 采样定...

  • Scipy

    通过傅里叶变换实现图片降噪 scipy.fftpack模块用来计算快速傅里叶变换速度比传统傅里叶变换更快,是对之前...

  • 基础-小波傅里叶变换

    https://www.zhihu.com/question/22864189 傅里叶变换-频率信息短时傅里叶变换...

  • 快速傅里叶变换——理论

    本文公式较多,欢迎大家勘误 1.周期离散信号的傅里叶变换 离散信号傅里叶变换的公式如下所示: 离散傅里叶变换的原理...

  • 11 MRI图像分析--连续离散傅里叶变换

    前言 连续傅里叶变换和离散傅里叶变换经常用于MRI 图像分析之中,第11块主要讲MRI 图像和傅里叶变换的细节,涉...

  • openCV:傅里叶变换

    傅里叶变换 概念 https://zhuanlan.zhihu.com/p/19763358 傅里叶变换的作用 高...

网友评论

      本文标题:38three.js傅里叶变换

      本文链接:https://www.haomeiwen.com/subject/uzfdpftx.html