subMesh.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. import { Nullable, IndicesArray, DeepImmutable, FloatArray } from "../types";
  2. import { Matrix, Vector3 } from "../Maths/math.vector";
  3. import { Engine } from "../Engines/engine";
  4. import { VertexBuffer } from "./buffer";
  5. import { IntersectionInfo } from "../Collisions/intersectionInfo";
  6. import { ICullable, BoundingInfo } from "../Culling/boundingInfo";
  7. import { Effect } from "../Materials/effect";
  8. import { Constants } from "../Engines/constants";
  9. import { DataBuffer } from './dataBuffer';
  10. import { extractMinAndMaxIndexed } from '../Maths/math.functions';
  11. import { Plane } from '../Maths/math.plane';
  12. declare type Collider = import("../Collisions/collider").Collider;
  13. declare type Material = import("../Materials/material").Material;
  14. declare type MaterialDefines = import("../Materials/materialDefines").MaterialDefines;
  15. declare type MultiMaterial = import("../Materials/multiMaterial").MultiMaterial;
  16. declare type AbstractMesh = import("./abstractMesh").AbstractMesh;
  17. declare type Mesh = import("./mesh").Mesh;
  18. declare type Ray = import("../Culling/ray").Ray;
  19. declare type TrianglePickingPredicate = import("../Culling/ray").TrianglePickingPredicate;
  20. /**
  21. * Defines a subdivision inside a mesh
  22. */
  23. export class SubMesh implements ICullable {
  24. /** @hidden */
  25. public _materialDefines: Nullable<MaterialDefines> = null;
  26. /** @hidden */
  27. public _materialEffect: Nullable<Effect> = null;
  28. /** @hidden */
  29. public _effectOverride: Nullable<Effect> = null;
  30. /**
  31. * Gets material defines used by the effect associated to the sub mesh
  32. */
  33. public get materialDefines(): Nullable<MaterialDefines> {
  34. return this._materialDefines;
  35. }
  36. /**
  37. * Sets material defines used by the effect associated to the sub mesh
  38. */
  39. public set materialDefines(defines: Nullable<MaterialDefines>) {
  40. this._materialDefines = defines;
  41. }
  42. /**
  43. * Gets associated effect
  44. */
  45. public get effect(): Nullable<Effect> {
  46. return this._effectOverride ?? this._materialEffect;
  47. }
  48. /**
  49. * Sets associated effect (effect used to render this submesh)
  50. * @param effect defines the effect to associate with
  51. * @param defines defines the set of defines used to compile this effect
  52. */
  53. public setEffect(effect: Nullable<Effect>, defines: Nullable<MaterialDefines> = null) {
  54. if (this._materialEffect === effect) {
  55. if (!effect) {
  56. this._materialDefines = null;
  57. }
  58. return;
  59. }
  60. this._materialDefines = defines;
  61. this._materialEffect = effect;
  62. }
  63. /** @hidden */
  64. public _linesIndexCount: number = 0;
  65. private _mesh: AbstractMesh;
  66. private _renderingMesh: Mesh;
  67. private _boundingInfo: BoundingInfo;
  68. private _linesIndexBuffer: Nullable<DataBuffer> = null;
  69. /** @hidden */
  70. public _lastColliderWorldVertices: Nullable<Vector3[]> = null;
  71. /** @hidden */
  72. public _trianglePlanes: Plane[];
  73. /** @hidden */
  74. public _lastColliderTransformMatrix: Nullable<Matrix> = null;
  75. /** @hidden */
  76. public _renderId = 0;
  77. /** @hidden */
  78. public _alphaIndex: number = 0;
  79. /** @hidden */
  80. public _distanceToCamera: number = 0;
  81. /** @hidden */
  82. public _id: number;
  83. private _currentMaterial: Nullable<Material> = null;
  84. /**
  85. * Add a new submesh to a mesh
  86. * @param materialIndex defines the material index to use
  87. * @param verticesStart defines vertex index start
  88. * @param verticesCount defines vertices count
  89. * @param indexStart defines index start
  90. * @param indexCount defines indices count
  91. * @param mesh defines the parent mesh
  92. * @param renderingMesh defines an optional rendering mesh
  93. * @param createBoundingBox defines if bounding box should be created for this submesh
  94. * @returns the new submesh
  95. */
  96. public static AddToMesh(materialIndex: number, verticesStart: number, verticesCount: number, indexStart: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true): SubMesh {
  97. return new SubMesh(materialIndex, verticesStart, verticesCount, indexStart, indexCount, mesh, renderingMesh, createBoundingBox);
  98. }
  99. /**
  100. * Creates a new submesh
  101. * @param materialIndex defines the material index to use
  102. * @param verticesStart defines vertex index start
  103. * @param verticesCount defines vertices count
  104. * @param indexStart defines index start
  105. * @param indexCount defines indices count
  106. * @param mesh defines the parent mesh
  107. * @param renderingMesh defines an optional rendering mesh
  108. * @param createBoundingBox defines if bounding box should be created for this submesh
  109. * @param addToMesh defines a boolean indicating that the submesh must be added to the mesh.subMeshes array (true by default)
  110. */
  111. constructor(
  112. /** the material index to use */
  113. public materialIndex: number,
  114. /** vertex index start */
  115. public verticesStart: number,
  116. /** vertices count */
  117. public verticesCount: number,
  118. /** index start */
  119. public indexStart: number,
  120. /** indices count */
  121. public indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox: boolean = true, addToMesh = true) {
  122. this._mesh = mesh;
  123. this._renderingMesh = renderingMesh || <Mesh>mesh;
  124. if (addToMesh) {
  125. mesh.subMeshes.push(this);
  126. }
  127. this._trianglePlanes = [];
  128. this._id = mesh.subMeshes.length - 1;
  129. if (createBoundingBox) {
  130. this.refreshBoundingInfo();
  131. mesh.computeWorldMatrix(true);
  132. }
  133. }
  134. /**
  135. * Returns true if this submesh covers the entire parent mesh
  136. * @ignorenaming
  137. */
  138. public get IsGlobal(): boolean {
  139. return (this.verticesStart === 0 && this.verticesCount === this._mesh.getTotalVertices());
  140. }
  141. /**
  142. * Returns the submesh BoudingInfo object
  143. * @returns current bounding info (or mesh's one if the submesh is global)
  144. */
  145. public getBoundingInfo(): BoundingInfo {
  146. if (this.IsGlobal) {
  147. return this._mesh.getBoundingInfo();
  148. }
  149. return this._boundingInfo;
  150. }
  151. /**
  152. * Sets the submesh BoundingInfo
  153. * @param boundingInfo defines the new bounding info to use
  154. * @returns the SubMesh
  155. */
  156. public setBoundingInfo(boundingInfo: BoundingInfo): SubMesh {
  157. this._boundingInfo = boundingInfo;
  158. return this;
  159. }
  160. /**
  161. * Returns the mesh of the current submesh
  162. * @return the parent mesh
  163. */
  164. public getMesh(): AbstractMesh {
  165. return this._mesh;
  166. }
  167. /**
  168. * Returns the rendering mesh of the submesh
  169. * @returns the rendering mesh (could be different from parent mesh)
  170. */
  171. public getRenderingMesh(): Mesh {
  172. return this._renderingMesh;
  173. }
  174. /**
  175. * Returns the replacement mesh of the submesh
  176. * @returns the replacement mesh (could be different from parent mesh)
  177. */
  178. public getReplacementMesh(): Nullable<AbstractMesh> {
  179. return this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;
  180. }
  181. /**
  182. * Returns the effective mesh of the submesh
  183. * @returns the effective mesh (could be different from parent mesh)
  184. */
  185. public getEffectiveMesh(): AbstractMesh {
  186. const replacementMesh = this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : null;
  187. return replacementMesh ? replacementMesh : this._renderingMesh;
  188. }
  189. /**
  190. * Returns the submesh material
  191. * @returns null or the current material
  192. */
  193. public getMaterial(): Nullable<Material> {
  194. var rootMaterial = this._renderingMesh.material;
  195. if (rootMaterial === null || rootMaterial === undefined) {
  196. return this._mesh.getScene().defaultMaterial;
  197. } else if ((<MultiMaterial>rootMaterial).getSubMaterial) {
  198. var multiMaterial = <MultiMaterial>rootMaterial;
  199. var effectiveMaterial = multiMaterial.getSubMaterial(this.materialIndex);
  200. if (this._currentMaterial !== effectiveMaterial) {
  201. this._currentMaterial = effectiveMaterial;
  202. this._materialDefines = null;
  203. }
  204. return effectiveMaterial;
  205. }
  206. return rootMaterial;
  207. }
  208. // Methods
  209. /**
  210. * Sets a new updated BoundingInfo object to the submesh
  211. * @param data defines an optional position array to use to determine the bounding info
  212. * @returns the SubMesh
  213. */
  214. public refreshBoundingInfo(data: Nullable<FloatArray> = null): SubMesh {
  215. this._lastColliderWorldVertices = null;
  216. if (this.IsGlobal || !this._renderingMesh || !this._renderingMesh.geometry) {
  217. return this;
  218. }
  219. if (!data) {
  220. data = this._renderingMesh.getVerticesData(VertexBuffer.PositionKind);
  221. }
  222. if (!data) {
  223. this._boundingInfo = this._mesh.getBoundingInfo();
  224. return this;
  225. }
  226. var indices = <IndicesArray>this._renderingMesh.getIndices();
  227. var extend: { minimum: Vector3, maximum: Vector3 };
  228. //is this the only submesh?
  229. if (this.indexStart === 0 && this.indexCount === indices.length) {
  230. let boundingInfo = this._renderingMesh.getBoundingInfo();
  231. //the rendering mesh's bounding info can be used, it is the standard submesh for all indices.
  232. extend = { minimum: boundingInfo.minimum.clone(), maximum: boundingInfo.maximum.clone() };
  233. } else {
  234. extend = extractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount, this._renderingMesh.geometry.boundingBias);
  235. }
  236. if (this._boundingInfo) {
  237. this._boundingInfo.reConstruct(extend.minimum, extend.maximum);
  238. }
  239. else {
  240. this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);
  241. }
  242. return this;
  243. }
  244. /** @hidden */
  245. public _checkCollision(collider: Collider): boolean {
  246. let boundingInfo = this.getBoundingInfo();
  247. return boundingInfo._checkCollision(collider);
  248. }
  249. /**
  250. * Updates the submesh BoundingInfo
  251. * @param world defines the world matrix to use to update the bounding info
  252. * @returns the submesh
  253. */
  254. public updateBoundingInfo(world: DeepImmutable<Matrix>): SubMesh {
  255. let boundingInfo = this.getBoundingInfo();
  256. if (!boundingInfo) {
  257. this.refreshBoundingInfo();
  258. boundingInfo = this.getBoundingInfo();
  259. }
  260. if (boundingInfo) {
  261. (<BoundingInfo>boundingInfo).update(world);
  262. }
  263. return this;
  264. }
  265. /**
  266. * True is the submesh bounding box intersects the frustum defined by the passed array of planes.
  267. * @param frustumPlanes defines the frustum planes
  268. * @returns true if the submesh is intersecting with the frustum
  269. */
  270. public isInFrustum(frustumPlanes: Plane[]): boolean {
  271. let boundingInfo = this.getBoundingInfo();
  272. if (!boundingInfo) {
  273. return false;
  274. }
  275. return boundingInfo.isInFrustum(frustumPlanes, this._mesh.cullingStrategy);
  276. }
  277. /**
  278. * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes
  279. * @param frustumPlanes defines the frustum planes
  280. * @returns true if the submesh is inside the frustum
  281. */
  282. public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {
  283. let boundingInfo = this.getBoundingInfo();
  284. if (!boundingInfo) {
  285. return false;
  286. }
  287. return boundingInfo.isCompletelyInFrustum(frustumPlanes);
  288. }
  289. /**
  290. * Renders the submesh
  291. * @param enableAlphaMode defines if alpha needs to be used
  292. * @returns the submesh
  293. */
  294. public render(enableAlphaMode: boolean): SubMesh {
  295. this._renderingMesh.render(this, enableAlphaMode, this._mesh._internalAbstractMeshDataInfo._actAsRegularMesh ? this._mesh : undefined);
  296. return this;
  297. }
  298. /**
  299. * @hidden
  300. */
  301. public _getLinesIndexBuffer(indices: IndicesArray, engine: Engine): DataBuffer {
  302. if (!this._linesIndexBuffer) {
  303. var linesIndices = [];
  304. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
  305. linesIndices.push(indices[index], indices[index + 1],
  306. indices[index + 1], indices[index + 2],
  307. indices[index + 2], indices[index]);
  308. }
  309. this._linesIndexBuffer = engine.createIndexBuffer(linesIndices);
  310. this._linesIndexCount = linesIndices.length;
  311. }
  312. return this._linesIndexBuffer;
  313. }
  314. /**
  315. * Checks if the submesh intersects with a ray
  316. * @param ray defines the ray to test
  317. * @returns true is the passed ray intersects the submesh bounding box
  318. */
  319. public canIntersects(ray: Ray): boolean {
  320. let boundingInfo = this.getBoundingInfo();
  321. if (!boundingInfo) {
  322. return false;
  323. }
  324. return ray.intersectsBox(boundingInfo.boundingBox);
  325. }
  326. /**
  327. * Intersects current submesh with a ray
  328. * @param ray defines the ray to test
  329. * @param positions defines mesh's positions array
  330. * @param indices defines mesh's indices array
  331. * @param fastCheck defines if the first intersection will be used (and not the closest)
  332. * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
  333. * @returns intersection info or null if no intersection
  334. */
  335. public intersects(ray: Ray, positions: Vector3[], indices: IndicesArray,
  336. fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo> {
  337. const material = this.getMaterial();
  338. if (!material) {
  339. return null;
  340. }
  341. let step = 3;
  342. let checkStopper = false;
  343. switch (material.fillMode) {
  344. case Constants.MATERIAL_PointListDrawMode:
  345. case Constants.MATERIAL_LineListDrawMode:
  346. case Constants.MATERIAL_LineLoopDrawMode:
  347. case Constants.MATERIAL_LineStripDrawMode:
  348. case Constants.MATERIAL_TriangleFanDrawMode:
  349. return null;
  350. case Constants.MATERIAL_TriangleStripDrawMode:
  351. step = 1;
  352. checkStopper = true;
  353. break;
  354. default:
  355. break;
  356. }
  357. // LineMesh first as it's also a Mesh...
  358. if (this._mesh.getClassName() === "InstancedLinesMesh" || this._mesh.getClassName() === "LinesMesh") {
  359. // Check if mesh is unindexed
  360. if (!indices.length) {
  361. return this._intersectUnIndexedLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
  362. }
  363. return this._intersectLines(ray, positions, indices, (this._mesh as any).intersectionThreshold, fastCheck);
  364. }
  365. else {
  366. // Check if mesh is unindexed
  367. if (!indices.length && this._mesh._unIndexed) {
  368. return this._intersectUnIndexedTriangles(ray, positions, indices, fastCheck, trianglePredicate);
  369. }
  370. return this._intersectTriangles(ray, positions, indices, step, checkStopper, fastCheck, trianglePredicate);
  371. }
  372. }
  373. /** @hidden */
  374. private _intersectLines(ray: Ray, positions: Vector3[], indices: IndicesArray, intersectionThreshold: number, fastCheck?: boolean): Nullable<IntersectionInfo> {
  375. var intersectInfo: Nullable<IntersectionInfo> = null;
  376. // Line test
  377. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 2) {
  378. var p0 = positions[indices[index]];
  379. var p1 = positions[indices[index + 1]];
  380. var length = ray.intersectionSegment(p0, p1, intersectionThreshold);
  381. if (length < 0) {
  382. continue;
  383. }
  384. if (fastCheck || !intersectInfo || length < intersectInfo.distance) {
  385. intersectInfo = new IntersectionInfo(null, null, length);
  386. intersectInfo.faceId = index / 2;
  387. if (fastCheck) {
  388. break;
  389. }
  390. }
  391. }
  392. return intersectInfo;
  393. }
  394. /** @hidden */
  395. private _intersectUnIndexedLines(ray: Ray, positions: Vector3[], indices: IndicesArray, intersectionThreshold: number, fastCheck?: boolean): Nullable<IntersectionInfo> {
  396. var intersectInfo: Nullable<IntersectionInfo> = null;
  397. // Line test
  398. for (var index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 2) {
  399. var p0 = positions[index];
  400. var p1 = positions[index + 1];
  401. var length = ray.intersectionSegment(p0, p1, intersectionThreshold);
  402. if (length < 0) {
  403. continue;
  404. }
  405. if (fastCheck || !intersectInfo || length < intersectInfo.distance) {
  406. intersectInfo = new IntersectionInfo(null, null, length);
  407. intersectInfo.faceId = index / 2;
  408. if (fastCheck) {
  409. break;
  410. }
  411. }
  412. }
  413. return intersectInfo;
  414. }
  415. /** @hidden */
  416. private _intersectTriangles(ray: Ray, positions: Vector3[], indices: IndicesArray,
  417. step: number, checkStopper: boolean,
  418. fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo> {
  419. var intersectInfo: Nullable<IntersectionInfo> = null;
  420. // Triangles test
  421. let faceID = -1;
  422. for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += step) {
  423. faceID++;
  424. const indexA = indices[index];
  425. const indexB = indices[index + 1];
  426. const indexC = indices[index + 2];
  427. if (checkStopper && indexC === 0xFFFFFFFF) {
  428. index += 2;
  429. continue;
  430. }
  431. var p0 = positions[indexA];
  432. var p1 = positions[indexB];
  433. var p2 = positions[indexC];
  434. if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray)) {
  435. continue;
  436. }
  437. var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
  438. if (currentIntersectInfo) {
  439. if (currentIntersectInfo.distance < 0) {
  440. continue;
  441. }
  442. if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
  443. intersectInfo = currentIntersectInfo;
  444. intersectInfo.faceId = faceID;
  445. if (fastCheck) {
  446. break;
  447. }
  448. }
  449. }
  450. }
  451. return intersectInfo;
  452. }
  453. /** @hidden */
  454. private _intersectUnIndexedTriangles(ray: Ray, positions: Vector3[], indices: IndicesArray,
  455. fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo> {
  456. var intersectInfo: Nullable<IntersectionInfo> = null;
  457. // Triangles test
  458. for (var index = this.verticesStart; index < this.verticesStart + this.verticesCount; index += 3) {
  459. var p0 = positions[index];
  460. var p1 = positions[index + 1];
  461. var p2 = positions[index + 2];
  462. if (trianglePredicate && !trianglePredicate(p0, p1, p2, ray)) {
  463. continue;
  464. }
  465. var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
  466. if (currentIntersectInfo) {
  467. if (currentIntersectInfo.distance < 0) {
  468. continue;
  469. }
  470. if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
  471. intersectInfo = currentIntersectInfo;
  472. intersectInfo.faceId = index / 3;
  473. if (fastCheck) {
  474. break;
  475. }
  476. }
  477. }
  478. }
  479. return intersectInfo;
  480. }
  481. /** @hidden */
  482. public _rebuild(): void {
  483. if (this._linesIndexBuffer) {
  484. this._linesIndexBuffer = null;
  485. }
  486. }
  487. // Clone
  488. /**
  489. * Creates a new submesh from the passed mesh
  490. * @param newMesh defines the new hosting mesh
  491. * @param newRenderingMesh defines an optional rendering mesh
  492. * @returns the new submesh
  493. */
  494. public clone(newMesh: AbstractMesh, newRenderingMesh?: Mesh): SubMesh {
  495. var result = new SubMesh(this.materialIndex, this.verticesStart, this.verticesCount, this.indexStart, this.indexCount, newMesh, newRenderingMesh, false);
  496. if (!this.IsGlobal) {
  497. let boundingInfo = this.getBoundingInfo();
  498. if (!boundingInfo) {
  499. return result;
  500. }
  501. result._boundingInfo = new BoundingInfo(boundingInfo.minimum, boundingInfo.maximum);
  502. }
  503. return result;
  504. }
  505. // Dispose
  506. /**
  507. * Release associated resources
  508. */
  509. public dispose(): void {
  510. if (this._linesIndexBuffer) {
  511. this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer);
  512. this._linesIndexBuffer = null;
  513. }
  514. // Remove from mesh
  515. var index = this._mesh.subMeshes.indexOf(this);
  516. this._mesh.subMeshes.splice(index, 1);
  517. }
  518. /**
  519. * Gets the class name
  520. * @returns the string "SubMesh".
  521. */
  522. public getClassName(): string {
  523. return "SubMesh";
  524. }
  525. // Statics
  526. /**
  527. * Creates a new submesh from indices data
  528. * @param materialIndex the index of the main mesh material
  529. * @param startIndex the index where to start the copy in the mesh indices array
  530. * @param indexCount the number of indices to copy then from the startIndex
  531. * @param mesh the main mesh to create the submesh from
  532. * @param renderingMesh the optional rendering mesh
  533. * @returns a new submesh
  534. */
  535. public static CreateFromIndices(materialIndex: number, startIndex: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh): SubMesh {
  536. var minVertexIndex = Number.MAX_VALUE;
  537. var maxVertexIndex = -Number.MAX_VALUE;
  538. const whatWillRender = (renderingMesh || mesh);
  539. var indices = whatWillRender!.getIndices()!;
  540. for (var index = startIndex; index < startIndex + indexCount; index++) {
  541. var vertexIndex = indices[index];
  542. if (vertexIndex < minVertexIndex) {
  543. minVertexIndex = vertexIndex;
  544. }
  545. if (vertexIndex > maxVertexIndex) {
  546. maxVertexIndex = vertexIndex;
  547. }
  548. }
  549. return new SubMesh(materialIndex, minVertexIndex, maxVertexIndex - minVertexIndex + 1, startIndex, indexCount, mesh, renderingMesh);
  550. }
  551. }