当前位置:网站首页>three objects are arranged in a spherical shape around the circumference
three objects are arranged in a spherical shape around the circumference
2022-08-05 10:02:00 【Jedi Hongbin】
圆形
思路: A circle based on the specified radius and the angle at which the object is required to exist Calculate the coordinates of the point on the circle
/** * Generates a composition around a circle from a model */
export const modelSurround = (model: Object3D, radius: number, count: number) => {
const group = new THREE.Group();
const onceAngle = (Math.PI * 2) / 360; //一度
const spaceAngle = (360 / count) * onceAngle; //The angle between two objects
for (let i = 1; i <= count; i++) {
const item = model.clone();
const x = Math.sin(spaceAngle * i) * radius;
const y = Math.cos(spaceAngle * i) * radius;
item.position.set(x, y, 0);
group.add(item);
}
return group;
};
调用
const model = new THREE.Mesh(
new THREE.BoxGeometry(3, 3, 3),
new THREE.MeshPhongMaterial({
color: 0xa88afa,
flatShading: true,
side: THREE.DoubleSide,
})
);
const roundModel = modelSurround(model, 10, 10);
scene.add(roundModel);
球形
/** * Generates a composition around a circle from a model */
export const modelSurround = (model: Object3D, radius: number, count: number, column: number = 1) => {
const group = new THREE.Group();
const onceAngle = (Math.PI * 2) / 360; //一度
const spaceAngle = (360 / count) * onceAngle; //The angle between two objects
for (let l = 0; l < column; l++) {
const columnGroup = new THREE.Group();
for (let i = 0; i < count; i++) {
const item = model.clone();
const x = Math.sin(spaceAngle * i) * radius;
const y = Math.cos(spaceAngle * i) * radius;
item.position.set(x, y, 0);
columnGroup.add(item);
}
columnGroup.rotation.y = (180 / column) * onceAngle * l;
group.add(columnGroup);
}
return group;
};
调用
const model = new THREE.Mesh(
new THREE.BoxGeometry(3, 3, 3),
new THREE.MeshPhongMaterial({
color: 0xa88afa,
flatShading: true,
side: THREE.DoubleSide,
})
);
const roundModel = modelSurround(model, 10, 20, 8);
roundModel.position.y = 70;
scene.add(roundModel);
Specify radians generate semicircle
/** * Generates a composition around a circle from a model */
export const modelSurround = ({
model,
radius,
count,
radian = 360,
column = 1,
}: {
/** * 模型 */
model: Object3D;
/** * 半径 */
radius: number;
/** * 重复数量 */
count: number;
/** * Arrange in radians by default360度(一周) * @default 360 */
radian?: number;
/** * 绕yThe axis rotates several columns360Columns are spherical 默认1列 * @default 1 */
column?: number;
}) => {
const group = new THREE.Group();
const onceAngle = (Math.PI * 2) / 360; //一度
const spaceAngle = (radian / count) * onceAngle; //The angle between two objects
for (let l = 0; l < column; l++) {
const columnGroup = new THREE.Group();
for (let i = 0; i < count; i++) {
const item = model.clone();
const x = Math.sin(spaceAngle * i) * radius;
const y = Math.cos(spaceAngle * i) * radius;
item.position.set(x, y, 0);
columnGroup.add(item);
}
columnGroup.rotation.y = (180 / column) * onceAngle * l;
group.add(columnGroup);
}
return group;
};
调用
const model = new THREE.Mesh(
new THREE.BoxGeometry(3, 3, 3),
new THREE.MeshPhongMaterial({
color: 0xa88afa,
flatShading: true,
side: THREE.DoubleSide,
})
);
const roundModel = modelSurround({
model, radius: 10, count: 10, radian: 90, column: 1 });
roundModel.position.y = 70;
scene.add(roundModel);
加入 Multiple models randomly choose permutations
/** * Generates a composition around a circle from a model */
export const modelSurround = ({
model,
radius,
count,
radian = 360,
column = 1,
syncRotation = false,
}: {
/** * 模型 Or a function that returns a model */
model: Object3D | (() => Object3D);
/** * 半径 */
radius: number;
/** * 重复数量 */
count: number;
/** * Arrange in radians by default360度(一周) * @default 360 */
radian?: number;
/** * 绕yThe axis rotates several columns360Columns are spherical 默认1列 * @default 1 */
column?: number;
/** * The rotation angle rotates synchronously * @default false */
syncRotation?: boolean;
}) => {
const group = new THREE.Group();
const onceAngle = (Math.PI * 2) / 360; //一度
const spaceAngle = (radian / count) * onceAngle; //The angle between two objects
for (let l = 0; l < column; l++) {
const columnGroup = new THREE.Group();
for (let i = 0; i < count; i++) {
const item = typeof model === "function" ? model().clone() : model.clone();
const x = Math.sin(spaceAngle * i) * radius;
const y = Math.cos(spaceAngle * i) * radius;
item.position.set(x, y, 0);
columnGroup.add(item);
syncRotation && (item.rotation.z = spaceAngle * -i);
}
columnGroup.rotation.y = (360 / column) * onceAngle * l;
group.add(columnGroup);
}
return group;
};
调用 Pass in a randomly generated model
/** * Get the three brick model */
const one = gltf.scene.getObjectByName("1");
const two = gltf.scene.getObjectByName("2");
const three = gltf.scene.getObjectByName("3");
if (!one || !two || !three) return;
const provider = [one, two, three];
const {
length: count } = provider;
const space = getSize(one).z + 1;
const blocksGroup = modelSurround({
model: () => {
const row = new Group();
for (let i = 0; i < count; i++) {
//A random model is obtained
const model = provider[Math.floor(Math.random() * count)].clone();
row.add(model);
//这样 0,1,2 是 0 3,4,5 是 1 The orderly arrangement keeps the coordinates consistent
const column = Math.floor(i / count);
const x = column * space;
const y = 0;
const z = (i % count) * space;
model.position.set(x, y, z);
}
return row;
},
count: 30,
radius: 460 * 4,
radian: 6,
syncRotation: true,
column: 4,
});
边栏推荐
猜你喜欢
随机推荐
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
【温度预警程序de开发】事件驱动模型实例运用
5. Deploy the web project to the cloud server
PHP 操作mangoDb
企业的数字化转型到底是否可以买来?
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
上海控安技术成果入选市经信委《2021年上海市网络安全产业创新攻关成果目录》
Why are RELTABLESPACE values 0 for many tables displayed in sys_class?
IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
手把手教你纯c实现异常捕获try-catch组件
Meteorological data processing example - matlab string cutting matching and R language date matching (data splicing)
CCVR eases heterogeneous federated learning based on classifier calibration
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
QSS 选择器
2.4G无线收发模块的应用
首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
Jenkins使用手册(2) —— 软件配置
使用工具类把对象中的null值转换为空字符串(集合也可以使用)
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
PAT Level B - B1021 Single Digit Statistics (15)