Decals not displaying in Autodesk Viewer

后端 未结 1 686
天命终不由人
天命终不由人 2021-01-26 12:32

When using the Autodesk Viewer, decals do not seem to display as expected. The image above has the decal displaying correctly (not rendered in Autodesk Viewer), and the image be

1条回答
  •  爱一瞬间的悲伤
    2021-01-26 13:17

    Here is my code sample. I imported the STEP file on Forge, and copied the RefdFile_1.png file on my node.js server.

    var attenuationVertexShader =`
      varying vec2 vUv;
      varying vec3 vPosition;
      void main() {
        vUv = uv;
        vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
        gl_Position = projectionMatrix * mvPosition;
      }
      ` ;
    
    var attenuationFragmentShader = `
      varying vec2 vUv;
      uniform sampler2D checkerboard;
      void main() {
        gl_FragColor = texture2D(checkerboard, vec2 (vUv.x * 0.1263, vUv.y * 0.166)) ;
      }
    ` ;
    
    var dbId =4 ;
    var fragId =0 ;
    var texturePath ="/RefdFile_1.png" ;
    var material =null ;
    
    oViewer =new Autodesk.Viewing.Private.GuiViewer3D ($("#viewer") [0], {}) ; // With toolbar
    Autodesk.Viewing.Initializer (options, function () {
        oViewer.initialize () ;
        oViewer.addEventListener (Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function (event) {
            oViewer.fitToView (true) ;
            setTimeout (function () { oViewer.autocam.setHomeViewFrom (oViewer.navigation.getCamera ()) ; }, 1000) ;
            setTimeout (createTexture, 500) ;
        }) ;
        oViewer.setGroundReflection (false) ;
        oViewer.setGroundShadow (false) ;
        oViewer.load (myurn) ;
    }) ;
    
    function createTexture () {
        var loader =new THREE.TextureLoader () ;
        loader.load (texturePath, function (texture) {
            texture.minFilter =THREE.LinearMipMapLinearFilter ; // THREE.LinearMipMapLinearFilter
            texture.magFilter =THREE.LinearFilter ;
    
            var uniforms ={
                checkerboard: {
                    type: 't',
                    value: texture
                }
            } ;
            material =new THREE.ShaderMaterial ({
              uniforms: uniforms,
              vertexShader: attenuationVertexShader,
              fragmentShader: attenuationFragmentShader,
              side: THREE.DoubleSide
            }) ;
            oViewer.impl.matman ().removeMaterial ('shaderMaterial') ;
            oViewer.impl.matman ().addMaterial ('shaderMaterial', material, true) ;
            var floor_mesh_render =oViewer.impl.getRenderProxy (oViewer.model, fragId) ;
            oViewer.model.getFragmentList ().setMaterial (fragId, material) ;
            oViewer.impl.invalidate (true) ;
        }) ;
    }
    

    0 讨论(0)
提交回复
热议问题