I want to construct a custom geometry with texture, this is my code, everything goes well.
var mypositions = Cesium.Cartesian3.fromDegreesArray([60.0, 20.0, 120, 20, 120.0, 40.0, 60, 40]);
var numPositions = mypositions.length;
var pos = new Float64Array(numPositions * 3);
for (var i = 0; i < numPositions; ++i) {
pos[i * 3] = mypositions[i].x;
pos[i * 3 + 1] = mypositions[i].y;
pos[i * 3 + 2] = mypositions[i].z;
}
var uvs = [0, 0, 1, 0, 1, 1, 0, 1];
var indexs = new Uint16Array([0, 1, 2, 0, 2, 3])
var geometry = new Cesium.Geometry({
attributes: {
position: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: pos
}),
st: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 2,
values: uvs
})
},
indices : indexs,
primitiveType: Cesium.PrimitiveType.TRIANGLES,
boundingSphere: Cesium.BoundingSphere.fromVertices(pos)
});
var myInstance = new Cesium.GeometryInstance({
geometry: geometry,
});
viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances: myInstance,
appearance: new Cesium.MaterialAppearance({
material : new Cesium.Material({
fabric : {
type : 'Image',
uniforms : {
image : './Cesium_Logo_Color.jpg'
}
}
})
})
}));
then i want to map the texture repeate two times in both u and v direction, so i change my texture coordinate
var uvs = [0, 0, 2, 0, 2, 2, 0, 2];
it seems like just work in u direction. And i know there is the other soultion is build a material with repeate times with x and y values, but my situation is i need to build many geometry and combine in a primitive with the same material. So only i can do is build different geometry with different texture coordinates. I don’n know it’s a bug in cesium or my solution is wrong. If anybody has a answer, please help me. Thank you!