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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- three.min.js r87 -->
<script src="https://threejs.org/build/three.min.js"></script>

<!-- GLTFLoader.js -->
<script src="https://threejs.org/examples/js/loaders/GLTFLoader.js"></script>

<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

body {
  background: #000;
}
              
            
!

JS

              
                var scene, renderer, controls;
var camera;
var mesh;

var isMouseDown = false;
 
function init() {
    scene = new THREE.Scene(); 
    
    camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 10000 ); 
    camera.position.z = 25; 
    camera.position.y = 15;
  
    renderer = new THREE.WebGLRenderer({
         antialias: true
    }); 
    renderer.setSize( window.innerWidth, window.innerHeight ); 
    document.body.appendChild( renderer.domElement ); 
    renderer.setClearColor(0x00ffff, 1); 
    renderer.gammaOutput = true;
    
    var light = new THREE.DirectionalLight("#c1582d", 1);
    var ambient = new THREE.AmbientLight("#85b2cd");
    light.position.set( 0, -70, 100 ).normalize();
    scene.add(light);
    scene.add(ambient);
  
  // controls
  controls = new THREE.OrbitControls(camera, renderer.domElement);

    var texture = new THREE.Texture();
    var manager = new THREE.LoadingManager();
    manager.onProgress = function ( item, loaded, total ) {};
    var onProgress = function ( xhr ) {};
    var onError = function ( xhr ) {};

    var loader = new THREE.GLTFLoader();

    // Load a glTF resource
    loader.load(
        // resource URL
          'https://threejsfundamentals.org/threejs/resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf',
        // called when the resource is loaded
        function ( gltf ) {
          mesh = gltf.scene;
          //mesh.scale.set( 0.05, 0.05, 0.05 );
          let bbox = new THREE.Box3().setFromObject(mesh);
          let center = new THREE.Vector3();
          bbox.getCenter(center);
          console.log(center);
          console.log(mesh);
          
          var pivotMesh = new THREE.Mesh(new THREE.BoxBufferGeometry(1, 1, 1))
          scene.add(pivotMesh)
          
          mesh.traverse((child)=>{

            if(child.geometry){
      
              child.parent.updateMatrixWorld();
              var vector = new THREE.Vector3();
              var quat = new THREE.Quaternion();
              
              child.getWorldPosition(vector)
              child.getWorldQuaternion(quat)
          
              scene.remove(child.parent)
              child.parent.remove(child)
              child.parent = null
              
              scene.add(child)
              child.position.copy(vector)
              child.quaternion.copy(quat)
              
              child.parent = pivotMesh
              pivotMesh.add(child)
              pivotMesh.position.set(-center.x, -center.y, -center.z);   
   
            }
           
              
          });
          scene.add( mesh );

          
         },
        // called when loading is in progresses
        function ( xhr ) {
          console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );

        },
        // called when loading has errors
        function ( error ) {
          console.log( 'An error happened' );

        }
    );
    
  let mat = new THREE.Matrix3();
  mat.setUvTransform(0, 0, 1, 1,0, 0.5, 0.5);
console.log(mat);
    render();   
}

function render() {
    requestAnimationFrame( render ); 
  controls.update();

    renderer.render(scene, camera); 
}

window.addEventListener('DOMContentLoaded', init);
              
            
!
999px

Console