mirror of
https://gitee.com/blitheli/test-skybox.git
synced 2025-06-16 10:28:18 +00:00
修改代码,还剩py,pz,mz未校验
This commit is contained in:
parent
ac8482aa44
commit
aa58143113
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@ -2,6 +2,13 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Chrome",
|
||||
"request": "launch",
|
||||
"type": "chrome",
|
||||
"url": "http://localhost:5000",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "pwa-node",
|
||||
"request": "launch",
|
||||
|
@ -14,21 +14,29 @@ const CatalogSkybox = {
|
||||
CatalogSkybox.cubeXyzToImgUV = function(x, y, z) {
|
||||
let faceId, i, j;
|
||||
|
||||
if (x === -1) { // back
|
||||
j = (1.0 - y) / 2.0;
|
||||
if (x === -1) { // back,mx
|
||||
//j = (1.0 - y) / 2.0;
|
||||
//i = (1.0 + z) / 2.0;
|
||||
j = (1.0 + y) / 2.0;
|
||||
i = (1.0 + z) / 2.0;
|
||||
faceId = 0;
|
||||
} else if (y === -1) { // left
|
||||
i = (1.0 + x) / 2.0;
|
||||
j = (1.0 - z) / 2.0;
|
||||
faceId = 1;
|
||||
} else if (x === 1) { // front
|
||||
j = (1.0 - y) / 2.0;
|
||||
i = (1.0 - z) / 2.0;
|
||||
faceId = 2;
|
||||
} else if (y === 1) { // right
|
||||
} else if (y === -1) { // left,my
|
||||
//i = (1.0 + x) / 2.0;
|
||||
//j = (1.0 - z) / 2.0;
|
||||
i = (1.0 + x) / 2.0;
|
||||
j = (1.0 + z) / 2.0;
|
||||
faceId = 1;
|
||||
} else if (x === 1) { // front,px
|
||||
//j = (1.0 - y) / 2.0;
|
||||
//i = (1.0 - z) / 2.0;
|
||||
i = (1.0 + y) / 2.0;
|
||||
j = (1.0 - z) / 2.0;
|
||||
faceId = 2;
|
||||
} else if (y === 1) { // right,py
|
||||
//i = (1.0 + x) / 2.0;
|
||||
//j = (1.0 + z) / 2.0;
|
||||
i = (1.0 + x) / 2.0;
|
||||
j = (1.0 - z) / 2.0;
|
||||
faceId = 3;
|
||||
} else if (z === 1) { // top
|
||||
i = (1.0 + x) / 2.0;
|
||||
@ -157,6 +165,21 @@ CatalogSkybox.sphere2CubeXyz = function (theta, phi) {
|
||||
return { x, y, z };
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 由立方体盒子某个面的图片坐标转换为对应立方盒子面的坐标
|
||||
*
|
||||
|
@ -1,8 +1,7 @@
|
||||
import "./hipparcos_7_concise.js"
|
||||
import hipparcos_catalog from "./hipparcos_7_concise.js";
|
||||
import CatalogSkybox from "./CatalogSkybox.js";
|
||||
|
||||
function createSkyboxImage(faceId, width) {
|
||||
|
||||
function createSkyboxImage(faceId0, width) {
|
||||
// 恒星亮度(等级),亮度等级越小,亮度越大
|
||||
const magBright = -1;
|
||||
const magMedium = 7;
|
||||
@ -11,25 +10,25 @@ function createSkyboxImage(faceId, width) {
|
||||
const sizeBright = 5;
|
||||
const sizeMedium = 1;
|
||||
const sizeDim = 0.1;
|
||||
// 恒星透明度
|
||||
const translucentBright = 0.0;
|
||||
const translucentMedium = 0.25;
|
||||
const translucentDim = 0.8;
|
||||
// 恒星透明度(1为不透明,0为透明)
|
||||
const translucentBright = 1.0;
|
||||
const translucentMedium = 0.5;
|
||||
const translucentDim = 0.2;
|
||||
|
||||
const d2r = Math.PI / 180;
|
||||
|
||||
// 创建width*width的jpg格式的图片,背景为黑色,随机生成1000个像素点,颜色为白色,大小从1到5像素不等
|
||||
var canvas = document.createElement('canvas');
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = width;
|
||||
canvas.height = width;
|
||||
var context = canvas.getContext('2d');
|
||||
var context = canvas.getContext("2d");
|
||||
// 黑色背景
|
||||
context.fillStyle = 'black';
|
||||
context.fillStyle = "black";
|
||||
context.fillRect(0, 0, width, width);
|
||||
|
||||
// 循环hipparcos数据,hipparcos_catalog为数组
|
||||
for (var i = 0; i < hipparcos_catalog.length; i++) {
|
||||
var star = hipparcos_catalog[i];
|
||||
for (var id = 0; id < hipparcos_catalog.length; id++) {
|
||||
var star = hipparcos_catalog[id];
|
||||
var mag = star[1];
|
||||
var ra = star[2];
|
||||
var dec = star[3];
|
||||
@ -45,7 +44,7 @@ function createSkyboxImage(faceId, width) {
|
||||
let { x, y, z } = CatalogSkybox.sphere2CubeXyz(ra, dec);
|
||||
|
||||
// 转换为图片坐标(i,为横坐标,向右,[0,1]), (j为纵坐标,向下,[0,1])
|
||||
let { i, j, faceId0 } = CatalogSkybox.cubeXyzToImgUV(x, y, z);
|
||||
let { i, j, faceId } = CatalogSkybox.cubeXyzToImgUV(x, y, z);
|
||||
|
||||
if (faceId !== faceId0) {
|
||||
continue;
|
||||
@ -53,8 +52,25 @@ function createSkyboxImage(faceId, width) {
|
||||
|
||||
// 像素大小
|
||||
let size = sizeBright;
|
||||
if (mag > magMedium && mag <= magBright) {
|
||||
size = sizeMedium + (sizeBright - sizeMedium) * (mag - magMedium) / (magBright - magMedium);
|
||||
let translucent = translucentBright;
|
||||
if (mag > magBright && mag <= magMedium) {
|
||||
size =
|
||||
sizeMedium +
|
||||
((sizeBright - sizeMedium) * (mag - magMedium)) /
|
||||
(magBright - magMedium);
|
||||
translucent =
|
||||
translucentMedium +
|
||||
((translucentBright - translucentMedium) * (mag - magMedium)) /
|
||||
(magBright - magMedium);
|
||||
}
|
||||
// 亮度太暗,最小值
|
||||
else if (mag > magMedium) {
|
||||
size = sizeDim;
|
||||
translucent = translucentDim;
|
||||
}
|
||||
|
||||
if (mag < 1) {
|
||||
console.log(mag, size, translucent);
|
||||
}
|
||||
|
||||
// 图像坐标系下的坐标
|
||||
@ -67,13 +83,12 @@ function createSkyboxImage(faceId, width) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
// 画点
|
||||
context.fillStyle = 'white';
|
||||
// 画点,白色,带透明度
|
||||
context.fillStyle = `rgba(255,255,255,${translucent})`;
|
||||
context.fillRect(u, v, size, size);
|
||||
}
|
||||
|
||||
var dataUrl = canvas.toDataURL('image/jpeg');
|
||||
|
||||
var dataUrl = canvas.toDataURL("image/jpeg");
|
||||
|
||||
// 将这个图片插入到id为img1的img元素中
|
||||
//var img1 = document.getElementById('img1');
|
||||
@ -87,8 +102,6 @@ function createSkyboxImage(faceId, width) {
|
||||
// 将这个图片插入到id为img1的img元素中
|
||||
//var img1 = document.getElementById('img1');
|
||||
//img1.src = dataUrl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default createSkyboxImage;
|
File diff suppressed because one or more lines are too long
12
main.js
12
main.js
@ -9,8 +9,8 @@ console.log("Cesium 启动");
|
||||
const viewer = new Cesium.Viewer("cesiumContainer");
|
||||
|
||||
|
||||
const width = 4096;
|
||||
const px = createSkyboxImage(0, width);
|
||||
const width = 3522;
|
||||
const py = createSkyboxImage(2, width);
|
||||
/*
|
||||
const py = createImage( width);
|
||||
const pz = createImage( width);
|
||||
@ -40,18 +40,18 @@ viewer.scene.skyBox = new Cesium.SkyBox({
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
// 创建下载链接
|
||||
const link = document.createElement('a');
|
||||
link.download = 'image.jpg';
|
||||
link.href = px;
|
||||
link.download = 'px.jpg';
|
||||
link.href = py;
|
||||
|
||||
// 模拟点击下载链接
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// 显示帧率
|
||||
viewer.scene.debugShowFramesPerSecond = true;
|
Loading…
Reference in New Issue
Block a user