- Added http://game-textures/put endpoint for CEF: set texture-dict/-name/-width/-height request headers and raw pixels array (e.g., canvasContext.getImageData(...).data) in POST payload; texture dictionary name prefix "crtxd_" is added to "texture-dict" name
- Added http://game-textures/remove endpoint for CEF: set texture-dict and optional texture-name request headers
Пост запрос гружу в обычный браузер, послего его подгрузки пробую накинуть на машину текстуру через наклейку - нихуя не работает.
Client:
JavaScript:
const browser = mp.browsers.new('package://index.html');
function loadTextureDictionary(textureDict) {
if (!mp.game.graphics.hasStreamedTextureDictLoaded(textureDict)) {
mp.game.graphics.requestStreamedTextureDict(textureDict, true);
mp.console.logInfo(`Loading texture dictionary: ${textureDict}`);
while (!mp.game.graphics.hasStreamedTextureDictLoaded(textureDict)) mp.game.wait(2500);
}
mp.console.logInfo(`Texture dictionary loaded: ${textureDict}`);
}
mp.events.add('browserDomReady', () => {
const vehicle = mp.vehicles.new(mp.game.joaat('oracle'), mp.players.local.position);
if (vehicle) {
setTimeout(() => {
vehicle.setLivery(0);
loadTextureDictionary('crtxd_zhopa');
vehicle.setLiveryTexture('crtxd_zhopa', 'kaka')
mp.console.logInfo('Livery set');
}, 3000);
}
});
browser
JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script>
function waitLoadImage(image) {
return new Promise((resolve, reject) => {
image.onload = () => resolve();
image.onerror = (err) => reject(err);
});
}
(async () => {
const width = 4096;
const height = 4096;
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
const image = new Image();
image.crossOrigin = 'anonymous';
image.src = 'https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg';
await waitLoadImage(image);
console.log('image loaded');
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
console.log('image data', imageData);
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
console.log('Image displayed on canvas');
fetch('http://game-textures/put', {
method: 'POST',
body: imageData.data,
headers: {
'texture-dict': 'zhopa',
'texture-name': 'kaka',
'texture-width': canvas.width,
'texture-height': canvas.height
}
}).then((response) => {
console.log('response', response);
});
})();
</script>
<body>
</body>
</html>