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

              
                
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ASTORIA ATELIER THREE.JS TEST 02</title>
</head>

<body>

    <canvas class="webgl"></canvas>



</body>
</html>
              
            
!

CSS

              
                *
{
    margin: 0;
    padding: 0;
}

html,
body
{
    overflow: hidden;
}


.webgl
{
    position: fixed;
    top: 0;
    left: 0;
    outline: none;
}

/*
.texteh1
{
    position: absolute;
    top: 50%;
    left: 50%;
    color: antiquewhite;
    font-size: 75px;
    opacity : 0.3;
}
*/
              
            
!

JS

              
                

// Canvas
const canvas = document.querySelector('canvas.webgl')

// Scene
const scene = new THREE.Scene()

// XYZ
const helper = new THREE.AxesHelper(50)
scene.add(helper)




////////// LOADERS

const cubeTextureLoader = new THREE.CubeTextureLoader()




/// UPDATE ALL MATERIALS

const updateAllMaterials = () =>
{
    scene.traverse((child) =>
    {
        if(child instanceof THREE.Mesh && child.material instanceof THREE.MeshStandardMaterial)
        {
            child.material.envMapIntensity = debugObject.envMapIntensity
            child.material.needsUpdate = true
            child.castShadow = true
            child.receiveShadow = true
    
        }
    })
}




////////// ENVIRONMENT MAP


const environmentMap = cubeTextureLoader.load([
    'https://i.ibb.co/SPs1JRz/nx.png',
    'https://i.ibb.co/2KXpQrL/ny.png',
    'https://i.ibb.co/2NpHN6J/nz.png',
    'https://i.ibb.co/mGfSw1X/px.png',
    'https://i.ibb.co/tsD9Rwr/py.png',
    'https://i.ibb.co/fk34d9s/pz.png'
])


environmentMap.encoding = THREE.sRGBEncoding

const colorfd = new THREE.Color( '#121212' )
scene.background = colorfd

scene.environment = environmentMap



////////////////////////////////////////////////////// OBJECTS



/// MATERIAL CYLINDERS

const material = new THREE.MeshStandardMaterial
const color = new THREE.Color( '#121212' )
material.color = color
material.roughness = 0
material.metalness = 0.9
//material.wireframe = true


// CYLINDER 1

const cylinder1 = new THREE.Mesh(
  new THREE.CylinderGeometry( 0.7, 0.7, 3, 32,5 ),
  material)

  cylinder1.position.set(-2.5,1,0)
  cylinder1.rotation.z = Math.PI *-0.06

scene.add(cylinder1)


// CYLINDER 2

const cylinder2 = new THREE.Mesh(
  new THREE.CylinderGeometry( 2, 2, 3, 32,5),
  material)

  cylinder2.position.set(3.5,0,5)
  cylinder2.rotation.z = Math.PI * 0.4

scene.add(cylinder2)


// CYLINDER 3

const cylinder3 = new THREE.Mesh(
  new THREE.CylinderGeometry( 0.7, 0.7, 3, 32,5 ),
  material)

  cylinder3.position.set(-5,0.2,2)
  cylinder3.rotation.z = Math.PI *0.05

scene.add(cylinder3)






////////// LIGHTS

const directionalLight = new THREE.DirectionalLight('#ffffff', 1)
directionalLight.castShadow = true
directionalLight.shadow.camera.far = 15
directionalLight.intensity = 1
directionalLight.shadow.mapSize.set(1024, 1024)
directionalLight.shadow.normalBias = 0.05
directionalLight.position.set(-5, 0, 3)
scene.add(directionalLight)




////////// SIZES

const sizes = {
    width: window.innerWidth,
    height: window.innerHeight
}


window.addEventListener('resize', () =>
{
    // Update sizes
    sizes.width = window.innerWidth
    sizes.height = window.innerHeight

    // Update camera
    camera.aspect = sizes.width / sizes.height
    camera.updateProjectionMatrix()

    // Update renderer
    renderer.setSize(sizes.width, sizes.height)
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))

  
})




////////// CAMERA

// Base camera
const camera = new THREE.PerspectiveCamera(40, sizes.width / sizes.height, 0.01, 100)
camera.position.set(3, 0, - 5)

scene.add(camera)

// CONTROLS

const controls = new THREE.OrbitControls(camera, canvas)
controls.enableDamping = true


console.log(camera)



////////// RENDERER

const renderer = new THREE.WebGLRenderer({
    canvas: canvas,
    antialias: true,

})

renderer.physicallyCorrectLights = true
renderer.outputEncoding = THREE.sRGBEncoding
renderer.shadowMap.enabled = true
renderer.shadowMap.type = THREE.PCFSoftShadowMap
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))





/*
////////////////// POST PROCESSING



const renderTarget = new THREE.WebGLRenderTarget(
  800,
  600,
  {
      minFilter: THREE.LinearFilter,
      magFilter: THREE.LinearFilter,
      format: THREE.RGBAFormat,
      encoding: THREE.sRGBEncoding
  }
)



const effectcomposer = new THREE.EffectComposer (renderer, renderTarget)
const renderPass = new THREE.RenderPass (scene, camera)

effectcomposer.addPass(renderPass)

effectcomposer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
effectcomposer.setSize(sizes.width, sizes.height)



// smaa

const smaaPass = new SMAAPass (scene, camera)
smaaPass.enabled = true

effectcomposer.addPass(smaaPass)

console.log(smaaPass)




// taa

const taaRenderPass = new TAARenderPass( scene, camera);
//taaRenderPass.unbiased = false;
effectcomposer.addPass( taaRenderPass );
taaRenderPass.TAASampleLevel = 30

console.log(taaRenderPass)




// bokeh

const target = new THREE.Vector3(0, 0, 0)
const lens = camera.position
const lensok = lens

const distance = target.distanceTo( lens )

const bokehsettings = {
  focus : (distance), aperture : 0.005,  maxblur : 0.2,
  width: sizes.width, height : sizes.height
}

const bokehPass = new BokehPass(scene, camera, bokehsettings)

effectcomposer.addPass(bokehPass)

bokehPass.enabled = false





/// fxaa

const fxaa = new ShaderPass(FXAAShader)
effectcomposer.addPass(fxaa)

fxaa.enabled = true

console.log(fxaa)
*/








////////// ANIMATE


const clock = new THREE.Clock()

const tick = () =>
{


    const elapsedTime = clock.getElapsedTime()


    // animation objects

    cylinder1.rotation.x = Math.cos(elapsedTime) +3
    cylinder1.rotation.y = 0.55 * elapsedTime
    cylinder1.rotation.z = 0.5 * elapsedTime
    
    cylinder3.position.x = Math.cos( elapsedTime / 15 ) *1
    cylinder3.position.z = Math.sin( elapsedTime / 3 ) *1 
    
    cylinder3.rotation.x = 0* elapsedTime 
    cylinder3.rotation.y = 0.6* elapsedTime 
    cylinder3.rotation.z = (0* elapsedTime) +0.1
    

    /// camera update
    camera.lookAt(cylinder1.position)

    // Update controls
    controls.update()
    
    // Call tick again on the next frame
    window.requestAnimationFrame(tick)

    // Render
    renderer.render(scene, camera)

    //effectcomposer.render()
    
    

    
    
  }

tick()



console.log(renderer.info)


              
            
!
999px

Console