Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:42:50+00:00 2026-06-16T00:42:50+00:00

I’ve created a tube geometry with data of 200 points loaded from external javascript

  • 0

I’ve created a tube geometry with data of 200 points loaded from external javascript file in JSON format. Please find the below code.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>3d Model using HTML5 and three.js</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <style>
            body {
                font-family: Monospace;
                background-color: #f0f0f0;
                margin: 0px;
                overflow: hidden;
            }
        </style>
    </head>
    <body>          
        <input type="button" value="plot" onClick="return plotPath();" />        
        <script src="three.min.js" type="text/javascript"></script>
        <script src="Curve.js" type="text/javascript"></script>
        <script src="TubeGeometry.js" type="text/javascript"></script>              
        <script src="Stats.js" type="text/javascript"></script>
        <script src="Detector.js" type="text/javascript"></script>      
        <script src="path.js" type="text/javascript"></script>

        <script>

        // variables
        var container, stats;

        var camera, scene, renderer, controls, stats;

        var text, plane, tube, tubeMesh, parent;

        var targetRotation = 0;
        var targetRotationOnMouseDown = 0;

        var mouseX = 0;
        var mouseXOnMouseDown = 0;

        var windowHalfX = window.innerWidth / 2;
        var windowHalfY = window.innerHeight / 2;

        var radius = 600;
        var theta = 0;
        var PI2 = Math.PI * 2;

        function plotPath()
        {                                           
            var obj = getPath();
            var segments = 50;
            var closed = false;
            var debug = true;
            var radiusSegments = 12;
            var tube;
            var points = [];
            var x=0,y=0,z=0;                    

            for(var i=0; i<obj.path.length; i++)
            {                               
                console.log(obj.path[i].point);
                points.push(obj.path[i].point);
                extrudePath = new THREE.SplineCurve3(points);
                extrudePath.dynamic = true;

                tube = new THREE.TubeGeometry(extrudePath, segments, 2, radiusSegments, closed, debug);
                tube.dynamic = true;

                tubeMesh = new THREE.Mesh(tube ,new THREE.MeshBasicMaterial({
                    color: 0x000000, side: THREE.DoubleSide,
                    opacity: 0.5, transparent: true, wireframe: true}));
                tubeMesh.__dirtyVertices = true;
                tubeMesh.dynamic = true;

                parent = new THREE.Object3D();
                parent.position.y = 100;

                if ( tube.debug ) tubeMesh.add( tube.debug );
                parent.add( tubeMesh );                                 
            }
            scene.add( tubeMesh );
            scene.add(parent);                      

            animate();                          
        } 

        init();                             

        function init(){

            // container
            container = document.createElement( 'div' );
            document.body.appendChild( container );                 

            // renderer         
            renderer = new THREE.WebGLRenderer( { antialias: true } );
            renderer.setClearColorHex(0xEEEEEE, 1.0);            
            renderer.setSize( window.innerWidth, window.innerHeight );
            renderer.clear();
            container.appendChild( renderer.domElement );                   

            // camera           
            camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
            camera.position.set(-100,75,75);                    

            // scene            
            scene = new THREE.Scene();
            camera.lookAt(scene.position);

            // light            
            scene.add( new THREE.AmbientLight( 0x404040 ) );
            light = new THREE.DirectionalLight( 0xffffff );
            light.position.set( 0, 1, 0 );
            scene.add( light ); 

            // CONTROLS
            controls = new THREE.TrackballControls( camera );               

            // Grid
            geometry = new THREE.Geometry();
            geometry.vertices.push( new THREE.Vector3( - 500, 0, 0 ) );
            geometry.vertices.push( new THREE.Vector3( 500, 0, 0 ) );

            for ( var i = 0; i <= 20; i ++ ) {

                line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.2 } ) );
                line.position.z = ( i * 50 ) - 500;
                scene.add( line );

                line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.2 } ) );
                line.position.x = ( i * 50 ) - 500;
                line.rotation.y = 90 * Math.PI / 180;
                scene.add( line );
            }                   

            // projector
            projector = new THREE.Projector();

            plotPath();

            // stats
            stats = new Stats();
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.top = '0px';
            container.appendChild( stats.domElement );

            document.addEventListener( 'mousedown', onDocumentMouseDown, false );
            document.addEventListener( 'mouseover', onDocumentMouseOver, false );
            document.addEventListener( 'touchstart', onDocumentTouchStart, false );
            document.addEventListener( 'touchmove', onDocumentTouchMove, false );
            window.addEventListener('DOMMouseScroll', mousewheel, false);
            window.addEventListener('mousewheel', mousewheel, false);
            window.addEventListener( 'resize', onWindowResize, false );
        }

        function mousewheel(event) {

            var fovMAX = 160;
            var fovMIN = 1;

            camera.fov -= event.wheelDeltaY * 0.05;
            camera.fov = Math.max( Math.min( camera.fov, fovMAX ), fovMIN );
            camera.projectionMatrix = new THREE.Matrix4().makePerspective(camera.fov, window.innerWidth / window.innerHeight, camera.near, camera.far);

        }

        function onWindowResize() {         
            camera.left = window.innerWidth / - 2;
            camera.right = window.innerWidth / 2;
            camera.top = window.innerHeight / 2;
            camera.bottom = window.innerHeight / - 2;
            camera.aspect = window.innerWidth / window.innerHeight;         

            renderer.setSize( window.innerWidth, window.innerHeight );
        }


        function onDocumentMouseDown( event ) {
            event.preventDefault();

            document.addEventListener( 'mousemove', onDocumentMouseMove, false );
            document.addEventListener( 'mouseup', onDocumentMouseUp, false );
            document.addEventListener( 'mouseout', onDocumentMouseOut, false );
            mouseXOnMouseDown = event.clientX - windowHalfX;
            targetRotationOnMouseDown = targetRotation;     
        }

        function onDocumentMouseMove( event ) {
            mouseX = event.clientX - windowHalfX;
            targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
        }

        function onDocumentMouseUp( event ) {
            document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
            document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
            document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
        }

        function onDocumentMouseOut( event ) {
            document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
            document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
            document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
        }

        function onDocumentMouseOver( event ) {
            document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
            document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
            document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
        }

        function onDocumentTouchStart( event ) {
            if ( event.touches.length === 1 ) {
                event.preventDefault();
                mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
                targetRotationOnMouseDown = targetRotation;
            }
        }

        function onDocumentTouchMove( event ) {
            if ( event.touches.length === 1 ) {
                event.preventDefault();
                mouseX = event.touches[ 0 ].pageX - windowHalfX;
                targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
            }
        }

        function animate() {
            requestAnimationFrame( animate, renderer.domElement );
            render();
            update();
        }

        function update(){
            controls.update();          
        }

        function toCameraCoords(position) {
              return camera.matrixWorldInverse.multiplyVector3(position.clone());
            }

        function render() {                 
            tubeMesh.rotation.y += ( targetRotation - tubeMesh.rotation.y ) * 0.15;                     
            camera.lookAt(scene.position);
            camera.updateMatrixWorld();
            renderer.render( scene, camera );
        }
        </script>        
    </body>
</html> 

When I use mouse wheel to zoom in, the camera will zoom in at starting point of the tube. How do I make the tube geometry can be zoomed completely or in other words any part of the tube can be zoomed ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:42:51+00:00Added an answer on June 16, 2026 at 12:42 am
    document.body.addEventListener( 'mousewheel', mousewheel, false );
    document.body.addEventListener( 'DOMMouseScroll', mousewheel, false ); // firefox
    
    
    function mousewheel( e ) {      
        var d = ((typeof e.wheelDelta != "undefined")?(-e.wheelDelta):e.detail);
        d = 100 * ((d>0)?1:-1);
    
        var cPos = camera.position;
        if (isNaN(cPos.x) || isNaN(cPos.y) || isNaN(cPos.y))
          return;
    
        var r = cPos.x*cPos.x + cPos.y*cPos.y;
        var sqr = Math.sqrt(r);
        var sqrZ = Math.sqrt(cPos.z*cPos.z + r);
    
    
        var nx = cPos.x + ((r==0)?0:(d * cPos.x/sqr));
        var ny = cPos.y + ((r==0)?0:(d * cPos.y/sqr));
        var nz = cPos.z + ((sqrZ==0)?0:(d * cPos.z/sqrZ));
    
        if (isNaN(nx) || isNaN(ny) || isNaN(nz))
          return;
    
        cPos.x = nx;
        cPos.y = ny;
        cPos.z = nz;
    }
    

    or even simpler ajusting only the camera :

    var mousewheel  = function ( e ) {
         var d = ((typeof e.wheelDelta != "undefined")?(-e.wheelDelta):e.detail);
         d = 100 * ((d>0)?1:-1);    
         var cPos = camera.position;
         if (isNaN(cPos.x) || isNaN(cPos.y) || isNaN(cPos.y)) return;
    
            // Your zomm limitation
            // For X axe you can add anothers limits for Y / Z axes
            if (cPos.x > _YOUR_ZOOM_MIN_X_ || cPos.x < _YOUR_ZOOM_MAX_X_ ){
               return ;
            }
    
       mb = d>0 ? 1.1 : 0.9;
       cPos.x = cPos.x * mb;
       cPos.y = cPos.y * mb;
       cPos.z = cPos.z * mb;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I am trying to render a haml file in a javascript response like so:
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.