Is it possible to get some shape properties from a mesh?
I want to get the shape and the diameter from an existing sphere mesh:
const sphere = Mesh.CreateSphere('sphere1', 16, 2, scene)
const shape = sphere.somewhere.shape // Expect it to be 'sphere'
const diameter = sphere.somewhere.diameter // Expect it to be 2
Thanks
Gijs
May 22, 2020, 1:30pm
2
Hello and wlcome @yannick ,
sphere.somewhere.diameter
Should IMO be possible with:
sphere.getBoundingInfo().boundingSphere.radius
But unfortunately it currently gives the bounding sphere of the bounding box, I’ll try to fix that.
As for the shape
property, it’s not possible like that as you can see in the source file:
import { Vector4, Vector3, Matrix } from "../../Maths/math.vector";
import { Mesh, _CreationDataStorage } from "../mesh";
import { VertexData } from "../mesh.vertexData";
import { Scene } from "../../scene";
import { Nullable } from '../../types';
VertexData.CreateSphere = function(options: { segments?: number, diameter?: number, diameterX?: number, diameterY?: number, diameterZ?: number, arc?: number, slice?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {
var segments: number = options.segments || 32;
var diameterX: number = options.diameterX || options.diameter || 1;
var diameterY: number = options.diameterY || options.diameter || 1;
var diameterZ: number = options.diameterZ || options.diameter || 1;
var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
var slice: number = options.slice && (options.slice <= 0) ? 1.0 : options.slice || 1.0;
var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
var radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);
var totalZRotationSteps = 2 + segments;
var totalYRotationSteps = 2 * totalZRotationSteps;
This file has been truncated. show original
It just creates new sphere vertex data (line 66), and applies it to a generic new Mesh
(line 117).
1 Like
It is not possible, unless you keep a reference to those parameters. A mesh is an abstract container for vertex data, it doesn’t store the construction parameters
1 Like
Thanks @Gijs and @RaananW !
Both answers helped a lot
2 Likes