三个js用dat gui改变球体的半径?

Mar*_*ist 3 webgl three.js

http://mrtn.ch/3D/13_06_27_gui_03.html

开始分析示例文件,现在我想知道如何使用 dat gui 滑块正确处理球体的半径。我可以移动滑块,但球体保持初始半径。我的代码有什么问题?

谢谢你的帮助!

yak*_*aku 7

SphereGeometry 在创建时仅使用半径参数。之后没有内置的方法来改变它。您需要手动修改几何顶点,或使用新半径创建新的 SphereGeometry。

或者,您可以仅缩放球体。在您的 updatesphere() 函数中,尝试如下操作:

radius = parameters.radius;
var scale = radius * 0.1; // adjust the multiplier to whatever
sphere.scale.x = scale;
sphere.scale.y = scale;
sphere.scale.z = scale;
Run Code Online (Sandbox Code Playgroud)