How to add surface's normal to a cylinderGeometry with "slices = 6"

Hello !

I tried to create a cylinder with hexagon bottom projection as follows:

var viewer = new Cesium.CesiumWidget(‘cesiumContainer’);
var scene = viewer.scene;

var cylinderGeometry = new Cesium.CylinderGeometry({
length : 5000,
topRadius : 3000,
bottomRadius : 3000,
slices: 6,
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
});

var cylinder = new Cesium.GeometryInstance({
geometry: cylinderGeometry,
modelMatrix: Cesium.Matrix4.multiplyByTranslation(
Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(116.60777 , 40.04883),
new Cesium.Cartesian3(0.0,0.0, length/2),
new Cesium.Matrix4()
),
attributes: {
color : Cesium.ColorGeometryInstanceAttribute.fromColor( Cesium.Color.fromCssColorString(’#0070c0’))
}
});

var primitive = new Cesium.Primitive({
geometryInstances : cylinder,
appearance: new Cesium.PerInstanceColorAppearance({
closed : true,
translucent: false,
flat: false,
faceForward: false
})
});

scene.primitives.add(primitive);

``

It is hard to distinguish the bottom projection is a circle or a hexagon,

how can I add normal to a cylinderGeometry?

Hello,

Currently the surface normals are pointing out from the edges of the sides of the cylinder, which is why they are being blended together. You would need to duplicate the points at each corner so you can have a normal for one side and a normal pointing in a different direction for the other.

You would need to edit the code here: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/CylinderGeometry.js#L215

However, if you only want a hexagon it might be easier to write a new custom geometry type that meets your needs.

For some more information about this, you can see this (slightly outdated and never published) post I wrote about creating custom geometry: https://github.com/AnalyticalGraphicsInc/cesium/wiki/Geometry-and-Appearances

And you can see our build guide for instructions on downloading and building the code base: https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/BuildGuide

Best,

Hannah

Thanks Hannah, so nice of you

在 2017年2月6日星期一 UTC+8下午10:49:34,Hannah Pinkos写道: