在Three.js中获得彩色平面而不是纹理

时间:2016-02-25 11:13:17

标签: javascript three.js

我正在尝试在我的对象上应用纹理。但我没有应用任何纹理,但只是对象上的彩色平面表示如果我正在应用的木纹理图像那么它只需要像棕色而不是实际纹理的纹理颜色。

基本代码如下:

var loader = new THREE.STLLoader();
var newMaterial = new THREE.MeshPhongMaterial( { color: colorValue, specular: 0xffffff, shininess: 100  } );

loader.load( './models/stl/binary/'+top, function ( newGeometry ) {

newMesh = new THREE.Mesh( newGeometry, newMaterial );

newMesh.position.set(  0,0.6, 0  );
newMesh.rotation.set(0,0.8,0);
newMesh.scale.set( 0.04, 0.04, 0.04 );

scene.add( newMesh );

我尝试使用以下纹理:

var newMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 100, map: THREE.ImageUtils.loadTexture( "textures/table/lighttexture.jpg" ),
    side: THREE.DoubleSide } );
    newMaterial.map.minFilter = THREE.LinearFilter;

上面代码的结果是一样的,只是应用了纹理的颜色。

var texture = new THREE.TextureLoader().load( "textures/water.jpg" );
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 4, 4 );
                var newMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 100, map: texture } );

获取上述代码的错误:

Uncaught TypeError: Cannot set property 'wrapS' of undefined

任何人都可以告诉我,我应该如何在我的物体上获得原始纹理?

修改

纹理对于球体几何体正常工作,如下面的代码所示。

            var sphereGeometry = new THREE.SphereGeometry(1, 10, 10);
            var mat = new THREE.MeshPhongMaterial();
            mat.map = new THREE.ImageUtils.loadTexture(
            "textures/table/lighttexture.jpg");
            mat.transparent = true;
            mat.side = THREE.DoubleSide;
            mat.depthWrite = false;
            mat.color = new THREE.Color(0xff0000);
            var sphere = new THREE.Mesh(sphereGeometry, mat);
            scene.add(sphere);

1 个答案:

答案 0 :(得分:0)

我怀疑你的几何体没有正确的紫外线 首先尝试纹理由三个

生成的几何体
/ Send Push Notification to all devices
// registered to `my_channel`

JSONObject jso = null;
try {
jso = new JSONObject("{
'aps' : {
'alert' : 'You got your emails.'," + "
'badge' : 9,
'sound' : 'bingbong.aiff'}," + "
'acme 1': 42
}");
pubnub.publish("my_channel", jso,
new Callback(){
@Override
public void successCallback(String arg0,
Object arg1) {
System.out.println(arg1);
}

如果纹理显示正确,则意味着从stl加载的几何体没有设置uvs或者它具有不正确的值(如全零)

到uvs使用

Sending Notifications
Sending a notification requires creating a JSON object. It is then added to a PubNub GCM specific message (the message is formatted for you).

public void sendNotification() {
    PnGcmMessage gcmMessage = new PnGcmMessage();
    JSONObject jso = new JSONObject();
    try {
        jso.put("GCMSays", "hi");
    } catch (JSONException e) { }
    gcmMessage.setData(jso);

    PnMessage message = new PnMessage(
            pubnub,
            "your channel name",
            callback,
            gcmMessage);
    try {
        message.publish();
    } catch (PubnubException e) {
        e.printStackTrace();
    }
}

Note that we have to create the callback methods which will be fired when the message is published:

public static Callback callback = new Callback() {
    @Override
    public void successCallback(String channel, Object message) {
        Log.i(TAG, "Success on Channel " + CHANNEL + " : " + message);
    }
    @Override
    public void errorCallback(String channel, PubnubError error) {
        Log.i(TAG, "Error On Channel " + CHANNEL + " : " + error);
    }
};

for Geometry

geometry = new THREE.PlaneGeometry(100,100);

如果您有BufferGeometry