Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!this.cmdlData.has(model.assetID))
this.cmdlData.set(model.assetID, new CMDLData(device, textureHolder, cache, model));
return this.cmdlData.get(model.assetID)!;
}
}
export class MREARenderer {
private bufferCoalescer: GfxBufferCoalescerCombo;
private materialGroupInstances: MaterialGroupInstance[] = [];
private materialInstances: MaterialInstance[] = [];
private surfaceData: SurfaceData[] = [];
private surfaceInstances: SurfaceInstance[] = [];
private cmdlData: CMDLData[] = [];
private actors: Actor[] = [];
public overrideSky: CMDLRenderer | null = null;
public modelMatrix = mat4.create();
public needSky: boolean = false;
public visible: boolean = true;
constructor(device: GfxDevice, modelCache: ModelCache, cache: GfxRenderCache, public textureHolder: RetroTextureHolder, public name: string, public mrea: MREA) {
this.translateModel(device, cache);
this.translateActors(device, cache, modelCache);
}
private translateModel(device: GfxDevice, cache: GfxRenderCache): void {
const materialSet = this.mrea.materialSet;
this.textureHolder.addMaterialSetTextures(device, materialSet);
// First, create our group commands. These will store UBO buffer data which is shared between
// all groups using that material.
for (let i = 0; i < materialSet.materials.length; i++) {
dst[13] = m[13];
dst[2] = 0;
dst[6] = m[6];
dst[10] = v[2] * mz;
dst[14] = m[14];
// Fill with junk to try and signal when something has gone horribly wrong. This should go unused,
// since this is supposed to generate a mat4x3 matrix.
m[3] = 9999.0;
m[7] = 9999.0;
m[11] = 9999.0;
m[15] = 9999.0;
}
const scratchModelViewMatrix = mat4.create();
const packetParams = new PacketParams();
export class ShapeInstance {
public visible: boolean = true;
constructor(public shapeData: ShapeData, private materialInstance: MaterialInstance) {
}
public prepareToRender(device: GfxDevice, renderInstManager: GfxRenderInstManager, depth: number, camera: Camera, viewport: NormalizedViewportCoords, modelData: J3DModelData, materialInstanceState: MaterialInstanceState, shapeInstanceState: ShapeInstanceState): void {
if (!this.visible)
return;
const materialInstance = this.materialInstance;
if (!materialInstance.visible)
return;
const shape = this.shapeData.shape;
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
// Inheritance
vtkViewNode.extend(publicAPI, model, initialValues);
model.keyMatrixTime = {};
macro.obj(model.keyMatrixTime);
model.keyMatrices = {
normalMatrix: mat3.create(),
vcdc: mat4.create(),
wcvc: mat4.create(),
wcdc: mat4.create(),
};
// Build VTK API
macro.setGet(publicAPI, model, ['context', 'keyMatrixTime']);
// Object methods
vtkOpenGLCamera(publicAPI, model);
}
protected generateSphere1Node(parent: SceneNode): SceneNode {
const gl = this._context.gl;
/* Create node and transform */
const node = parent.addNode(new SceneNode('mesh'));
const translate = mat4.fromTranslation(mat4.create(), vec3.fromValues(0.0, 0.0, 0.0));
const scale = mat4.fromScaling(mat4.create(), vec3.fromValues(0.4, 0.4, 0.4));
const transformMatrix = mat4.multiply(mat4.create(), translate, scale);
const transform = new TransformComponent(transformMatrix);
node.addComponent(transform);
/* Create and load texture. */
const texture = new Texture2D(this._context, 'Texture');
texture.initialize(1, 1, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE);
texture.fetch('./data/concrete_floor_02_diff_1k.webp', false).then(() => {
this.invalidate(true);
});
/* Create material */
const material = new SceneExampleMaterial(this._context, 'ExampleMaterial1');
material.texture = texture;
material.textured = true;
aPosition: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1]
})
])
);
let shader = renderer.shaders.create(
require('../shader/phong.vert'),
require('../shader/phong.frag')
);
let texture = renderer.textures.create(require('../texture/2.png'), {
params: {
wrapS: gl.REPEAT,
wrapT: gl.REPEAT
}
});
let model1Mat = mat4.create();
let model1Normal = mat3.create();
return (delta, context) => {
renderer.render({
options: {
clearColor: new Float32Array([0, 0, 0, 1]),
clearDepth: 1,
cull: gl.BACK,
depth: gl.LEQUAL
},
uniforms: Object.assign({}, context.camera, {
uPointLight: [{
position: [0, -8, 3],
color: '#ffffff',
intensity: [0.3, 0.7, 1.0, 0.00015]
}]
constructor(fieldOfViewDegree, aspect, zNear, zFar)
{
super();
this.fieldOfView = fieldOfViewDegree;
this._apsect = aspect;
this.zNear = zNear;
this.zFar = zFar;
this._view = mat4.create();
this._projection = mat4.create();
this._projection = mat4.perspective(this._projection,
glMatrix.toRadian(fieldOfViewDegree),
aspect,
zNear,
zFar
);
}
lookAt(aEye, aCenter, aUp = [0, 1, 0])
public static inverse(m: Matrix): Matrix {
const newMat = mat4.create();
return new Matrix(mat4.invert(newMat, m.rawElements));
}
public setTransformFromParent() {
if (!!this.parent) {
this._matrix = mat4.mul(mat4.create(), this.parent.matrix, this.localMatrix);
this.genOtherMatrixs();
mat4.getTranslation(this._position, this.matrix);
mat4.getRotation(this._rotation, this.matrix);
vec3.mul(this.scaling, this.parent.scaling, this.localScaling);
}
return this;
}
return raf(() => {
let projection = mat4.create()
let modelview = mat4.create()
let mvp = mat4.create()
mat4.perspective(
projection,
(params.fovy * Math.PI) / 180,
1,
params.near,
params.far
)
mat4.lookAt(
modelview,
[params.eyeX, params.eyeY, params.eyeZ],
[params.centerX, params.centerY, params.centerZ],
[params.upX, params.upY, params.upZ]
const actors: Actor[] = [];
let actorTableIdx = offs;
const q = quat.create();
for (let i = 0; i < nActors; i++) {
const roomFront = view.getUint8(actorTableIdx + 0x00);
const transitionEffectFront = view.getUint8(actorTableIdx + 0x01);
const roomBack = view.getUint8(actorTableIdx + 0x02);
const transitionEffectBack = view.getUint8(actorTableIdx + 0x03);
const actorId = view.getUint16(actorTableIdx + 0x04, true);
const positionX = view.getInt16(actorTableIdx + 0x06, true);
const positionY = view.getInt16(actorTableIdx + 0x08, true);
const positionZ = view.getInt16(actorTableIdx + 0x0A, true);
const rotationY = view.getInt16(actorTableIdx + 0x0C, true) / 0x7FFF;
const variable = view.getUint16(actorTableIdx + 0x0E, true);
const modelMatrix = mat4.create();
quat.fromEuler(q, 0, rotationY * 180, 0);
mat4.fromRotationTranslation(modelMatrix, q, [positionX, positionY, positionZ]);
actors.push({ actorId, modelMatrix, variable, timeSpawnFlags: 0xFF });
actorTableIdx += 0x10;
}
return actors;
}