You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-20 15:36:18 +00:00
🆙 Some minor mem tweaks
This commit is contained in:
@@ -285,6 +285,8 @@ export class AvatarImage implements IAvatarImage, IAvatarEffectListener
|
|||||||
|
|
||||||
const container = this.buildAvatarContainer(avatarCanvas, setType);
|
const container = this.buildAvatarContainer(avatarCanvas, setType);
|
||||||
|
|
||||||
|
if(!container) return null;
|
||||||
|
|
||||||
GetRenderer().render({
|
GetRenderer().render({
|
||||||
target: this._activeTexture,
|
target: this._activeTexture,
|
||||||
container: container,
|
container: container,
|
||||||
|
|||||||
@@ -117,7 +117,12 @@ export class RoomCameraWidgetManager implements IRoomCameraWidgetManager
|
|||||||
|
|
||||||
TextureUtils.writeToTexture(container, renderTexture);
|
TextureUtils.writeToTexture(container, renderTexture);
|
||||||
|
|
||||||
return await TextureUtils.generateImage(renderTexture);
|
const image = await TextureUtils.generateImage(renderTexture);
|
||||||
|
|
||||||
|
container.destroy({ children: true });
|
||||||
|
renderTexture.destroy(true);
|
||||||
|
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get effects(): Map<string, IRoomCameraWidgetEffect>
|
public get effects(): Map<string, IRoomCameraWidgetEffect>
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ export class CommunicationManager implements ICommunicationManager
|
|||||||
t.shadowColor = 'blue';
|
t.shadowColor = 'blue';
|
||||||
t.fillRect(-20, 10, 234, 5);
|
t.fillRect(-20, 10, 234, 5);
|
||||||
const i = e.toDataURL();
|
const i = e.toDataURL();
|
||||||
document.body.appendChild(e);
|
e.width = 0;
|
||||||
|
e.height = 0;
|
||||||
let r = 0;
|
let r = 0;
|
||||||
if (i.length === 0) return 'nothing!';
|
if (i.length === 0) return 'nothing!';
|
||||||
for (let n = 0; n < i.length; n++) {
|
for (let n = 0; n < i.length; n++) {
|
||||||
|
|||||||
+5
-2
@@ -283,6 +283,8 @@ export class FurnitureBadgeDisplayVisualization extends FurnitureAnimatedVisuali
|
|||||||
tempCtx.putImageData(patchData, 0, 0);
|
tempCtx.putImageData(patchData, 0, 0);
|
||||||
|
|
||||||
accCtx.drawImage(tempCanvas, frame.dims.left, frame.dims.top);
|
accCtx.drawImage(tempCanvas, frame.dims.left, frame.dims.top);
|
||||||
|
tempCanvas.width = 0;
|
||||||
|
tempCanvas.height = 0;
|
||||||
|
|
||||||
// Create a new canvas for this frame and create a texture from it
|
// Create a new canvas for this frame and create a texture from it
|
||||||
const frameCanvas = document.createElement('canvas');
|
const frameCanvas = document.createElement('canvas');
|
||||||
@@ -299,6 +301,9 @@ export class FurnitureBadgeDisplayVisualization extends FurnitureAnimatedVisuali
|
|||||||
frameDelays.push(frame.delay || 10);
|
frameDelays.push(frame.delay || 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accCanvas.width = 0;
|
||||||
|
accCanvas.height = 0;
|
||||||
|
|
||||||
// Create AnimatedSprite with frame textures
|
// Create AnimatedSprite with frame textures
|
||||||
if(this._frameTextures.length > 1)
|
if(this._frameTextures.length > 1)
|
||||||
{
|
{
|
||||||
@@ -342,13 +347,11 @@ export class FurnitureBadgeDisplayVisualization extends FurnitureAnimatedVisuali
|
|||||||
tex.source.update();
|
tex.source.update();
|
||||||
img.onload = null;
|
img.onload = null;
|
||||||
img.onerror = null;
|
img.onerror = null;
|
||||||
img.src = '';
|
|
||||||
};
|
};
|
||||||
img.onerror = () =>
|
img.onerror = () =>
|
||||||
{
|
{
|
||||||
img.onload = null;
|
img.onload = null;
|
||||||
img.onerror = null;
|
img.onerror = null;
|
||||||
img.src = '';
|
|
||||||
};
|
};
|
||||||
img.src = badgeUrl;
|
img.src = badgeUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -35,14 +35,12 @@ export class FurnitureDynamicThumbnailVisualization extends IsometricImageFurniV
|
|||||||
}
|
}
|
||||||
image.onload = null;
|
image.onload = null;
|
||||||
image.onerror = null;
|
image.onerror = null;
|
||||||
image.src = '';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
image.onerror = () => {
|
image.onerror = () => {
|
||||||
this.setThumbnailImages(null);
|
this.setThumbnailImages(null);
|
||||||
image.onload = null;
|
image.onload = null;
|
||||||
image.onerror = null;
|
image.onerror = null;
|
||||||
image.src = '';
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.setThumbnailImages(null);
|
this.setThumbnailImages(null);
|
||||||
|
|||||||
@@ -883,8 +883,18 @@ export class RoomPlane implements IRoomPlane
|
|||||||
const container = new Container();
|
const container = new Container();
|
||||||
const visibleAvatarIds = new Set<number>();
|
const visibleAvatarIds = new Set<number>();
|
||||||
|
|
||||||
const addReflectionSprite = (texture: Texture, oppositeTexture: Texture, location: IVector3D, alpha: number, verticalOffset: number = 0, direction: number = 0, avatarId: number = -1): boolean => {
|
const addReflectionSprite = (
|
||||||
if(!texture?.source || texture.source.destroyed || !texture.source.style || !location || alpha < 0) return false;
|
texture: Texture,
|
||||||
|
oppositeTexture: Texture,
|
||||||
|
location: IVector3D,
|
||||||
|
alpha: number,
|
||||||
|
verticalOffset: number = 0,
|
||||||
|
direction: number = 0,
|
||||||
|
avatarId: number = -1
|
||||||
|
): boolean =>
|
||||||
|
{
|
||||||
|
if(!texture?.source || texture.source.destroyed || !texture.source.style || !location || alpha < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
const relative = Vector3d.dif(location, this._location);
|
const relative = Vector3d.dif(location, this._location);
|
||||||
const planeDistance = Math.abs(Vector3d.scalarProjection(relative, this._normal));
|
const planeDistance = Math.abs(Vector3d.scalarProjection(relative, this._normal));
|
||||||
@@ -894,7 +904,8 @@ export class RoomPlane implements IRoomPlane
|
|||||||
const leftSideLoc = Vector3d.scalarProjection(relative, this._leftSide);
|
const leftSideLoc = Vector3d.scalarProjection(relative, this._leftSide);
|
||||||
const rightSideLoc = Vector3d.scalarProjection(relative, this._rightSide);
|
const rightSideLoc = Vector3d.scalarProjection(relative, this._rightSide);
|
||||||
|
|
||||||
const closestMask = this._windowMasks.reduce((best, mask) => {
|
const closestMask = this._windowMasks.reduce((best, mask) =>
|
||||||
|
{
|
||||||
const score = Math.abs(mask.leftSideLoc - leftSideLoc) + Math.abs(mask.rightSideLoc - rightSideLoc);
|
const score = Math.abs(mask.leftSideLoc - leftSideLoc) + Math.abs(mask.rightSideLoc - rightSideLoc);
|
||||||
|
|
||||||
if(!best || (score < best.score)) return { mask, score };
|
if(!best || (score < best.score)) return { mask, score };
|
||||||
@@ -936,7 +947,8 @@ export class RoomPlane implements IRoomPlane
|
|||||||
if(shouldMirror && oppositeTexture)
|
if(shouldMirror && oppositeTexture)
|
||||||
{
|
{
|
||||||
if(normalFacingDot >= transitionHigh) oppositeWeight = 1;
|
if(normalFacingDot >= transitionHigh) oppositeWeight = 1;
|
||||||
else if(normalFacingDot > transitionLow) oppositeWeight = (normalFacingDot - transitionLow) / (transitionHigh - transitionLow);
|
else if(normalFacingDot > transitionLow)
|
||||||
|
oppositeWeight = (normalFacingDot - transitionLow) / (transitionHigh - transitionLow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oppositeWeight < 1)
|
if(oppositeWeight < 1)
|
||||||
@@ -944,7 +956,6 @@ export class RoomPlane implements IRoomPlane
|
|||||||
const sprite = new Sprite(texture);
|
const sprite = new Sprite(texture);
|
||||||
sprite.anchor.set(0.5, 1);
|
sprite.anchor.set(0.5, 1);
|
||||||
sprite.position.set(Math.trunc(x), Math.trunc(y));
|
sprite.position.set(Math.trunc(x), Math.trunc(y));
|
||||||
sprite.scale.set(1, 1);
|
|
||||||
sprite.tint = 0xCFE3FF;
|
sprite.tint = 0xCFE3FF;
|
||||||
sprite.alpha = alpha * (1 - oppositeWeight);
|
sprite.alpha = alpha * (1 - oppositeWeight);
|
||||||
container.addChild(sprite);
|
container.addChild(sprite);
|
||||||
@@ -955,7 +966,6 @@ export class RoomPlane implements IRoomPlane
|
|||||||
const sprite = new Sprite(oppositeTexture);
|
const sprite = new Sprite(oppositeTexture);
|
||||||
sprite.anchor.set(0.5, 1);
|
sprite.anchor.set(0.5, 1);
|
||||||
sprite.position.set(Math.trunc(x), Math.trunc(y));
|
sprite.position.set(Math.trunc(x), Math.trunc(y));
|
||||||
sprite.scale.set(1, 1);
|
|
||||||
sprite.tint = 0xCFE3FF;
|
sprite.tint = 0xCFE3FF;
|
||||||
sprite.alpha = alpha * oppositeWeight;
|
sprite.alpha = alpha * oppositeWeight;
|
||||||
container.addChild(sprite);
|
container.addChild(sprite);
|
||||||
@@ -966,22 +976,28 @@ export class RoomPlane implements IRoomPlane
|
|||||||
|
|
||||||
for(const avatar of avatars)
|
for(const avatar of avatars)
|
||||||
{
|
{
|
||||||
if(!avatar?.texture?.source || avatar.texture.source.destroyed || !avatar.texture.source.style || !avatar.location) continue;
|
if(!avatar?.texture?.source || avatar.texture.source.destroyed || !avatar.texture.source.style || !avatar.location)
|
||||||
|
continue;
|
||||||
|
|
||||||
let firstSeenAt = this._windowReflectionFirstSeenAt.get(avatar.id);
|
let firstSeenAt = this._windowReflectionFirstSeenAt.get(avatar.id);
|
||||||
|
|
||||||
if(firstSeenAt === undefined)
|
if(firstSeenAt === undefined) firstSeenAt = now;
|
||||||
{
|
|
||||||
firstSeenAt = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
const elapsed = Math.min(fadeDurationMs, Math.max(0, (now - firstSeenAt)));
|
const elapsed = Math.min(fadeDurationMs, Math.max(0, (now - firstSeenAt)));
|
||||||
const progress = (elapsed / fadeDurationMs);
|
const alpha = (0.4 * (elapsed / fadeDurationMs));
|
||||||
const alpha = (0.4 * progress);
|
|
||||||
|
|
||||||
if(!addReflectionSprite(avatar.texture, avatar.oppositeTexture, avatar.location, alpha, avatar.verticalOffset || 0, avatar.direction || 0, avatar.id)) continue;
|
if(!addReflectionSprite(
|
||||||
|
avatar.texture,
|
||||||
|
avatar.oppositeTexture,
|
||||||
|
avatar.location,
|
||||||
|
alpha,
|
||||||
|
avatar.verticalOffset || 0,
|
||||||
|
avatar.direction || 0,
|
||||||
|
avatar.id))
|
||||||
|
continue;
|
||||||
|
|
||||||
if(!this._windowReflectionFirstSeenAt.has(avatar.id)) this._windowReflectionFirstSeenAt.set(avatar.id, firstSeenAt);
|
if(!this._windowReflectionFirstSeenAt.has(avatar.id))
|
||||||
|
this._windowReflectionFirstSeenAt.set(avatar.id, firstSeenAt);
|
||||||
|
|
||||||
visibleAvatarIds.add(avatar.id);
|
visibleAvatarIds.add(avatar.id);
|
||||||
this._windowReflectionFadeOut.delete(avatar.id);
|
this._windowReflectionFadeOut.delete(avatar.id);
|
||||||
@@ -998,24 +1014,13 @@ export class RoomPlane implements IRoomPlane
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move to fade-out (NO destruction)
|
||||||
for(const [id, lastVisible] of this._windowReflectionLastVisible)
|
for(const [id, lastVisible] of this._windowReflectionLastVisible)
|
||||||
{
|
{
|
||||||
if(visibleAvatarIds.has(id) || this._windowReflectionFadeOut.has(id)) continue;
|
if(visibleAvatarIds.has(id) || this._windowReflectionFadeOut.has(id)) continue;
|
||||||
|
|
||||||
if(!lastVisible.texture?.source || lastVisible.texture.source.destroyed || !lastVisible.texture.source.style)
|
|
||||||
{
|
|
||||||
this._windowReflectionLastVisible.delete(id);
|
|
||||||
this._windowReflectionFirstSeenAt.delete(id);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._windowReflectionFadeOut.set(id, {
|
this._windowReflectionFadeOut.set(id, {
|
||||||
texture: lastVisible.texture,
|
...lastVisible,
|
||||||
oppositeTexture: lastVisible.oppositeTexture,
|
|
||||||
location: lastVisible.location,
|
|
||||||
verticalOffset: lastVisible.verticalOffset,
|
|
||||||
direction: lastVisible.direction,
|
|
||||||
startedAt: now
|
startedAt: now
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1023,6 +1028,7 @@ export class RoomPlane implements IRoomPlane
|
|||||||
this._windowReflectionFirstSeenAt.delete(id);
|
this._windowReflectionFirstSeenAt.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fade-out rendering (NO destruction)
|
||||||
for(const [id, fadeOut] of this._windowReflectionFadeOut)
|
for(const [id, fadeOut] of this._windowReflectionFadeOut)
|
||||||
{
|
{
|
||||||
const elapsed = (now - fadeOut.startedAt);
|
const elapsed = (now - fadeOut.startedAt);
|
||||||
@@ -1030,13 +1036,22 @@ export class RoomPlane implements IRoomPlane
|
|||||||
if(elapsed >= fadeDurationMs)
|
if(elapsed >= fadeDurationMs)
|
||||||
{
|
{
|
||||||
this._windowReflectionFadeOut.delete(id);
|
this._windowReflectionFadeOut.delete(id);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const alpha = (0.4 * (1 - (elapsed / fadeDurationMs)));
|
const alpha = (0.4 * (1 - (elapsed / fadeDurationMs)));
|
||||||
|
|
||||||
if(!addReflectionSprite(fadeOut.texture, fadeOut.oppositeTexture, fadeOut.location, alpha, fadeOut.verticalOffset, fadeOut.direction, id)) this._windowReflectionFadeOut.delete(id);
|
if(!addReflectionSprite(
|
||||||
|
fadeOut.texture,
|
||||||
|
fadeOut.oppositeTexture,
|
||||||
|
fadeOut.location,
|
||||||
|
alpha,
|
||||||
|
fadeOut.verticalOffset,
|
||||||
|
fadeOut.direction,
|
||||||
|
id))
|
||||||
|
{
|
||||||
|
this._windowReflectionFadeOut.delete(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!container.children.length)
|
if(!container.children.length)
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ export class BadgeImageManager
|
|||||||
if(!renderedLayers) return false;
|
if(!renderedLayers) return false;
|
||||||
|
|
||||||
const texture = TextureUtils.generateTexture(container);
|
const texture = TextureUtils.generateTexture(container);
|
||||||
|
container.destroy({ children: true });
|
||||||
GetAssetManager().setTexture(groupBadge.code, texture);
|
GetAssetManager().setTexture(groupBadge.code, texture);
|
||||||
|
|
||||||
GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(groupBadge.code, texture));
|
GetEventDispatcher().dispatchEvent(new BadgeImageReadyEvent(groupBadge.code, texture));
|
||||||
|
|||||||
Reference in New Issue
Block a user