본문 바로가기

Dev/webgl

[playcanvas engine only] Texture map

방법 1

class PlayerEntity {

    constructor() {
        this.entity = new pc.Entity();
        // load component
        this.entity.addComponent("model", { type: "box" });
        this.entity.setName('Player')

        const entityMaterial = this.entity.model.meshInstances[0].material;
        entityMaterial.diffuseMap = this.setMaterial("./assets/textures/proto_orange.png");
        entityMaterial.update();
   
        console.log(pc.app.assets)
    }

      setMaterial(materialPath) {
        let texture = new pc.gfx.Texture(app.graphicsDevice);
        let img = new Image();
        img.onload = function () {
          texture.setSource(img);
        };
        img.src = materialPath;
        return texture;
      }
}

방법 2 (더 간단)

app.assets.loadFromUrl("../assets/clouds.jpg", "texture", function (err, asset) {
            var material = new pc.StandardMaterial();
            material.diffuseMap = asset.resource;
            material.update();
            box.model.model.meshInstances[0].material = material;
        });

 

중요한건 FBX로 max나 maya에서 내보낼때, texture 랑FBX가 떨어지는데

데이터상 Texture가 묻어있다는거다 ..

-------------

FBX -> playcanvas JSON 묻은걸 보존

FBX -> gltf 묻은걸 보존 x

'Dev > webgl' 카테고리의 다른 글

[playcanvas] ibl to cubemap with trouble  (0) 2019.09.06
[webgl] Gltf 란?  (0) 2019.09.05
[playcanvas engine only] Texture map  (0) 2019.09.04
[playcanvas] Shader, Material, Texture, Map 용어정리  (1) 2019.08.28
model과 mesh 구분 그리고..  (1) 2019.08.28
[playcanvas] cors 문제  (1) 2019.08.27