Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              var camera, scene, renderer, control, orbit, cube, cube1;
        var back = false;
        var meshes = new Array();
        var meshl = new Array();
        var meshr = new Array();

        // init();
        // render();

const textures = [];
            const manager = new THREE.LoadingManager();
            manager.onLoad = function() {
            const loader = new THREE.TextureLoader(manager);
            var arr = [

        function init() {


            container = document.createElement('div');
            renderer = new THREE.WebGLRenderer({
                antialias: true
            renderer.setSize(window.innerWidth, window.innerHeight);

            camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 3000);
            camera.position.set(100, 100, 500);
            camera.lookAt(0, 20, 0);

            scene = new THREE.Scene();
            scene.add(new THREE.GridHelper(2000, 10));

            var light = new THREE.DirectionalLight(0xffffff, 2);
            light.position.set(1, 1, 1);

            orbit = new THREE.OrbitControls(camera, renderer.domElement);
            orbit.addEventListener('change', render);

            control = new THREE.TransformControls(camera, renderer.domElement);
            control.addEventListener('change', render);

            control.addEventListener('dragging-changed', function(event) {

                orbit.enabled = !event.value;


            // instantiate a texture loader
            // var loader = new THREE.TextureLoader();
            // loader.crossOrigin = '';

            // The textures to use
            // var arr = [
            //     'images/slider0.jpg',
            //     'images/slider1.jpg',
            //     'images/slider2.jpg'
            // ];
            // var textureToShow = 0;

            // var texture = loadTexture('');

            var material = new THREE.MeshBasicMaterial();

            //var material1 = new THREE.MeshBasicMaterial();
            var geometry = new THREE.PlaneGeometry(200, 200, 200);
            //var geometry1 = new THREE.PlaneGeometry(300, 200, 200);
            cube = new THREE.Mesh(geometry, material);
            //cube1 = new THREE.Mesh(geometry1, material1);

            // loader.load(arr[textureToShow], function(tex) {
            // = tex;
            //     textureToShow++;
            //     scene.add(cube);
            //     render();
            // });

            // var texture1 = new THREE.TextureLoader().load('images/right-arrow.png', render);
            // texture1.anisotropy = renderer.capabilities.getMaxAnisotropy();
            // var material1 = new THREE.MeshLambertMaterial({
            //     map: texture1,
            //     color: 0x000000,
            // });
          //child mesh objects for click events
            var mesh11 = new THREE.Mesh(new THREE.PlaneGeometry(20, 40, 0), new THREE.MeshBasicMaterial({
                color: 0xaa00ff
            mesh11.position.x = 90;
            var mesh12 = new THREE.Mesh(new THREE.BoxGeometry(20, 40, 0), new THREE.MeshBasicMaterial({
                color: 0xaa00ff
            mesh12.position.x = -90;
          //pushing the code to arrays
          //adding DOM Event listenersto child objects
            var domEvents = new THREEx.DomEvents(camera, renderer.domElement);

            domEvents.addEventListener(mesh11, 'click', function(event) {
                for (let i = 0; i < arr.length; i++) {
                    loader.load(arr[i], function(tex) {
                        textures[i] = tex;
             = textures[i];
            }, false)
            domEvents.addEventListener(mesh12, 'click', function(event) {
                loader.load(arr[textureToShow], function(tex) {
                    console.log("left:" + arr[textureToShow]);

                    if (textureToShow == -1) {
                        textureToShow = 2;
           = tex;
                    console.log("after: " + textureToShow);
            }, false)


            window.addEventListener('resize', onWindowResize, false);
        }//end of init()

        function onWindowResize() {

            camera.aspect = window.innerWidth / window.innerHeight;

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


        function render() {

            renderer.render(scene, camera);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.