当前位置:网站首页>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,
});
边栏推荐
- Hundred lines of code launch red hearts, why programmers lose their girlfriends!
- 入门 Polkadot 平行链开发,看这一篇就够了
- js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)
- 浅析WSGI协议
- 歌词整理
- uniapp 连接ibeacon
- 项目成本控制如何帮助项目成功?
- IDEA performs the Test operation, resulting in duplicate data when data is inserted
- 19.服务器端会话技术Session
- 基于MindSpore高效完成图像分割,实现Dice!
猜你喜欢

MySQL transactions

【zeno】为zeno增加子模块/新节点的最小化的例子

NowCoderTOP35-40 - continuous update ing

Custom filters and interceptors implement ThreadLocal thread closure

七夕浪漫约会不加班,RPA机器人帮你搞定工作

【温度预警程序de开发】事件驱动模型实例运用

NowCoderTOP35-40——持续更新ing

Oracle temporary table space role

Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)

How to realize the short press and long press detection of the button?
随机推荐
What is the function of the regular expression replaceAll() method?
SD NAND Flash简介!
PHP operation mangoDb
2022/8/4 考试总结
IDEA performs the Test operation, resulting in duplicate data when data is inserted
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
MySQL之数据视图
egg框架使用(二)
three物体围绕一周呈球形排列
The difference between find, matches, lookingAt matching strings in matcher
无题三
无题十四
无题十
无题六
【Unity】【UGUI】【在屏幕上显示文本】
ffmpeg drawtext 添加文本水印
项目成本控制如何帮助项目成功?
Oracle临时表空间作用
The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
使用工具类把对象中的null值转换为空字符串(集合也可以使用)