Skip to content

Commit

Permalink
fix: wireframe index buffer type bug (#33)
Browse files Browse the repository at this point in the history
* fix: wireframe index buffer type bug
  • Loading branch information
yangfengzzz authored Jul 21, 2022
1 parent 900fb59 commit d07ff60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 15 additions & 14 deletions packages/auxiliary-lines/src/WireframeManager.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {
BoolUpdateFlag,
BoxColliderShape,
Camera,
CapsuleColliderShape,
SphereColliderShape,
Collider,
dependentComponents,
DirectLight,
Entity,
GLCapabilityType,
Matrix,
MeshRenderer,
MeshTopology,
ModelMesh,
Script,
UnlitMaterial,
Vector3,
Transform,
PointLight,
Camera,
Matrix,
Script,
SphereColliderShape,
SpotLight,
DirectLight,
Collider,
Entity,
dependentComponents,
BoolUpdateFlag
Transform,
UnlitMaterial,
Vector3
} from "oasis-engine";

import { WireframePrimitive } from "./WireframePrimitive";

/**
Expand Down Expand Up @@ -442,12 +443,12 @@ export class WireframeManager extends Script {
const indices = this._indices;
const neededLength = this._indicesCount + length;
if (neededLength > indices.length) {
const maxLength = this._supportUint32Array ? 65535 : 4294967295;
const maxLength = this._supportUint32Array ? 4294967295 : 65535;
if (neededLength > maxLength) {
throw Error("The vertex count is over limit.");
}

const newIndices = this._supportUint32Array ? new Uint16Array(neededLength) : new Uint32Array(neededLength);
const newIndices = this._supportUint32Array ? new Uint32Array(neededLength) : new Uint16Array(neededLength);
newIndices.set(indices);
this._indices = newIndices;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/auxiliary-lines/src/WireframePrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class WireframePrimitive {
shift.y = -height;
WireframePrimitive.createCircleWireframe(radius, 1, shift, positions, positionOffset, indices, indicesOffset);

positions.push(new Vector3(0, height, 0));
positions.push(new Vector3());
positions.push(new Vector3(-radius, -height, 0));
positions.push(new Vector3(radius, -height, 0));
positions.push(new Vector3(0, -height, radius));
Expand Down Expand Up @@ -287,7 +287,7 @@ export class WireframePrimitive {
const indexBegin = positionOffset + WireframePrimitive.circleVertexCount;
indicesOffset += WireframePrimitive.circleIndexCount;
for (let i = 0; i < 8; i++) {
let radian = MathUtil.degreeToRadian(45 * i);
const radian = MathUtil.degreeToRadian(45 * i);
positions.push(new Vector3(radius * Math.cos(radian), 0, radius * Math.sin(radian)));
positions.push(new Vector3(radius * Math.cos(radian), -height, radius * Math.sin(radian)));

Expand Down

0 comments on commit d07ff60

Please sign in to comment.