本文主要是介绍Cesium Primitive报错:Appearance/Geometry mismatch,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Cesium 在用Primitive创建对象时报错:Appearance/Geometry mismatch
An error occurred while rendering. Rendering has stopped.
DeveloperError: Appearance/Geometry mismatch. The appearance requires vertex shader attribute input 'color', which was not computed as part of the Geometry. Use the appearance's vertexFormat property when constructing the geometry.
错误的大致意思就是实体的顶点和材质不匹配,导致渲染出错;
解决方案:
①类似BoxOutlineGeometry这类几何,不能使用光照,需要将appearance中的flat属性设置为true,即关闭光照。
正常代码:
// 创建boxOutline的几何实例let boxOutlineInstance = new Cesium.GeometryInstance({geometry: boxOutlineGeometry,modelMatrix: Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(120, 40)),new Cesium.Cartesian3(0.0, 0.0, 1000.0),new Cesium.Matrix4()),id: "boxOutline",attributes: {color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED),},});// 创建图元let primitive = new Cesium.Primitive({geometryInstances: boxOutlineInstance,appearance: new Cesium.PerInstanceColorAppearance({flat: true,faceForward: true,translucent: false,closed: false,}),show: true,modelMatrix: Cesium.Matrix4.IDENTITY,vertexCacheOptimize: false,interleave: false,compressVertices: true,releaseGeometryInstances: true,allowPicking: true,cull: true,asynchronous: true,debugShowBoundingVolume: false,shadows: Cesium.ShadowMode.DISABLED,});viewer.scene.primitives.add(primitive);
②绘制Primitive实体时,几何图形的vertexFormat确定它是否可以与其他几何图形组合。两个几何图形不必是相同的类型,但它们需要匹配的顶点格式。我们可以理解成实体的vertexFormat需要与他的appearance定义的材质形式一致。
错误代码:
let primitive = new Cesium.Primitive({geometryInstances: new Cesium.GeometryInstance({geometry: new Cesium.PolylineGeometry({positions: Cesium.Cartesian3.fromDegreesArray(positions),width: 3.0,vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,}),}),appearance: new Cesium.PolylineMaterialAppearance({flat: true,material: Cesium.Material.fromType(Cesium.Material.PolylineDashType, {color: Cesium.Color.CYAN, //线条颜色gapColor: Cesium.Color.TRANSPARENT, //间隔颜色dashLength: 20, //短划线长度}),}),});viewer.scene.primitives.add(primitive);
正确代码:注意vertexFormat形式更改为PolylineMaterialAppearance
let primitive = new Cesium.Primitive({geometryInstances: new Cesium.GeometryInstance({geometry: new Cesium.PolylineGeometry({positions: Cesium.Cartesian3.fromDegreesArray(positions),width: 3.0,vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,}),}),appearance: new Cesium.PolylineMaterialAppearance({material: Cesium.Material.fromType(Cesium.Material.PolylineDashType, {color: Cesium.Color.CYAN, //线条颜色gapColor: Cesium.Color.TRANSPARENT, //间隔颜色dashLength: 20, //短划线长度}),}),});viewer.scene.primitives.add(primitive);
这篇关于Cesium Primitive报错:Appearance/Geometry mismatch的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!