使用 Autodesk 查看器时,贴花似乎没有按预期显示。上图正确显示贴花(未在 Autodesk Viewer 中渲染),下图没有贴花(在 Autodesk 查看器中渲染)。
为什么会这样?如何使贴花在 Autodesk Viewer 中工作?
源文件在这里。
使用 Autodesk 查看器时,贴花似乎没有按预期显示。上图正确显示贴花(未在 Autodesk Viewer 中渲染),下图没有贴花(在 Autodesk 查看器中渲染)。
为什么会这样?如何使贴花在 Autodesk Viewer 中工作?
源文件在这里。
这是我的代码示例。我在 Forge 上导入了 STEP 文件,并在我的 node.js 服务器上复制了 RefdFile_1.png 文件。
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) ;
}) ;
}