Created
June 25, 2015 23:18
-
-
Save chris-cooper/590465f9b0dadd7fc91b to your computer and use it in GitHub Desktop.
Cesium low level textured quad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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