简体   繁体   English

Three.js 中 TrackballControls.target 的特殊行为

[英]Peculiar behavior of TrackballControls.target in Three.js

I am trying to create a simulation of 3D distribution of galaxies.我正在尝试创建 3D 星系分布的模拟。

The galaxies are points.星系是点。

question1.htm uses galaxydata1.txt to calculate and load the galaxy positions: question1.htm使用galaxydata1.txt计算和加载星系位置:

rawFile.open("GET", "galaxydata1.txt", false);

var parts = data[i].split("\t");

var D = parts[0];
var glon = parts[1]*3.1416/180;
var glat = parts[2]*3.1416/180;

var z = D*Math.sin(glat);
var xy = D*Math.cos(glat);
var x = xy*Math.cos(glon);
var y = xy*Math.sin(glon);

dotGeometry.vertices.push(new THREE.Vector3( x, y, z ));                

I want the simulation to work in resource-limited devices.我希望模拟在资源有限的设备中工作。 So, I figured that I can calculate the positions beforehand and save them in a file.所以,我想我可以预先计算位置并将它们保存在文件中。

I did this using write.htm to create galaxydata2.txt .我使用write.htm创建了 galaxydata2.txt

question2.htm uses galaxydata2.txt to load the galaxy positions: question2.htm使用galaxydata2.txt加载星系位置:

var parts = data[i].split(" ");

rawFile.open("GET", "galaxydata2.txt", false);

dotGeometry.vertices.push(new THREE.Vector3( parts[0], parts[1], parts[2] ));

It can be verified that the transformation is accurate because both question1.htm and question2.htm generate exactly the same models.可以验证转换是准确的,因为question1.htmquestion2.htm生成的模型完全相同。

Now, I have implemented a galaxy search function, which searches a galaxy by name and centers it using:现在,我实现了一个星系搜索 function,它按名称搜索一个星系并将其居中:

controls.target = dots.geometry.vertices[i];

You may try it by searching for m31 (one of the names for the Andromeda galaxy).您可以通过搜索 m31 (仙女座星系的名称之一)来尝试。

Bewilderingly, while the galaxy search function works in question1.htm , it doesn't work in question2.htm !令人困惑的是,虽然星系搜索 function 在question1.htm中有效,但在question2.htm中无效!

I have spent tens of hours since the last 2 days trying to find the cause, but cannot get head or tail of it.自从过去 2 天以来,我已经花了几十个小时试图找到原因,但无法找到原因。

Note that I have used exactly the same code to calculate the positions in both the cases.请注意,我使用完全相同的代码来计算这两种情况下的位置。

Most probably, I am missing something which would be immediately clear to the experts here.最有可能的是,我遗漏了一些在这里的专家会立即清楚的东西。

If / when possible, please guide me.如果/可能的话,请指导我。

Your dots.geometry.vertices in your search function have not been converted into floats.. they are all strings.您在搜索 function 中的 dots.geometry.vertices 尚未转换为浮点数..它们都是字符串。

1: n {x: "-34.10470732858122", y: "95.77578953486031", z: "-66.52906941334713 "} 2: n {x: "-23.203470164906907", y: "64.44921156287786", z: "-43.97565350543055 "} 3: n {x: "-22.228259825915906", y: "57.0117730686664", z: "-31.448405312168955 "} 1:n {x:“ -34.10470732858122”,y:“ 95.777578953486031”,Z:“ -66.5290694134713”} 2:n {x:x:x:x:“ -23.203347016490690160606074.644444444444444444444444444444444444444444444444444.” n {x:“-22.228259825915906”,y:“57.0117730686664”,z:“-31.448405312168955”}

So that will not work.所以这行不通。

You will need to do a.parseFloat on the data after you load it before stuffing it into the geometry.在将数据加载到几何体之前,您需要对数据执行 a.parseFloat 操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM