Skip to content

Commit

Permalink
Base push for tint experi;ent
Browse files Browse the repository at this point in the history
  • Loading branch information
NeylMahfouf2608 committed Feb 5, 2025
1 parent 9e00efb commit f609bf2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 58 deletions.
30 changes: 15 additions & 15 deletions Extensions/3D/Cube3DRuntimeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace gdjs {
rightFaceVisible: boolean;
topFaceVisible: boolean;
bottomFaceVisible: boolean;
color: string;
tint: string;
materialType: 'Basic' | 'StandardWithoutMetalness';
};
}
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace gdjs {
];
_materialType: gdjs.Cube3DRuntimeObject.MaterialType =
gdjs.Cube3DRuntimeObject.MaterialType.Basic;
_color: number;
_tint: number;
constructor(
instanceContainer: gdjs.RuntimeInstanceContainer,
objectData: Cube3DObjectData
Expand Down Expand Up @@ -119,8 +119,8 @@ namespace gdjs {
objectData.content.bottomFaceResourceName,
];

this._color = gdjs.rgbOrHexStringToNumber(
objectData.content.color || '128;128;128'
this._tint = gdjs.rgbOrHexStringToNumber(
objectData.content.tint || '128;128;128'
);

this._materialType = this._convertMaterialType(
Expand Down Expand Up @@ -212,11 +212,11 @@ namespace gdjs {
this._faceResourceNames[faceIndex] = resourceName;
this._renderer.updateFace(faceIndex);
}
setColor(color: string): void {
const colorinHex = gdjs.rgbOrHexStringToNumber(color);
if (colorinHex === this._color) return;
this._color = colorinHex;
this._renderer.updateColor();
setTint(tint: string): void {
const tintInHex = gdjs.rgbOrHexStringToNumber(tint);
if (tintInHex === this._tint) return;
this._tint = tintInHex;
this._renderer.updateTint();
}

/** @internal */
Expand Down Expand Up @@ -302,8 +302,8 @@ namespace gdjs {
newObjectData.content.frontFaceResourceName
);
}
if (oldObjectData.content.color !== newObjectData.content.color) {
this.setColor(newObjectData.content.color);
if (oldObjectData.content.tint !== newObjectData.content.tint) {
this.setTint(newObjectData.content.tint);
}

if (
Expand Down Expand Up @@ -438,7 +438,7 @@ namespace gdjs {
vfb: this._visibleFacesBitmask,
trfb: this._textureRepeatFacesBitmask,
frn: this._faceResourceNames,
c: this._color,
c: this._tint,
};
}

Expand Down Expand Up @@ -493,9 +493,9 @@ namespace gdjs {
}
}
if (networkSyncData.c !== undefined) {
if (this._color !== networkSyncData.c) {
this._color = networkSyncData.c;
this._renderer.updateColor();
if (this._tint !== networkSyncData.c) {
this._tint = networkSyncData.c;
this._renderer.updateTint();
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions Extensions/3D/Cube3DRuntimeObjectPixiRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ namespace gdjs {
if (!runtimeObject.isFaceAtIndexVisible(faceIndex))
return getTransparentMaterial();

const resourceName = runtimeObject.getFaceAtIndexResourceName(faceIndex);
if (!resourceName) {
return new THREE.MeshBasicMaterial({ vertexColors: true });
}
return runtimeObject
.getInstanceContainer()
.getGame()
Expand Down Expand Up @@ -94,26 +90,26 @@ namespace gdjs {
this.updateSize();
this.updatePosition();
this.updateRotation();
this.updateColor();
this.updateTint();
}
updateColor() {
const colors: number[] = [];
updateTint() {
const tints: number[] = [];

const normalizedColor = gdjs
.hexNumberToRGBArray(this._cube3DRuntimeObject._color)
const normalizedTint = gdjs
.hexNumberToRGBArray(this._cube3DRuntimeObject._tint)
.map((component) => component / 255);

for (
let i = 0;
i < this._boxMesh.geometry.attributes.position.count;
i++
) {
colors.push(...normalizedColor);
tints.push(...normalizedTint);
}

this._boxMesh.geometry.setAttribute(
'color',
new THREE.BufferAttribute(new Float32Array(colors), 3)
new THREE.BufferAttribute(new Float32Array(tints), 3)
);
}

Expand Down
58 changes: 26 additions & 32 deletions Extensions/3D/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ module.exports = {
propertyName === 'backFaceUpThroughWhichAxisRotation' ||
propertyName === 'facesOrientation' ||
propertyName === 'materialType' ||
propertyName === 'color'
propertyName === 'tint'
) {
objectContent[propertyName] = newValue;
return true;
Expand Down Expand Up @@ -904,10 +904,10 @@ module.exports = {
.setMeasurementUnit(gd.MeasurementUnit.getPixel())
.setGroup(_('Default size'));
objectProperties
.getOrCreate('color')
.setValue(objectContent.color || '128;128;128')
.getOrCreate('tint')
.setValue(objectContent.tint || '128;128;128')
.setType('Color')
.setLabel(_('Color'))
.setLabel(_('Tint'))
.setGroup(_('Texture'));

objectProperties
Expand Down Expand Up @@ -1099,7 +1099,7 @@ module.exports = {
topFaceResourceRepeat: false,
bottomFaceResourceRepeat: false,
materialType: 'Basic',
color: '128;128;128',
tint: '128;128;128',
};

Cube3DObject.updateInitialInstanceProperty = function (
Expand Down Expand Up @@ -1578,18 +1578,18 @@ module.exports = {

object
.addScopedAction(
'SetColor',
_('Color'),
_('Change the color of the cube.'),
_('Change the color of _PARAM0_ to _PARAM1_'),
_('Color'),
'SetTint',
_('Tint'),
_('Change the tint of the cube.'),
_('Change the tint of _PARAM0_ to _PARAM1_'),
_('Tint'),
'res/actions/color24.png',
'res/actions/color.png'
)
.addParameter('object', _('3D Cube'), 'Cube3DObject', false)
.addParameter('color', _('Color'), '', false)
.addParameter('color', _('Tint'), '', false)
.getCodeExtraInformation()
.setFunctionName('setColor');
.setFunctionName('setTint');

extension
.addExpressionAndConditionAndAction(
Expand Down Expand Up @@ -2361,7 +2361,7 @@ module.exports = {
this._facesOrientation = 'Y';
this._backFaceUpThroughWhichAxisRotation = 'X';
this._shouldUseTransparentTexture = false;
this._color = '';
this._tint = '';

const geometry = new THREE.BoxGeometry(1, 1, 1);
const materials = [
Expand All @@ -2385,16 +2385,10 @@ module.exports = {
return getTransparentMaterial();
}

const resourceName = this._faceResourceNames[faceIndex];

if (!resourceName) {
return new THREE.MeshBasicMaterial({ vertexColors: true });
}

// Utilisation du loader de ressources pour obtenir le matériau
return await this._pixiResourcesLoader.getThreeMaterial(
project,
resourceName,
this._faceResourceNames[faceIndex],
{
useTransparentTexture: this._shouldUseTransparentTexture,
}
Expand All @@ -2421,11 +2415,11 @@ module.exports = {
this._updateTextureUvMapping();
}

_updateColor() {
const colors = [];
const normalizedColor = objectsRenderingService
_updateTint() {
const tints = [];
const normalizedTint = objectsRenderingService
.hexNumberToRGBArray(
objectsRenderingService.rgbOrHexToHexNumber(this._color)
objectsRenderingService.rgbOrHexToHexNumber(this._tint)
)
.map((component) => component / 255);

Expand All @@ -2434,12 +2428,12 @@ module.exports = {
i < this._threeObject.geometry.attributes.position.count;
i++
) {
colors.push(...normalizedColor);
tints.push(...normalizedTint);
}

this._threeObject.geometry.setAttribute(
'color',
new THREE.BufferAttribute(new Float32Array(colors), 3)
new THREE.BufferAttribute(new Float32Array(tints), 3)
);
}

Expand Down Expand Up @@ -2475,18 +2469,18 @@ module.exports = {

let materialsDirty = false;
let uvMappingDirty = false;
let colorDirty = false;
let tintDirty = false;

const shouldUseTransparentTexture =
object.content.enableTextureTransparency;
if (this._shouldUseTransparentTexture !== shouldUseTransparentTexture) {
this._shouldUseTransparentTexture = shouldUseTransparentTexture;
materialsDirty = true;
}
const color = object.content.color || '128;128;128';
if (this._color !== color) {
this._color = color;
colorDirty = true;
const tint = object.content.tint || '128;128;128';
if (this._tint !== tint) {
this._tint = tint;
tintDirty = true;
}

const faceResourceNames = [
Expand Down Expand Up @@ -2580,7 +2574,7 @@ module.exports = {

if (materialsDirty) this._updateThreeObjectMaterials();
if (uvMappingDirty) this._updateTextureUvMapping();
if (colorDirty) this._updateColor();
if (tintDirty) this._updateTint();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions GDJS/Runtime/pixi-renderers/pixi-image-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ namespace gdjs {
map: this.getThreeTexture(resourceName),
side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,
transparent: useTransparentTexture,
vertexColors: true,
})
: new THREE.MeshStandardMaterial({
map: this.getThreeTexture(resourceName),
side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,
transparent: useTransparentTexture,
metalness: 0,
vertexColors: true,
});
this._loadedThreeMaterials.put(cacheKey, material);
return material;
Expand Down

0 comments on commit f609bf2

Please sign in to comment.