当前位置:网站首页>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,
});
边栏推荐
- Oracle temporary table space role
- 2022-08-01 Review the basic binary tree and operations
- 茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
- Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
- Advanced usage of C language
- js hijacks the array push method
- 什么是CRM决策分析管理?
- 无题九
- How to realize the short press and long press detection of the button?
- PAT乙级-B1020 月饼(25)
猜你喜欢

阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!

5. Deploy the web project to the cloud server

Oracle temporary table space role

Seata source code analysis: initialization process of TM RM client

Tanabata romantic date without overtime, RPA robot helps you get the job done

leetcode: 529. Minesweeper Game

什么是CRM决策分析管理?

19. Server-side session technology Session

mysql索引

哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
随机推荐
欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(下)
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
Dry goods!Generative Model Evaluation and Diagnosis
歌词整理
LeetCode 216. Combined Sum III (2022.08.04)
19.服务器端会话技术Session
无题一
leetcode: 529. 扫雷游戏
2022.8.3
语音社交软件开发——充分发挥其价值
Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
The Seven Weapons of Programmers
hcip BGP 增强实验
What is CRM Decision Analysis Management?
使用工具类把对象中的null值转换为空字符串(集合也可以使用)
Two-table query average grouping in sql server
Open Source Summer | How OpenHarmony Query Device Type (eTS)
PAT Grade B-B1020 Mooncake(25)
Why are RELTABLESPACE values 0 for many tables displayed in sys_class?