【问题标题】:three.js; Cannot read property 'position' of undefined and don't know why三.js;无法读取未定义的属性“位置”并且不知道为什么
【发布时间】:2014-07-10 22:17:05
【问题描述】:

我要做我的太阳!!!!!!!!!!!!!!!!!!太阳神!!!急——!

..对不起。

效果也不好。

控制台上显示的错误消息,它说;

// Uncaught TypeError: Cannot read property 'position' of undefined;

这里是源码

// Constructing * The Solar *
var shape = new THREE.BufferGeometry();
    shape.addAttribute('position', new THREE.Float32Attribute(6,3));
    // console shows problem is here but I can't find any
    shape.addAttribute('textureOrder', new THREE.Int8Attribute(6,1));


    for(var i=0; i<6; i++) {
        shape.attribute.position.setXYZ(i, 0, 0, 0);
        shape.attribute.textureOrder.setX(i, i);
    };

var d = new Date();

var mater = new THREE.ShaderMaterial({
    uniforms: {
        time: { type: 'f', value: d.getTime() },
        tsun_core: { type: 't', value: loadTexture('./sun_core.png') },
        tsun_innerglow: { type: 't', value: loadTexture('./sun_innerglow.png') },
        tsun_starlight: { type: 't', value: loadTexture('./sun_starlight.png') },
        tsun_outerglow: { type: 't', value: loadTexture('./sun_outerglow.png') },
        tsun_shortjetlight: { type: 't', value: loadTexture('./sun_shortjetlight.png') },
        tsun_longjetlight: { type: 't', value: loadTexture('./sun_longjetlight.png') }
    },
    vertexShader: document.getElementById('vs-sun').textContent,
    fragmentShader: document.getElementById('fs-sun').textContent
});
    mater.depthTest = false;
    mater.vertexColor = true;
    mater.transparent = true;
    mater.blending = THREE.AdditiveBlending;

sun = new THREE.ParticleSystem(shape, mater);
scene.add(sun);

我的目标是,在片段着色器中将 gl_FragColor 不透明度更改为uniform time,以便我的太阳(?)更具动态性...

我认为,问题的原因在源头之上。请指导我..

【问题讨论】:

    标签: javascript properties three.js webgl undefined


    【解决方案1】:

    THREE.BufferGeometry 实例上调用addAttribute 方法会在attributes 属性下创建属性,而不是attribute

    替换这些行

        shape.attribute.position.setXYZ(i, 0, 0, 0);
        shape.attribute.textureOrder.setX(i, i);
    

    以下几行

        shape.attributes.position.setXYZ(i, 0, 0, 0);
        shape.attributes.textureOrder.setX(i, i);
    

    【讨论】:

    • 感谢您的回答。我英语不好,非常感谢您的指正
    猜你喜欢
    • 2021-05-10
    • 2018-08-31
    • 1970-01-01
    • 2021-12-20
    • 2017-08-26
    • 2020-07-01
    • 2021-08-02
    • 2017-10-29
    • 1970-01-01
    相关资源
    最近更新 更多