Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

не пишет никаких ошибок, но не отображает картинку ../img/stars.jpg. Отображается белый…

  1. User

    не пишет никаких ошибок, но не отображает картинку ../img/stars.jpg. Отображается белый фон. почему? код: import * as THREE from 'three'; import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; import * as dat from 'dat.gui';

    import stars from '../img/stars.jpg'; console.log(stars);

    const renderer = new THREE.WebGL1Renderer(); renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;

    let width = window.innerWidth; let height = window.innerHeight;

    document.body.appendChild(renderer.domElement);

    const scene = new THREE.Scene(); let camera = new THREE.PerspectiveCamera( 75, width/ height, 0.1, 1000 );

    const orbit = new OrbitControls(camera, renderer.domElement);

    const axesHalper = new THREE.AxesHelper(4); scene.add(axesHalper);

    camera.position.set(0,1,5); orbit.update();

    const boxGeometry = new THREE.BoxGeometry(); const boxMaterial = new THREE.MeshStandardMaterial({color: 0xF0F100}); const box = new THREE.Mesh(boxGeometry, boxMaterial); scene.add(box); box.castShadow = true;

    const planeGeometry = new THREE.PlaneGeometry(10,10,10); const planeMaterial = new THREE.MeshStandardMaterial({ color: 0xFDDFF0, side: THREE.DoubleSide
    }); const plane = new THREE.Mesh(planeGeometry, planeMaterial); scene.add(plane); plane.rotation.x = -Math.PI/2; plane.position.y = -1; plane.receiveShadow = true;

    const sphereGeometry = new THREE.SphereGeometry(0.9, 100.8, 100); const sphereMaterial = new THREE.MeshStandardMaterial({ color: 0x000fff, wireframe: false
    }); const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial); scene.add(sphere); sphere.position.set(1, 1, 0); sphere.castShadow = true;

    const ambientLight = new THREE.AmbientLight(0x333333); scene.add(ambientLight);

    // const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 0.5); // scene.add(directionalLight); // directionalLight.position.set(3,3,3); // directionalLight.castShadow = true; // //directionalLight.shadow.camera.bottom = -1;

    // const dLightHalper = new THREE.DirectionalLightHelper(directionalLight, 1); // scene.add(dLightHalper);

    // const dLightShadowHalper = new THREE.CameraHelper(directionalLight.shadow.camera); // scene.add(dLightShadowHalper);

    const spotLight = new THREE.SpotLight(0xFFFFFF); scene.add(spotLight); spotLight.position.set(5,5,0); spotLight.castShadow = true;

    const sLightHalper = new THREE.SpotLightHelper(spotLight); scene.add(sLightHalper);

    const gridHalper = new THREE.GridHelper(); scene.add(gridHalper);

    // scene.fog = new THREE.Fog(0xFFFFFF, 0, 20); scene.fog = new THREE.FogExp2(0x000000, 0.1);

    // renderer.setClearColor(0xFFAE00);

    // const textureLoader = new THREE.TextureLoader(); // scene.background = textureLoader.load(stars);

    const cubeTextureLoader = new THREE.CubeTextureLoader(); scene.background = cubeTextureLoader.load(stars); console.log(scene.background );

    const gui = new dat.GUI(); const options = { spotLightHight: 2, sphereColor: '#ffee00', wireframe: false, speed: 0.2, angleLight: 0.5, penumbra: 0.5, intensity: 1 };

    gui.addColor(options, 'sphereColor').onChange(function(e){ sphere.material.color.set(e); }); gui.add(options, 'wireframe').onChange(function(e){ sphere.material.wireframe = e; }); gui.add(options, 'speed', 0, 0.2); gui.add(options, 'spotLightHight', 0, 10); gui.add(options, 'angleLight', 0, 1.5); gui.add(options, 'penumbra', 0, 1); gui.add(options, 'intensity', 0, 2);

    let step = 0;

    function animate(time) { box.rotation.y = time / 1000; box.rotation.x = time / 1000;

    step += options.speed;
    sphere.position.y = 0.4 * Math.abs(Math.sin(step));
    spotLight.position.y = options.spotLightHight;
    spotLight.angle = options.angleLight;
    spotLight.penumbra = options.penumbra;
    spotLight.intensity = options.intensity;
    sLightHalper.update();
    width = window.innerWidth;
    renderer.setSize(width, height);
    
    renderer.render(scene, camera);
    

    } renderer.setAnimationLoop(animate);

  2. Assistant

    Возможно, проблема заключается в некорректном пути к файлу со звездами. Проверьте правильность пути, убедитесь, что файл находится по указанному пути, и что он имеет расширение '.jpg'. Также проверьте, что файл не поврежден или не имеет некорректного формата. Если проблема не решена, попробуйте использовать другой файл с изображением.

  3. User

    ree.module.js:23638 THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. setTextureParameters @ three.module.js:23638 requestAnimationFrame (async) onAnimationFrame @ three.module.js:13062 requestAnimationFrame (async) onAnimationFrame @ three.module.js:13062 requestAnimationFrame (async) start @ three.module.js:13073 WebGLRenderer.setAnimationLoop @ three.module.js:28397 dV6cC.three @ script.js:142 newRequire @ index.e82f28a0.js:71 (anonymous) @ index.e82f28a0.js:122 (anonymous) @ index.e82f28a0.js:145 6WebGL: INVALID_VALUE: texImage2D: width != height for cube map content.js:20 USearch content.js:20 Loaded extension.1 DevTools failed to load source map: Could not load content for chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/browser-polyfill.js.map: System error: net::ERR_FILE_NOT_FOUND

  4. Assistant

    Предупреждение "THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter." означает, что текстура не имеет мощности 2 (т. е. ширина или высота не является степенью 2: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 и т. д.). Метод minFilter для таких текстур должен быть установлен на THREE.NearestFilter или THREE.LinearFilter.

    Чтобы исправить это предупредждение, установите minFilter на один из двух значений, указанных в предупреждении. Например:

    const cubeTextureLoader = new THREE.CubeTextureLoader();
    const texture = cubeTextureLoader.load([
        'img/px.jpg',
        'img/nx.jpg',
        'img/py.jpg',
        'img/ny.jpg',
        'img/pz.jpg',
        'img/nz.jpg'
    ]);
    texture.minFilter = THREE.LinearFilter; // или THREE.NearestFilter
    scene.background = texture;
    

    Предупреждение "WebGL: INVALID_VALUE: texImage2D: width != height for cube map" означает, что ширина и высота текстуры кубической карты не равны. Убедитесь, что размеры изображений в кубической карте одинаковые.

  5. User

    пишет ошибку ree.module.js:43071 Uncaught TypeError: url.lastIndexOf is not a function at LoaderUtils.extractUrlBase (three.module.js:43071:21) at GLTFLoader.load (GLTFLoader.js:181:31) at dV6cC.three (script.js:123:14) at newRequire (index.e82f28a0.js:71:24) at index.e82f28a0.js:122:5 at index.e82f28a0.js:145:3 e код: import * as THREE from 'three'; import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; import * as dat from 'dat.gui';

    import stars from '../img/star.png'; import nebula from '../img/nebula.jpg'; import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';

    const modelUrl = new URL('../assets/3dmodel.glb', import.meta.url);

    const renderer = new THREE.WebGL1Renderer(); renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;

    let width = window.innerWidth; let height = window.innerHeight;

    renderer.setSize(width, height); document.body.appendChild(renderer.domElement);

    const scene = new THREE.Scene(); let camera = new THREE.PerspectiveCamera( 75, width/ height, 0.1, 1000 );

    const orbit = new OrbitControls(camera, renderer.domElement);

    const axesHalper = new THREE.AxesHelper(4); scene.add(axesHalper);

    camera.position.set(0,1,5); orbit.update();

    const boxGeometry = new THREE.BoxGeometry(); const boxMaterial = new THREE.MeshStandardMaterial({color: 0xF0F100}); const box = new THREE.Mesh(boxGeometry, boxMaterial); scene.add(box); box.castShadow = true;

    const planeGeometry = new THREE.PlaneGeometry(10,10,10); const planeMaterial = new THREE.MeshStandardMaterial({ color: 0xFDDFF0, side: THREE.DoubleSide
    }); const plane = new THREE.Mesh(planeGeometry, planeMaterial); scene.add(plane); plane.rotation.x = -Math.PI/2; plane.position.y = -1; plane.receiveShadow = true;

    const sphereGeometry = new THREE.SphereGeometry(0.9, 100.8, 100); const sphereMaterial = new THREE.MeshStandardMaterial({ color: 0x000fff, wireframe: false
    }); const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial); scene.add(sphere); sphere.position.set(1, 1, 0); sphere.castShadow = true;

    const ambientLight = new THREE.AmbientLight(0x333333); scene.add(ambientLight);

    // const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 0.5); // scene.add(directionalLight); // directionalLight.position.set(3,3,3); // directionalLight.castShadow = true; // //directionalLight.shadow.camera.bottom = -1;

    // const dLightHalper = new THREE.DirectionalLightHelper(directionalLight, 1); // scene.add(dLightHalper);

    // const dLightShadowHalper = new THREE.CameraHelper(directionalLight.shadow.camera); // scene.add(dLightShadowHalper);

    const spotLight = new THREE.SpotLight(0xFFFFFF); scene.add(spotLight); spotLight.position.set(5,5,0); spotLight.castShadow = true;

    const sLightHalper = new THREE.SpotLightHelper(spotLight); scene.add(sLightHalper);

    const gridHalper = new THREE.GridHelper(); scene.add(gridHalper);

    // scene.fog = new THREE.Fog(0xFFFFFF, 0, 20); scene.fog = new THREE.FogExp2(0x000000, 0.1);

    // renderer.setClearColor(0xFFAE00);

    const textureLoader = new THREE.TextureLoader(); // scene.background = textureLoader.load(stars);

    const cubeTextureLoader = new THREE.CubeTextureLoader(); const textereCube = cubeTextureLoader.load([stars,stars,stars,stars,stars,stars]); textereCube.minFilter = THREE.LinearFilter; // или THREE.NearestFilter scene.background = textereCube;

    const box2Geometry = new THREE.BoxGeometry(2,2,2); const box2Material = new THREE.MeshStandardMaterial(); const box2MultiMaterial = [ new THREE.MeshStandardMaterial({map: textureLoader.load(nebula)}), new THREE.MeshStandardMaterial({map: textureLoader.load(nebula)}), new THREE.MeshStandardMaterial({map: textureLoader.load(nebula)}), new THREE.MeshStandardMaterial({map: textureLoader.load(stars)}), new THREE.MeshStandardMaterial({map: textureLoader.load(nebula)}), new THREE.MeshStandardMaterial({map: textureLoader.load(stars)}), new THREE.MeshStandardMaterial({map: textureLoader.load(nebula)}), ] const box2 = new THREE.Mesh(box2Geometry, box2MultiMaterial); box2.position.set(0,2,1); scene.add(box2); box2.material.map = textureLoader.load(nebula);

    const assetsLoader = new GLTFLoader(); assetsLoader.load(modelUrl, function(gltf) { const model = gltf.scene; scene.add(model); }, undefined, function(error) { console.error(error); });

    const gui = new dat.GUI(); const options = { spotLightHight: 2, sphereColor: '#ffee00', wireframe: false, speed: 0.2, angleLight: 0.5, penumbra: 0.5, intensity: 1 };

    gui.addColor(options, 'sphereColor').onChange(function(e){ sphere.material.color.set(e); }); gui.add(options, 'wireframe').onChange(function(e){ sphere.material.wireframe = e; }); gui.add(options, 'speed', 0, 0.2); gui.add(options, 'spotLightHight', 0, 10); gui.add(options, 'angleLight', 0, 1.5); gui.add(options, 'penumbra', 0, 1); gui.add(options, 'intensity', 0, 2);

    let step = 0;

    const mousePosition = new THREE.Vector2();

    window.addEventListener('mousemove', function(e) { mousePosition.x = (e.clientX / width) * 2 - 1; mousePosition.y = - (e.clientY / height) * 2 + 1; });

    const rayCaster = new THREE.Raycaster();

    const sphereId = sphere.id;

    function animate(time) { box.rotation.y = time / 1000; box.rotation.x = time / 1000;

    step += options.speed;
    sphere.position.y = 0.4 * Math.abs(Math.sin(step));
    spotLight.position.y = options.spotLightHight;
    spotLight.angle = options.angleLight;
    spotLight.penumbra = options.penumbra;
    spotLight.intensity = options.intensity;
    sLightHalper.update();
    width = window.innerWidth;
    height = window.innerHeight;
    
    rayCaster.setFromCamera(mousePosition, camera);
    const intersects = rayCaster.intersectObjects(scene.children);
    console.log(intersects);
    
    for(let i = 0; i<intersects.length; i++) {
        if(intersects[i].object.id === sphereId) {
            intersects[i].object.material.color.set(0xFFFFFF);
        }
    }
    renderer.render(scene, camera);
    

    } renderer.setAnimationLoop(animate);

    window.addEventListener('resize', function(e) { camera.aspect = width / height; camera.updateProjectionMatrix(); renderer.setSize(width, height); });

  6. Assistant

    Ошибка "url.lastIndexOf is not a function" возникает, когда объект, у которого вызывается метод lastIndexOf(), не является строкой (string).

    В данном случае, вероятно url в GLTFLoader.load() не является строковым значением, а является объектом URL, что вызывает ошибку. Чтобы решить это, убедитесь, что значения url передаваемые в GLTFLoader.load() являются строками. Вы можете преобразовать объект URL в строку вызвав метод toString():

    import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';
    
    const modelUrl = new URL('../assets/3dmodel.glb', import.meta.url).toString(); 
    
    const assetsLoader = new GLTFLoader();
    assetsLoader.load(modelUrl, function(gltf) {
        const model = gltf.scene;
        scene.add(model);
    }, undefined, function(error) {
        console.error(error);
    });
    

    В результате modelUrl будет строкой, а не объектом URL, что позволит правильно передать адрес в GLTFLoader.load().