question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

STL rendering issues on Chrome

See original GitHub issue

Describe the bug

I am working on a project in which I need to add an ability to view stl files uploaded by users. I followed some tutorials and examples, and in all of them I encountered an issue with rendering the stls. They look like that: image

This happens on Chrome. On Safari it works normally.

Here is a link to the STL that you see in the screenshot: https://storage.googleapis.com/ucloud-v3/ccab50f18fb14c91ccca300a.stl

I have tried it on other files, got the same resuilt.

To Reproduce Just run the code below.

Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />

    <title>Stl Viewer</title>
    <script>
      function STLViewer(model, elementID) {
        var elem = document.getElementById(elementID)

        var camera = new THREE.PerspectiveCamera(70, elem.clientWidth / elem.clientHeight, 1, 1000)
        var renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })
        renderer.setSize(elem.clientWidth, elem.clientHeight)
        elem.appendChild(renderer.domElement)

        window.addEventListener(
          'resize',
          function () {
            renderer.setSize(elem.clientWidth, elem.clientHeight)
            camera.aspect = elem.clientWidth / elem.clientHeight
            camera.updateProjectionMatrix()
          },
          false
        )

        var controls = new THREE.OrbitControls(camera, renderer.domElement)
        controls.enableDamping = true
        controls.rotateSpeed = 0.3
        controls.dampingFactor = 0.1
        controls.enableZoom = true
        controls.autoRotate = false
        controls.autoRotateSpeed = 0.75

        var scene = new THREE.Scene()
        scene.add(new THREE.HemisphereLight(0xffffff, 1.5))

        new THREE.STLLoader().load(model, function (geometry) {
          const material = new THREE.MeshPhongMaterial({ color: 0xaaaaaa, specular: 0x111111, shininess: 200 })
          const mesh = new THREE.Mesh(geometry, material)
          scene.add(mesh)

          var middle = new THREE.Vector3()
          geometry.computeBoundingBox()
          geometry.boundingBox.getCenter(middle)
          mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-middle.x, -middle.y, -middle.z))
          mesh.castShadow = false
          mesh.receiveShadow = false

          var largestDimension = Math.max(
            geometry.boundingBox.max.x,
            geometry.boundingBox.max.y,
            geometry.boundingBox.max.z
          )
          camera.position.z = largestDimension * 1.5

          var animate = function () {
            requestAnimationFrame(animate)
            controls.update()
            renderer.render(scene, camera)
          }

          animate()
        })
      }

      window.onload = function () {
        STLViewer('https://storage.googleapis.com/ucloud-v3/ccab50f18fb14c91ccca300a.stl', 'model')
      }
    </script>
  </head>

  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>

    <script src="./lib/three.min.js"></script>
    <script src="./lib/STLLoader.js"></script>
    <script src="./lib/OrbitControls.js"></script>

    <div id="model" style="width: 1500px; height: 1000px"></div>
  </body>
</html>

I downloaded three.min.js, STLLoader.js and OrbitControls directly from the three.js repo:

https://github.com/mrdoob/three.js/blob/dev/build/three.min.js https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/STLLoader.js https://github.com/mrdoob/three.js/blob/dev/examples/js/controls/OrbitControls.js

I tried also taking from master, same result.

Expected behavior

STL should simply render normally. image

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome version 100.0.4896.127 (today’s latest), Safari (15.3)
  • Three.js version: [dev, r???]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Mugen87commented, Jul 31, 2022

In the meanwhile, there is a Chromium bug tracking this issue:

https://bugs.chromium.org/p/chromium/issues/detail?id=1321452

1reaction
LeviPesincommented, Aug 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cura on Chromebook Rendering Fix - YouTube
If you are having trouble with screen rendering issues (especially in the "open" and "save" dialogues) while running Cura on your Chromebook ......
Read more >
Cannot render STL (3D file) in web browser, where it worked ...
I have been using this 3D rendering of the ISS for months now for a project. All of the sudden it doesn't work....
Read more >
WebGL Troubleshooting - Markforged Support
WebGL (Web Graphics Library) is an online tool that allows you to render 3D graphics, including parts and builds within Eiger. Google Chrome...
Read more >
936789 - Regression: Rendering issues when scrolling a page
Issue 936789: Regression: Rendering issues when scrolling a page. Reported by schedule meh. ... Chrome Version: Canary 74.0.3720.2
Read more >
How to enable WebGL on Chrome? - GeeksforGeeks
All the processing required to get a particular image is performed locally with the help of the client's graphics hardware. In most cases,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found