当前位置:网站首页>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,
});
边栏推荐
猜你喜欢
2022.8.3
数据中台建设(十):数据安全管理
项目成本控制如何帮助项目成功?
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!
JS逆向入门学习之回收商网,手机号码简易加密解析
mysql索引
一文道清什么是SPL
Dry goods!Generative Model Evaluation and Diagnosis
随机推荐
leetcode: 529. 扫雷游戏
Egg framework usage (2)
Tanabata romantic date without overtime, RPA robot helps you get the job done
无题十一
无题九
mysql索引
手写柯里化 - toString 理解
开发常用手册链接分享
Egg framework usage (1)
MySQL使用聚合函数可以不搭配GROUP BY分组吗?
dotnet OpenXML parsing PPT charts Getting started with area charts
leetcode: 529. Minesweeper Game
正则表达式replaceAll()方法具有什么功能呢?
语音社交软件开发——充分发挥其价值
2022-08-01 回顾基础二叉树以及操作
Oracle临时表空间作用
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
static linking and dynamic linking
How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
无题十