使用Autodesk Viewer时,贴花似乎没有按预期显示。上面的图像正确显示贴花(未在Autodesk Viewer中渲染),下面的图像没有贴花(在Autodesk查看器中渲染)。
为什么会这样,以及如何使用贴花在Autodesk Viewer中工作?
源文件here。
答案 0 :(得分:0)
这是我的代码示例。我在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) ;
}) ;
}