SyntaxError: Unexpected reserved word в строке const shaderCode = await…
- User
SyntaxError: Unexpected reserved word в строке const shaderCode = await loadShaderFile('glsl.glsl'); код: import * as THREE from 'three'; import Stats from 'three/addons/libs/stats.module.js'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; async function loadShaderFile(url) { const response = await fetch(url); const shaderCode = await response.text(); return shaderCode; }
async function main() {
// Создаем загрузчик gltf const loader = new GLTFLoader(); loader.load( 'card3.glb', (gltf) => { const phone = gltf.scene; let container, stats, clock; let camera, scene, renderer; let line; const segments = 1000; const r = 800; let t = 0; init(); const controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; scene.add(controls.target); animate(); function init() { container = document.getElementById( 'container' ); // camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 4000 ); camera.position.z = 2750; scene = new THREE.Scene(); clock = new THREE.Clock(); const shaderCode = await loadShaderFile('glsl.glsl'); const geometry = new THREE.BufferGeometry(); //const material = new THREE.LineBasicMaterial( { vertexColors: true } ); const material = new THREE.ShaderMaterial({ fragmentShader: shaderCode }) const positions = []; const colors = []; for ( let i = 0; i < segments; i ++ ) { const x = Math.random() * r - r / 2; const y = Math.random() * r - r / 2; const z = Math.random() * r - r / 2; // positions positions.push( x, y, z ); // colors colors.push( ( x / r ) + 0.5 ); colors.push( ( y / r ) + 0.5 ); colors.push( ( z / r ) + 0.5 ); } geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) ); geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) ); geometry.computeBoundingSphere(); line = new THREE.Line( geometry, material ); scene.add( line ); // renderer = new THREE.WebGLRenderer(); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight ); renderer.useLegacyLights = false; container.appendChild( renderer.domElement ); // stats = new Stats(); container.appendChild( stats.dom ); // window.addEventListener( 'resize', onWindowResize ); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); } // function animate() { requestAnimationFrame( animate ); controls.update(); render(); stats.update(); } function render() { const delta = clock.getDelta(); const time = clock.getElapsedTime(); t += delta * 0.5; renderer.render( scene, camera ); } } ); - Assistant
- User
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'domElement') в строке const controls = new OrbitControls(camera, renderer.domElement); не переписывай весь код, только там, где надо поправить
- Assistant