|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
let camera, scene, renderer;
|
|
|
|
|
|
-const shadowHasAlpha = false //阴影是否考虑光透过透明材质
|
|
|
+const shadowHasAlpha = false //阴影是否考虑光透过透明材质
|
|
|
|
|
|
const planeGeo = new THREE.PlaneBufferGeometry(1, 1)
|
|
|
const raycaster = new THREE.Raycaster(); raycaster.linePrecision = 0;//不检测boxHelper
|
|
@@ -93,7 +93,7 @@ var isMobile = (function() {
|
|
|
)
|
|
|
)
|
|
|
})()
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
var Viewer = function (index, dom) {
|
|
@@ -105,7 +105,7 @@ var Viewer = function (index, dom) {
|
|
|
this.control.latMin = this.control.latMax = 0
|
|
|
|
|
|
|
|
|
- //this.control.target.set(0,-1,0)
|
|
|
+ //this.control.target.set(0,-1,0)
|
|
|
this.setRenderer()
|
|
|
|
|
|
this.scene = new THREE.Scene;
|
|
@@ -127,7 +127,7 @@ var Viewer = function (index, dom) {
|
|
|
this.animate()
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
+/*
|
|
|
同一时间,视线范围不能同时出现两张卡。也就是分布要根据视角范围变化,但是如果浏览器变宽导致的出现两张卡不算。
|
|
|
|
|
|
*/
|
|
@@ -146,16 +146,16 @@ Viewer.prototype.preLoadCards = function () {
|
|
|
let add = () => {
|
|
|
if (document.hidden) return
|
|
|
let count = this.getCount()
|
|
|
- let hopeCount = Density * (this.renderer.domElement.clientWidth * this.renderer.domElement.clientHeight) / 100000
|
|
|
-
|
|
|
- if(count < hopeCount){
|
|
|
+ let hopeCount = Density * (this.renderer.domElement.clientWidth * this.renderer.domElement.clientHeight) / 100000
|
|
|
+
|
|
|
+ if(count < hopeCount){
|
|
|
let ratio = count / hopeCount
|
|
|
-
|
|
|
- if(Math.random() > ratio){
|
|
|
+
|
|
|
+ if(Math.random() > ratio){
|
|
|
this.addCard()
|
|
|
}
|
|
|
}
|
|
|
- setTimeout(add, 100/* 40000 * Math.random() * this.getDensity() */) //当前视野中密度越小 添加越频繁
|
|
|
+ setTimeout(add, 200/* 40000 * Math.random() * this.getDensity() */) //当前视野中密度越小 添加越频繁
|
|
|
}
|
|
|
add()
|
|
|
|
|
@@ -182,20 +182,24 @@ Viewer.prototype.getCount = function () {
|
|
|
let count = this.cardGroup.children.filter(card => {
|
|
|
return frustum.containsPoint(card.position)
|
|
|
}).length
|
|
|
-
|
|
|
+
|
|
|
return count
|
|
|
}
|
|
|
|
|
|
|
|
|
Viewer.prototype.addCard = function (around) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ let cardOldIndex = 0
|
|
|
+
|
|
|
let cardIndex = Math.floor(cardNames.length * Math.random())
|
|
|
+ if(cardIndex === cardOldIndex){
|
|
|
+ cardIndex = Math.floor(60 * Math.random())
|
|
|
+ }
|
|
|
+ cardOldIndex = cardIndex
|
|
|
common.loadTexture(cardNames[cardIndex], (map) => {
|
|
|
|
|
|
|
|
|
- /* let card = new THREE.Mesh(planeGeo, new THREE.MeshBasicMaterial({
|
|
|
+ /* let card = new THREE.Mesh(planeGeo, new THREE.MeshBasicMaterial({
|
|
|
map,
|
|
|
transparent:true, opacity:0,side:2
|
|
|
})) */
|
|
@@ -227,7 +231,7 @@ Viewer.prototype.addCard = function (around) {
|
|
|
let direction, far = setting.cards.far
|
|
|
if (around) {//在四周所有方向都可生成,在一开始时需要
|
|
|
let n = 0.6//范围0-1 越大越可能接近相机
|
|
|
- far = far * (1 - n * Math.random()) //靠近一点
|
|
|
+ far = far * (1 - n * Math.random()) //靠近一点
|
|
|
direction = new THREE.Vector3(0, 0, -1).applyEuler(new THREE.Euler(0, Math.PI * 2 * Math.random(), 0))
|
|
|
} else {//仅在相机前方生成,因为相机往这个方向移动,最前方空缺
|
|
|
|
|
@@ -268,7 +272,7 @@ Viewer.prototype.removeCards = function () {//移除超过bound的卡
|
|
|
}
|
|
|
|
|
|
|
|
|
-Viewer.prototype.update = function (deltaTime) {//绘制的时候同时更新
|
|
|
+Viewer.prototype.update = function (deltaTime) {//绘制的时候同时更新
|
|
|
|
|
|
this.setSize()
|
|
|
this.control.update(deltaTime)
|
|
@@ -324,7 +328,7 @@ Viewer.prototype.setRenderer = function () {
|
|
|
this.renderer.shadowMap.enabled = true
|
|
|
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap
|
|
|
console.log("ContextCreated")
|
|
|
- //this.emit(Events.ContextCreated)
|
|
|
+ //this.emit(Events.ContextCreated)
|
|
|
} catch (e) {
|
|
|
console.error("Unable to create a WebGL rendering context")
|
|
|
}
|
|
@@ -339,7 +343,7 @@ Viewer.prototype.hasChanged = function () {//判断画面是否改变了,改
|
|
|
projectionMatrix: this.camera.projectionMatrix.clone(),//worldMatrix在control时归零了所以不用了吧,用position和qua也一样
|
|
|
position: this.camera.position.clone(),
|
|
|
quaternion: this.camera.quaternion.clone(),
|
|
|
- //mouse: this.mouse.clone(),
|
|
|
+ //mouse: this.mouse.clone(),
|
|
|
fov: this.camera.fov
|
|
|
};
|
|
|
}.bind(this)
|
|
@@ -355,7 +359,7 @@ Viewer.prototype.hasChanged = function () {//判断画面是否改变了,改
|
|
|
!this.camera.quaternion.equals(this.previousState.quaternion)
|
|
|
|
|
|
|
|
|
- var changed = cameraChanged //|| !this.mouse.equals(this.previousState.mouse)
|
|
|
+ var changed = cameraChanged //|| !this.mouse.equals(this.previousState.mouse)
|
|
|
|
|
|
copy()
|
|
|
|
|
@@ -399,7 +403,7 @@ Viewer.prototype.animate = function () {
|
|
|
|
|
|
|
|
|
Viewer.prototype.onPointerMove = function (event, force) {
|
|
|
-
|
|
|
+
|
|
|
if (event.isPrimary === false) return;
|
|
|
|
|
|
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|