cesiumgs / cesium-threejs-experiment Goto Github PK
View Code? Open in Web Editor NEWA small example for using Three JS on Cesium to emulate a combined scene.
License: Apache License 2.0
A small example for using Three JS on Cesium to emulate a combined scene.
License: Apache License 2.0
while i use the new version of three.js such as :
import * as THREE from 'https://cdn.skypack.dev/three'
then can not add anything of three.js object in the canvas
The function lookAt() in the Object3D in revision 88 and above of three.js has been changed, so there caught a problem that mesh can't be seen.
then I modified: "centerHigh = new THREE.Vector3(centerHigh.x, centerHigh.y, centerHigh.z)" at line 205 in CesiumThree.js .and it works.
After all, Cartesian3 can't be used as Vector3 at all situations.
when i do as the readme shows, i got errors...as the title
This sample code refers to cesium-threejs-experiment,but the geometry disappeared when the camera changed.
class ThreeJSPrimitive {
constructor(options) {
this.geometry = null;
this.combineGeometry([options.geometryInstance]);
var geometry = new THREE.BufferGeometry();
geometry.addAttribute('position2DHigh', new THREE.BufferAttribute(this.geometry.attributes.position2DHigh.values, 3));
geometry.addAttribute('position2DLow', new THREE.BufferAttribute(this.geometry.attributes.position2DLow.values, 3));
geometry.setIndex(new THREE.BufferAttribute(this.geometry.indices, 1));
var vertexShader = `attribute vec3 position2DHigh;
attribute vec3 position2DLow;
varying vec3 v_pos;
void main(){
v_pos=position2DHigh.zxy+position2DLow.zxy;
gl_Position = projectionMatrix * modelViewMatrix * vec4(v_pos,1.0);
}`;
var fragmentShader = `varying vec3 v_pos;
void main(){
vec4 color;
if(v_pos.x>2000000.0){
color=vec4(1.0,1.0,1.0,1.0);
}else{
color=vec4(1.0,0.0,0.0,1.0);
}
gl_FragColor = color*color.a;
}`;
this.scene = new THREE.Scene();
this.material = new THREE.ShaderMaterial({
vertexShader: vertexShader,
fragmentShader: fragmentShader,
//side: THREE.DoubleSide,
//depthTest: false,
//blending: THREE.NoBlending,
depthWrite: false,
//transparent: true,
uniforms: {}
});
var cubeMesh = new THREE.Mesh(geometry, this.material);
this.scene.add(cubeMesh);
}
combineGeometry(geometris) {
var projection = new Cesium.WebMercatorProjection(Cesium.Ellipsoid.WGS84);
var result = Cesium.PrimitivePipeline.combineGeometry({
instances: geometris,
ellipsoid: projection.ellipsoid,
projection: projection,
elementIndexUintSupported: true,
scene3DOnly: false,
vertexCacheOptimize: false,
compressVertices: true,
modelMatrix: this.modelMatrix
});
this.geometry = result.geometries[0];
this.attributeLocations = result.attributeLocations;
this.modelMatrix = Cesium.Matrix4.clone(result.modelMatrix, this.modelMatrix);
}
update(frameState) {
if (!this.renderer) {
this.renderer = new THREE.WebGLRenderer({
canvas: document.getElementById('cube'),
alpha: true
});
this.renderer.autoClear = true;
}
var camera = frameState.camera;
if (!this.camera) {
this.camera = new THREE.PerspectiveCamera(camera.frustum.fov, camera.frustum.aspectRatio, camera.frustum.near, camera.frustum.far);
//this.camera = new THREE.Camera();
}
this.camera.projectionMatrix = new THREE.Matrix4().fromArray(camera.frustum.projectionMatrix);
this.camera.matrix = new THREE.Matrix4().getInverse(new THREE.Matrix4().fromArray(camera.viewMatrix));
this.camera.matrix.decompose(this.camera.position, this.camera.quaternion, this.camera.scale);
this.renderer.state.reset();
this.renderer.render(this.scene, this.camera);
}
}
var polygon = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(
Cesium.Cartesian3.fromDegreesArray(degreesArray)
),
height: maxHeight,
extrudedHeight: 0
});
var geometry = Cesium.PolygonGeometry.createGeometry(polygon);
var geoInstance = new Cesium.GeometryInstance({
geometry: geometry
});
var primitive3 = new ThreeJSPrimitive({
geometryInstance: geoInstance
});
viewer.scene.primitives.add(primitive3);
How does this project load the obj model and how to introduce the OBJLoader.js plug-in?
"Cesium + Three JS Experiment" should be changed to something like "cesium-threejs-experiment".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.