38three.js傅里叶变换

图片.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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,194评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,058评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,780评论 0 346
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,388评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,430评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,764评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,907评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,679评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,122评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,459评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,605评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,270评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,867评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,734评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,961评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,297评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,472评论 2 348

推荐阅读更多精彩内容