修改代码,还剩py,pz,mz未校验

This commit is contained in:
blitheli 2024-08-13 22:39:49 +08:00
parent ac8482aa44
commit aa58143113
5 changed files with 142 additions and 97 deletions

7
.vscode/launch.json vendored
View File

@ -2,6 +2,13 @@
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "http://localhost:5000",
"webRoot": "${workspaceFolder}"
},
{ {
"type": "pwa-node", "type": "pwa-node",
"request": "launch", "request": "launch",

View File

@ -14,21 +14,29 @@ const CatalogSkybox = {
CatalogSkybox.cubeXyzToImgUV = function(x, y, z) { CatalogSkybox.cubeXyzToImgUV = function(x, y, z) {
let faceId, i, j; let faceId, i, j;
if (x === -1) { // back if (x === -1) { // back,mx
j = (1.0 - y) / 2.0; //j = (1.0 - y) / 2.0;
//i = (1.0 + z) / 2.0;
j = (1.0 + y) / 2.0;
i = (1.0 + z) / 2.0; i = (1.0 + z) / 2.0;
faceId = 0; faceId = 0;
} else if (y === -1) { // left } else if (y === -1) { // left,my
i = (1.0 + x) / 2.0; //i = (1.0 + x) / 2.0;
j = (1.0 - z) / 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
i = (1.0 + x) / 2.0; i = (1.0 + x) / 2.0;
j = (1.0 + z) / 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; faceId = 3;
} else if (z === 1) { // top } else if (z === 1) { // top
i = (1.0 + x) / 2.0; i = (1.0 + x) / 2.0;
@ -157,6 +165,21 @@ CatalogSkybox.sphere2CubeXyz = function (theta, phi) {
return { x, y, z }; return { x, y, z };
} }
/** /**
* 由立方体盒子某个面的图片坐标转换为对应立方盒子面的坐标 * 由立方体盒子某个面的图片坐标转换为对应立方盒子面的坐标
* *

View File

@ -1,8 +1,7 @@
import "./hipparcos_7_concise.js" import hipparcos_catalog from "./hipparcos_7_concise.js";
import CatalogSkybox from "./CatalogSkybox.js"; import CatalogSkybox from "./CatalogSkybox.js";
function createSkyboxImage(faceId, width) { function createSkyboxImage(faceId0, width) {
// 恒星亮度(等级),亮度等级越小,亮度越大 // 恒星亮度(等级),亮度等级越小,亮度越大
const magBright = -1; const magBright = -1;
const magMedium = 7; const magMedium = 7;
@ -11,25 +10,25 @@ function createSkyboxImage(faceId, width) {
const sizeBright = 5; const sizeBright = 5;
const sizeMedium = 1; const sizeMedium = 1;
const sizeDim = 0.1; const sizeDim = 0.1;
// 恒星透明度 // 恒星透明度(1为不透明0为透明)
const translucentBright = 0.0; const translucentBright = 1.0;
const translucentMedium = 0.25; const translucentMedium = 0.5;
const translucentDim = 0.8; const translucentDim = 0.2;
const d2r = Math.PI / 180; const d2r = Math.PI / 180;
// 创建width*width的jpg格式的图片背景为黑色随机生成1000个像素点颜色为白色大小从1到5像素不等 // 创建width*width的jpg格式的图片背景为黑色随机生成1000个像素点颜色为白色大小从1到5像素不等
var canvas = document.createElement('canvas'); var canvas = document.createElement("canvas");
canvas.width = width; canvas.width = width;
canvas.height = 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); context.fillRect(0, 0, width, width);
// 循环hipparcos数据,hipparcos_catalog为数组 // 循环hipparcos数据,hipparcos_catalog为数组
for (var i = 0; i < hipparcos_catalog.length; i++) { for (var id = 0; id < hipparcos_catalog.length; id++) {
var star = hipparcos_catalog[i]; var star = hipparcos_catalog[id];
var mag = star[1]; var mag = star[1];
var ra = star[2]; var ra = star[2];
var dec = star[3]; var dec = star[3];
@ -45,7 +44,7 @@ function createSkyboxImage(faceId, width) {
let { x, y, z } = CatalogSkybox.sphere2CubeXyz(ra, dec); let { x, y, z } = CatalogSkybox.sphere2CubeXyz(ra, dec);
// 转换为图片坐标i,为横坐标,向右,[0,1]), (j为纵坐标,向下,[0,1]) // 转换为图片坐标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) { if (faceId !== faceId0) {
continue; continue;
@ -53,8 +52,25 @@ function createSkyboxImage(faceId, width) {
// 像素大小 // 像素大小
let size = sizeBright; let size = sizeBright;
if (mag > magMedium && mag <= magBright) { let translucent = translucentBright;
size = sizeMedium + (sizeBright - sizeMedium) * (mag - magMedium) / (magBright - magMedium); 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; v = 0;
} }
// 画点 // 画点,白色,带透明度
context.fillStyle = 'white'; context.fillStyle = `rgba(255,255,255,${translucent})`;
context.fillRect(u, v, size, size); context.fillRect(u, v, size, size);
} }
var dataUrl = canvas.toDataURL('image/jpeg'); var dataUrl = canvas.toDataURL("image/jpeg");
// 将这个图片插入到id为img1的img元素中 // 将这个图片插入到id为img1的img元素中
//var img1 = document.getElementById('img1'); //var img1 = document.getElementById('img1');
@ -87,8 +102,6 @@ function createSkyboxImage(faceId, width) {
// 将这个图片插入到id为img1的img元素中 // 将这个图片插入到id为img1的img元素中
//var img1 = document.getElementById('img1'); //var img1 = document.getElementById('img1');
//img1.src = dataUrl; //img1.src = dataUrl;
} }
export default createSkyboxImage; export default createSkyboxImage;

File diff suppressed because one or more lines are too long

12
main.js
View File

@ -9,8 +9,8 @@ console.log("Cesium 启动");
const viewer = new Cesium.Viewer("cesiumContainer"); const viewer = new Cesium.Viewer("cesiumContainer");
const width = 4096; const width = 3522;
const px = createSkyboxImage(0, width); const py = createSkyboxImage(2, width);
/* /*
const py = createImage( width); const py = createImage( width);
const pz = createImage( width); const pz = createImage( width);
@ -40,18 +40,18 @@ viewer.scene.skyBox = new Cesium.SkyBox({
}, },
}); });
/*
// 创建下载链接 // 创建下载链接
const link = document.createElement('a'); const link = document.createElement('a');
link.download = 'image.jpg'; link.download = 'px.jpg';
link.href = px; link.href = py;
// 模拟点击下载链接 // 模拟点击下载链接
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
*/
// 显示帧率 // 显示帧率
viewer.scene.debugShowFramesPerSecond = true; viewer.scene.debugShowFramesPerSecond = true;