Skip to content

Instantly share code, notes, and snippets.

@chris-cooper
Created June 25, 2015 23:18
Show Gist options
  • Select an option

  • Save chris-cooper/590465f9b0dadd7fc91b to your computer and use it in GitHub Desktop.

Select an option

Save chris-cooper/590465f9b0dadd7fc91b to your computer and use it in GitHub Desktop.
Cesium low level textured quad
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var flatten = function(ar) {
return [].concat.apply([], ar);
};
var extract = function(p) {
return [p.x, p.y, p.z];
};
var pts = Cesium.Cartesian3.fromDegreesArray([
0.0, 0.0,
10.0, 10.0,
10.0, 0.0,
0.0, 0.0,
0.0, 10.0,
10.0, 10.0
]);
var ptsArray = new Float64Array(flatten(pts.map(extract)));
var boundingSphere = Cesium.BoundingSphere.fromPoints(pts);
var sts = new Float32Array([0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0]);
var normals = new Float32Array([0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0]);
var instance = new Cesium.GeometryInstance({
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 1.0))
},
geometry: new Cesium.Geometry({
attributes: {
position: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.DOUBLE,
componentsPerAttribute: 3,
values: ptsArray,
normalize: false
}),
st: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 2,
values: sts,
normalize: false
}),
normal: new Cesium.GeometryAttribute({
componentDatatype: Cesium.ComponentDatatype.FLOAT,
componentsPerAttribute: 3,
values: normals,
normalize: false
})
},
primitiveType: Cesium.PrimitiveType.TRIANGLES,
boundingSphere: boundingSphere
}),
id: '' + Date.now()
});
var material = new Cesium.Material({
fabric: {
type: 'Image',
uniforms: {
image: '../images/Cesium_Logo_Color.jpg'
}
}
});
var appearance = new Cesium.MaterialAppearance({
material: material,
faceForward: true,
flat: true
});
var primitive = new Cesium.Primitive({
geometryInstances: [instance],
appearance: appearance,
asynchronous: false,
compressVertices: false,
cull: false,
debugShowBoundingVolume: false,
allowPicking: true
});
scene.primitives.add(primitive);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment