在3D动画中保持恒定数量的可见圆 [英] Keep constant number of visible circles in 3D animation
问题描述
我创建了一个3D动画,其中白色圆圈的透视投影在2D计算机屏幕(GIF 1)上投影的假3D空间中随机移动。
因为我需要保持相同的数字可见的圆圈中,每当一个圆圈从框架中消失时,我就必须在框架中创建一个新的可见的圆圈。为此,我编写了这段代码:
-
首先,我创建了初始坐标和两个运动角度(球形坐标):
用于圆圈:
circle.position.xy = np.random。均匀(-25,25,size = 2)
z = np.random.uniform(near_z,far_z)
circle.position.z = z
circle.position.x * = z / -50
circle.position.y * = z / -50
circle.theta_deg = np.random.rand(1)* 360
circle.phi_deg = np.random.rand(1)* 360
theta_rad = circle.theta_deg * np.pi / 180
phi_rad = circle.phi_deg * np.pi / 180
circle.dx =速度* np.sin(-phi_rad-theta_rad)/ frameRate
circle.dy = -speed * np.cos(phi_rad + theta_rad)/ frameRate
.dz = -speed * np.cos(theta_rad)/ frameRate
-
然后,在播放动画的循环中,并更新每个圆圈的位置乐,我把这种情况放在了针对相同问题的相同答案上
我的状况有什么问题,如何检测从框架中消失的圆圈并在框架中重新创建一个圆圈?
解决方案根据您发布的代码,我只能看到两个兴趣点,而无需实际运行
(您能否在发布的代码周围添加一些粘合代码以使其可作为独立示例运行?)- 您只是在if条件下重设x和y位置,您也需要重设z,否则,它们将飞到相机后面或消失在距离
- 问题中的if条件链接的另一部分是:
sphere.position.z> = camera_z
,它将为您的代码转换为circle.position.z< = near_z
实际检测到在相机后面飞行的球体
两者都无法真正解释第二个gif中发生了什么。 ..
再三考虑:gif 2中的跳跃圆圈可能就是立即重置每一帧的圆圈,因为它们未正确重置为其z坐标保持不变。
I have created a 3D animation with a perspective projection of white circles moving randomly in a fake 3D space projected on a 2D computer screen (GIF 1).
Since I need to keep the same number of visible circles, every time a circle disappears from the frame, I have to create a new visible one within the frame. To do so, I have written this piece of code:
First I created initial coordinates and the two angles of movements (spherical coordinates):
for circle in circles: circle.position.xy = np.random.uniform(-25, 25, size=2) z = np.random.uniform(near_z, far_z) circle.position.z = z circle.position.x *= z/-50 circle.position.y *= z/-50 circle.theta_deg = np.random.rand(1) * 360 circle.phi_deg = np.random.rand(1) * 360 theta_rad = circle.theta_deg * np.pi / 180 phi_rad = circle.phi_deg* np.pi / 180 circle.dx = speed * np.sin(-phi_rad - theta_rad) / frameRate circle.dy = -speed * np.cos(phi_rad + theta_rad) / frameRate circle.dz = -speed * np.cos(theta_rad) / frameRate
Then, in the loop that plays the animation, and updates the position of each circle, I have put this condition following the same answer that was provided to the same kind of issue here:
max_dist = max(abs(circle.position.x),abs(circle.position.y)) limit_dist = 25 * abs((circle.position.z-near_z) / far_z) z_rel = np.random.uniform(near_z,far_z) if max_dist > limit_dist: circle.position.x = np.random.uniform(-25, 25) * z_rel/far_z circle.position.y = np.random.uniform(-25, 25) * z_rel/far_z
I got a weird result as shown in GIF 2
What is wrong with my condition and how can I detect a circle that disappears from the frame and recreate one inside the frame?
解决方案Based on the code you posted I can only see two points of interest without actually running it
(could you add some glue code around the code you posted to make it runnable as a standalone example?)- You are only resetting the x and y position in the if condition, you need to reset z too, otherwise, they will fly behind the camera or vanish in the distance
- the if-condition from the question you linked has another part:
sphere.position.z >= camera_z
which would translate for your code intocircle.position.z <= near_z
to actually detect spheres flying behind the camera
Both can't really explain what's happening in your second gif...
On second thought: the jumping circles in gif 2 could just be circles that get instantly reset each frame because they aren't properly reset as their z-coordinate stays the same.
这篇关于在3D动画中保持恒定数量的可见圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-