Changeset 9b1c16f for src


Ignore:
Timestamp:
Aug 24, 2017, 5:50:45 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
172e90d, 68030fa, dffb538
Parents:
17bc29b
git-author:
Joachim Langenbach <joachim.langenbach@…> (08/24/17 17:44:38)
git-committer:
Joachim Langenbach <joachim.langenbach@…> (08/24/17 17:50:45)
Message:

Added OrbitControl to 3D Rendering

Location:
src/webapp/webclient
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/css/GnuBoat.css

    r17bc29b r9b1c16f  
    9696}
    9797
    98 .chartGeometry {
     98.renderingGeometry {
    9999        width: 100%;
    100100        height: 24em;
  • src/webapp/webclient/index.html

    r17bc29b r9b1c16f  
    3838                <script src="lib/js/leaflet.hotline.min.js" type="text/javascript"></script>
    3939                <script src="lib/js/three.min.js"></script>
     40                <script src="lib/js/three.OrbitControls.js"></script>
    4041               
    4142                <link rel="stylesheet" href="css/GnuBoat.css" type="text/css"/>
    … …  
    7576                                GnuBoat.start();
    7677                        });
    77                        
    78                        
    79 //                      $(document).ready(function () {
    80 //                              var width = $("#3dchart").width();
    81 //                              var height = $("#3dchart").height();
    82 //                     
    83 //                              var scene = new THREE.Scene();
    84 //                              var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
    85 //
    86 //                              var renderer = new THREE.WebGLRenderer();
    87 //                              renderer.setSize(width, height );
    88 //                              document.getElementById("3dchart").appendChild( renderer.domElement );
    89 //
    90 //                              var geometry = new THREE.BoxGeometry( 1, 1, 1 );
    91 //                              var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    92 //                              var cube = new THREE.Mesh( geometry, material );
    93 //                              scene.add( cube );
    94 //
    95 //                              camera.position.z = 5;
    96 //
    97 //                              var animate = function () {
    98 //                                      requestAnimationFrame( animate );
    99 //
    100 //                                      cube.rotation.x += 0.1;
    101 //                                      cube.rotation.y += 0.1;
    102 //
    103 //                                      renderer.render(scene, camera);
    104 //                              };
    105 //
    106 //                              animate();
    107 //                      });
    10878                </script>
    10979        </head>
    … …  
    11787                                                <li class="pure-menu-item"><a class="pure-menu-link" href="#display">Display</a></li>
    11888                                                <li class="pure-menu-item"><a class="pure-menu-link" href="#map">Map</a></li>
    119                                                 <li class="pure-menu-item"><a class="pure-menu-link" href="#charts">Charts</a></li>
     89                                                <li class="pure-menu-item"><a class="pure-menu-link" href="#rendering">3D Rendering</a></li>
    12090                                                <li class="pure-menu-item"><a class="pure-menu-link" href="#logfiles">Logfiles</a></li>
    12191                                                <li class="pure-menu-item"><a class="pure-menu-link" href="#opencpn">OpenCPN</a></li>
    … …  
    187157                                        </form>
    188158
    189                                         <h2 class="content-subhead">Charts</h2>
     159                                        <h2 class="content-subhead">3D Rendering</h2>
    190160                                        <div>
    191                                                 <a name="charts"></a>
    192                                                 <div id="3dchart" class="chartGeometry"></div>
     161                                                <a name="rendering"></a>
     162                                                <form id="renderForm" class="pure-form">
     163                                                        <label>Scale Depth Axis:</label><input id="renderScaleZ" type="range" name="renderScaleZ" min="0.5" max="1000" step="1" value="10" class="pure-input-1">
     164                                                </form>
     165                                                <div id="rendering" class="renderingGeometry"></div>
    193166                                        </div>
    194167
  • src/webapp/webclient/js/GnuBoat.js

    r17bc29b r9b1c16f  
    193193        });
    194194       
    195         $("#3dchart").empty();
    196         var width = $("#3dchart").width();
    197         var height = $("#3dchart").height();
     195        $("#rendering").empty();
     196        var width = $("#rendering").width();
     197        var height = $("#rendering").height();
    198198
    199199        var fieldOfView = 75;
    200200       
    201201        GnuBoat.private.renderScene = new THREE.Scene();
    202 //      var aspect = width/height;
    203 //      var distance = 1000;
    204 //      GnuBoat.private.renderCamera = new THREE.OrthographicCamera(-distance * aspect, distance * aspect, distance, -distance, 0.1, 1000000);
    205 //      GnuBoat.private.renderCamera.up = new THREE.Vector3(0, 0, 1);
    206 //      GnuBoat.private.renderCamera.position.set(-1, -1, distance);
    207 //      GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
     202        GnuBoat.private.renderScene.background = new THREE.Color(0xEEEEEE);
    208203       
    209204        GnuBoat.private.renderCamera = new THREE.PerspectiveCamera(75, width/height, 0.1, 1000000);
    … …  
    214209        GnuBoat.private.renderRenderer = new THREE.WebGLRenderer();
    215210        GnuBoat.private.renderRenderer.setSize(width, height);
    216         GnuBoat.private.renderRenderer.setClearColor(0xEEEEEE);
    217         document.getElementById("3dchart").appendChild(GnuBoat.private.renderRenderer.domElement);
    218 
    219         GnuBoat.private.animate();
     211        GnuBoat.private.renderRenderer.setPixelRatio( window.devicePixelRatio );
     212        document.getElementById("rendering").appendChild(GnuBoat.private.renderRenderer.domElement);
     213       
     214        GnuBoat.private.renderControls = new THREE.OrbitControls( GnuBoat.private.renderCamera, GnuBoat.private.renderRenderer.domElement );
     215        GnuBoat.private.renderControls.zoomSpeed = 2;
     216       
     217       
     218       
     219        var deep = new THREE.Color(0x347C7C);
     220        var shallow = new THREE.Color(0xBCD9D9);
     221        var size = 5;
     222        GnuBoat.private.renderDepthSteps = 50;
     223
     224        var deltaR = (Math.max(deep.r, shallow.r) - Math.min(deep.r, shallow.r))/GnuBoat.private.renderDepthSteps;
     225        var deltaG = (Math.max(deep.g, shallow.g) - Math.min(deep.g, shallow.g))/GnuBoat.private.renderDepthSteps;
     226        var deltaB = (Math.max(deep.b, shallow.b) - Math.min(deep.b, shallow.b))/GnuBoat.private.renderDepthSteps;
     227        for(var i = 0; i < GnuBoat.private.renderDepthSteps; i++){
     228                var stepColor = new THREE.Color(Math.max(deep.r, shallow.r) - i * deltaR,
     229                                                                                Math.max(deep.g, shallow.g) - i * deltaG,
     230                                                                                Math.max(deep.b, shallow.b) - i * deltaB);
     231                GnuBoat.private.renderDepthMaterials.push(stepColor);
     232        }
     233        GnuBoat.private.renderDepthMaterials.push(shallow);
    220234}
    221235
    … …  
    237251                GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000);
    238252        GnuBoat.logfilesLoad();
     253       
     254        GnuBoat.private.animate();
    239255}
    240256
    … …  
    272288        renderCamera: null,
    273289        renderRenderer: null,
    274         renderGeometry: null,
    275         renderMaterial: null,
    276         renderCube: null,
    277290        renderMapBounds: null,
    278291        renderGrid: null,
     292        renderControls: null,
     293        renderCloud: null,
     294        renderDepthMaterials: [],
     295        renderDepthSteps: null,
    279296       
    280297        openLink: function(target)
    … …  
    378395                                        }
    379396                                }
    380                                 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"]);
     397                                GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]);
    381398                        }
    382399                }
    … …  
    478495                var m4 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getNorth(), GnuBoat.private.mapBounds.getWest());
    479496                var geometryMapBounds = new THREE.Geometry();
    480                 var materialMapBounds = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 1});
     497                var materialMapBounds = new THREE.LineBasicMaterial({color: 0x66BD66, linewidth: 1});
    481498                // z is greator 0, to draw the map boundings over the grid
    482499                var vertex = new THREE.Vector3(0, 0, 2);
    … …  
    490507                GnuBoat.private.renderMapBounds = new THREE.LineLoop(geometryMapBounds, materialMapBounds);
    491508                GnuBoat.private.renderScene.add(GnuBoat.private.renderMapBounds);
    492                
    493 //              var geometry = new THREE.Geometry();
    494 //              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
    495 //              geometry.vertices.push(new THREE.Vector3(1000, 0, 4));
    496 //              var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0xFF0000}));
    497 //              GnuBoat.private.renderScene.add(line);
    498 //             
    499 //              geometry = new THREE.Geometry();
    500 //              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
    501 //              geometry.vertices.push(new THREE.Vector3(0, 1000, 4));
    502 //              line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0x0000FF}));
    503 //              GnuBoat.private.renderScene.add(line);
    504 //             
    505 //              geometry = new THREE.Geometry();
    506 //              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
    507 //              geometry.vertices.push(new THREE.Vector3(0, 0, 1000));
    508 //              line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0x00FF00}));
    509 //              GnuBoat.private.renderScene.add(line);
    510509
    511510                // add 500m grid
    … …  
    514513                geometryMapBounds.computeBoundingBox();
    515514                var maxLength = Math.max(geometryMapBounds.boundingBox.getSize().x, geometryMapBounds.boundingBox.getSize().y);
    516                 GnuBoat.private.renderGrid = new THREE.GridHelper(maxLength, Math.round(maxLength / 500.0), 0xDDDDDD, 0xDDDDDD);
     515                GnuBoat.private.renderGrid = new THREE.GridHelper(maxLength, Math.round(maxLength / 500.0), 0xCCCCCC, 0xCCCCCC);
    517516                GnuBoat.private.renderGrid.geometry.rotateX( Math.PI / 2 );
    518517                GnuBoat.private.renderGrid.translateX(maxLength / 2.0);
    … …  
    520519                GnuBoat.private.renderScene.add(GnuBoat.private.renderGrid);
    521520               
    522                 var distance = 0.3 * maxLength;
     521                var distance = 150;
    523522                var fieldOfView = 2 * Math.atan(maxLength / (2.0 * distance) ) * 180.0 / Math.PI;
    524                 GnuBoat.private.renderCamera.position.set(0.1 * maxLength, 0.2 * maxLength, 0.3 * maxLength);
     523                GnuBoat.private.renderCamera.position.set(-10, -5, 100);
    525524                GnuBoat.private.renderCamera.fov = fieldOfView;
     525                GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
     526                GnuBoat.private.renderCamera.zoom = 5;
    526527                GnuBoat.private.renderCamera.updateProjectionMatrix();
    527528        },
    528529       
    529         drawDensityEstimation: function(densityPoints, maxima)
    530         {
    531                 var material = new THREE.PointsMaterial({color: 0x00CCCC, size: 1});
     530        drawDensityEstimation: function(densityPoints, maximum, minimum)
     531        {
     532                var material = new THREE.PointsMaterial({vertexColors: THREE.VertexColors, size: 5});
    532533                var geometry = new THREE.Geometry();
    533534                var mercatorSouthWest = {x: 0, y: 0};
    534                 if(GnuBoat.private.mapBounds != null){
     535                if(GnuBoat.private.mapBounds != null)
    535536                        mercatorSouthWest = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getWest());
    536                 }
    537537               
    538538                for(var i = 0; i < densityPoints.length; i++){
    539539                        var mercator = GnuBoat.private.mercator(densityPoints[i].latitude, densityPoints[i].longitude);
    540                         var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maxima);
     540                        var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maximum);
     541                        var color = new THREE.Color(0x000000);
     542                        if(GnuBoat.private.renderDepthSteps != null){
     543                                var step = Math.floor((densityPoints[i].depth - minimum)/((maximum-minimum)/GnuBoat.private.renderDepthSteps));
     544                                if(step >= 0 && step < GnuBoat.private.renderDepthMaterials.length)
     545                                        color = GnuBoat.private.renderDepthMaterials[step];
     546                        }
    541547                        geometry.vertices.push(vertex);
     548                        geometry.colors.push(color);
    542549                }
    543550                // point cloud
    … …  
    551558        {
    552559                requestAnimationFrame(GnuBoat.private.animate);
    553 
    554 //              if(GnuBoat.private.mapBounds != null){
    555 //                      GnuBoat.private.camera.position.set(GnuBoat.private.mapBounds.getCenter().lng, GnuBoat.private.mapBounds.getSouth(), 0);
    556 //                      GnuBoat.private.camera.up = new THREE.Vector3(0, 0, 1);
    557 //                      GnuBoat.private.camera.lookAt(new THREE.Vector3(GnuBoat.private.mapBounds.getCenter().lng, GnuBoat.private.mapBounds.getCenter().lat, 0));
    558 //                      GnuBoat.private.camera.zoom = 1;
    559 //              }
    560                
    561 //              var width = $("#3dchart").width();
    562 //              var height = $("#3dchart").height();
    563 //              GnuBoat.private.renderer.setSize(width, height);
     560                if(GnuBoat.private.renderCloud != null){
     561                        var scaleZ = $("#renderScaleZ").val();
     562                        if(GnuBoat.private.renderCloud.scale.z != scaleZ)
     563                                GnuBoat.private.renderCloud.scale.set(1, 1, scaleZ);
     564                }
     565               
     566                GnuBoat.private.renderControls.update();
    564567                GnuBoat.private.renderRenderer.render(GnuBoat.private.renderScene, GnuBoat.private.renderCamera);
    565568        },
Note: See TracChangeset for help on using the changeset viewer.