Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body {
	background-color: #000;
	margin: 0px;
	overflow: hidden;
}
              
            
!

JS

              
                // Simple three.js example

console.log('***************** BEGIN *******************');  

var texture_image = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"%3E%3Cg fill-rule="evenodd"%3E%3Cg fill="%239C92AC" fill-opacity="0.4"%3E%3Cpath opacity=".5" d="M96 95h4v1h-4v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9zm-1 0v-9h-9v9h9zm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3C/g%3E%3C/g%3E%3C/svg%3E';


//var texture_image = 'http://www.dimmicomefare.it/wp-content/uploads/quadretti.jpg';

//var texture_image = '';


function meshFitUvMap(mesh) {
  
   if (mesh.geometry && 
       mesh.material && 
       mesh.material.map && 
       mesh.material.map.userData && 
       mesh.material.map.userData.fitTo > 0) {
     
       
      var geometry = mesh.geometry;
      var textureFitTo = mesh.material.map.userData.fitTo; 
      var faces = mesh.geometry.faces;
      for (var i = 0, len = faces.length; i < len; i ++) {
           var face = faces[i];
           var uv = geometry.faceVertexUvs[0][i];
          
         /*
           var vA = mesh.geometry.vertices[face.a];
           var vB = mesh.geometry.vertices[face.b];
           var vC = mesh.geometry.vertices[face.c];
         
         //  console.log('vertex' , vA , vB , vC);
           var dvAB = vA.distanceTo(vB);
           var dvBC = vB.distanceTo(vC);
           var dvCA = vC.distanceTo(vA);
         //  console.log('distance' , dvAB , dvBC , dvCA);
         
            
          
           //console.log('Uv current ' + i , uv );
           var newUv0 = new THREE.Vector2( uv[0].x / 2  , uv[2].y / 2 ); 
           var newUv1 = new THREE.Vector2( uv[1].x / 2  , uv[1].y / 2 ); 
           var newUv2 = new THREE.Vector2( uv[2].x / 2  , uv[2].y / 2 );
         
         */
         
         
           var components = ['x', 'y', 'z'].sort(function(a, b) {
              return Math.abs(face.normal[a]) > Math.abs(face.normal[b]);
           });
         
         var v1 = mesh.geometry.vertices[face.a];
         var v2 = mesh.geometry.vertices[face.b];
         var v3 = mesh.geometry.vertices[face.c];
         
         var newUv0 = new THREE.Vector2(v1[components[0]] / textureFitTo, v1[components[1]] / textureFitTo);
         var newUv1 = new THREE.Vector2(v2[components[0]] / textureFitTo, v2[components[1]] / textureFitTo);
         var newUv2 = new THREE.Vector2(v3[components[0]] / textureFitTo, v3[components[1]] / textureFitTo);
         
       /*  var newUv0 = new THREE.Vector2(v1[components[0]] , v1[components[1]] );
         var newUv1 = new THREE.Vector2(v2[components[0]] , v2[components[1]] );
         var newUv2 = new THREE.Vector2(v3[components[0]] , v3[components[1]] );*/
         
           uv[0].copy(newUv0);
           uv[1].copy(newUv1);
           uv[2].copy(newUv2);

       }
   }
}

function sezione (b,t,h,x) {
   return b - ( (b -t) * x / h); 
}

function createMesh(b , t , h , material) {
   var spessore = 0.4;  
   var rientro_basso = 2;
   var rientro_alto = 2.5;
   var rientro_ab = 2;
   
   var points = [
         new THREE.Vector2(-b + rientro_basso, 0),
         new THREE.Vector2(-b , 0),
         new THREE.Vector2(-t , h),
         new THREE.Vector2(-t + rientro_alto, h),
         new THREE.Vector2(-t + rientro_alto, h - rientro_ab),
         new THREE.Vector2(-t + rientro_alto - spessore, h - rientro_ab),
         new THREE.Vector2(-t + rientro_alto - spessore, h - spessore),
         new THREE.Vector2(-sezione(b,t,h,h - spessore) + spessore, h - spessore),
         new THREE.Vector2(-sezione(b,t,h,spessore) + spessore, spessore),
         new THREE.Vector2(-b + rientro_basso, spessore),
         new THREE.Vector2(-b + rientro_basso, 0)
  ];

  var latheGeometry = new THREE.LatheGeometry(points, 64);
   
   var mesh = new THREE.Mesh( latheGeometry,  material);
   mesh.position.set(-4,0,0);
   mesh.castShadow = true;
   mesh.receiveShadow = true;
   meshFitUvMap(mesh);
   
   scene.add(mesh);
}

init();
animate();

function init() {

    // renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );
    renderer.shadowMap.enabled = true;
    renderer.shadowMap.type = THREE.PCFSoftShadowMap;
    renderer.antialias = true;
    document.body.appendChild( renderer.domElement );

    // scene
    scene = new THREE.Scene();
    
    // camera
    camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.set( 20, 20, 20 );

    // controls
    controls = new THREE.OrbitControls( camera );
    
    // ambient
    scene.add( new THREE.AmbientLight( 0x888888, 0.6 ) );
    
    // light
 /*   var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
    light.position.set( 10, 8, 10 );
    scene.add( light );*/
    
    // axes
    scene.add( new THREE.AxesHelper( 20 ) );
  
    var light = new THREE.PointLight(0x00ffff, 1);
    light.castShadow = true;
    light.shadow.mapSize.width = 2048;
    light.shadow.mapSize.height = 2048;
    light.position.set(5, 15, 15);
    scene.add(light);


    var fixTexture = new THREE.TextureLoader().load( texture_image );
    fixTexture.userData = {
      fitTo : 1
    };
  	fixTexture.wrapS = THREE.RepeatWrapping;
	  fixTexture.wrapT = THREE.RepeatWrapping;
     
    // material
  
   var material = new THREE.MeshPhongMaterial( {
        color: 0xffffff, 
        transparent: false,
        opacity: 0.9,
        map: fixTexture,
        side: THREE.DoubleSide
    } ); 
    
  
    var geometry = new THREE.PlaneGeometry( 1 , 1 , 1 );
		var plane = new THREE.Mesh( geometry, material );
		plane.rotation.x=-0.5*Math.PI;
		plane.position.set(-4.5,0,1.5);
    plane.castShadow = true;
    plane.receiveShadow = true;
    meshFitUvMap(plane);
    scene.add( plane );
  
    var geometry = new THREE.PlaneGeometry( 2 , 6 , 1 );
		var plane = new THREE.Mesh( geometry, material );
		plane.rotation.x=-0.5*Math.PI;
		plane.position.set(-3,0,1);  
    plane.castShadow = true;
    plane.receiveShadow = true;
    meshFitUvMap(plane);
    scene.add( plane );
   
    var geometry = new THREE.PlaneGeometry( 4 , 4 , 1 );
		var plane = new THREE.Mesh( geometry, material );
		plane.rotation.x=-0.5*Math.PI;
		plane.position.set(0,0,0);
    plane.castShadow = true;
    plane.receiveShadow = true;
    meshFitUvMap(plane);
    scene.add(plane);
  
    var geometry = new THREE.BoxGeometry( 2, 5, 2 );
    var box = new THREE.Mesh( geometry, material );
    box.position.set(0,0,-3); 
    box.castShadow = true;
    box.receiveShadow = true;
    meshFitUvMap(box);
    scene.add( box );
  
    var geometry = new THREE.BoxGeometry( 3, 3, 3 );
    var box = new THREE.Mesh( geometry, material );
    box.position.set(3.5,0,0);  
    box.castShadow = true;
    box.receiveShadow = true;
    meshFitUvMap(box);
    scene.add( box );
  
    var geometry = new THREE.CylinderGeometry( 3, 3, 4, 32 );
    var box = new THREE.Mesh( geometry, material );
    box.position.set(3.5,-0.5,4.5);  
    box.castShadow = true;
    box.receiveShadow = true;
    meshFitUvMap(box);
    scene.add( box );
  
    var geometry = new THREE.OctahedronGeometry( 2, 0 );
    var box = new THREE.Mesh( geometry, material );
    box.position.set(0,0,0);  
    box.castShadow = true;
    box.receiveShadow = true;
    meshFitUvMap(box);
    scene.add( box );
  
    createMesh(1 , 4 , 3 , material);
  
}

function animate() {

    requestAnimationFrame( animate );

    renderer.render( scene, camera );

}

              
            
!
999px

Console