From 23616628cacd41364cd780252a3c0b74c1d84441 Mon Sep 17 00:00:00 2001 From: tuckie <22203973+twuky@users.noreply.github.com> Date: Mon, 27 Mar 2023 16:33:59 -0700 Subject: [PATCH 1/5] generator uses Uint8Arrays for unsigned char pointers --- tools/generate_templates/ArgumentTypeConversion.js | 4 ++-- tools/generate_templates/node-raylib-bindings.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/generate_templates/ArgumentTypeConversion.js b/tools/generate_templates/ArgumentTypeConversion.js index e8ebf67..357896b 100644 --- a/tools/generate_templates/ArgumentTypeConversion.js +++ b/tools/generate_templates/ArgumentTypeConversion.js @@ -1,6 +1,6 @@ function ArgumentTypeConversion (arg) { - if (arg === 'const unsigned char *') { return 'Buffer' } - if (arg === 'unsigned char *') { return 'Buffer' } + if (arg === 'const unsigned char *') { return 'UInt8Array' } + if (arg === 'unsigned char *') { return 'UInt8Array' } if (arg === 'char') { return 'string' } if (arg === 'char *') { return 'string' } diff --git a/tools/generate_templates/node-raylib-bindings.js b/tools/generate_templates/node-raylib-bindings.js index 68f90c9..b79daee 100644 --- a/tools/generate_templates/node-raylib-bindings.js +++ b/tools/generate_templates/node-raylib-bindings.js @@ -26,6 +26,12 @@ const SanitizeTypeName = name => { if (name === 'const char *') { return 'string' } + if (name === 'const unsigned char *') { + return 'bufferPointer' + } + if (name === 'unsigned char *') { + return 'bufferPointer' + } if (name.endsWith('*')) { return 'pointer' } @@ -241,6 +247,9 @@ inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } +uintptr_t bufferPointerFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } From f6396ded68d1915886d1a7c59293e18a45fe0117 Mon Sep 17 00:00:00 2001 From: tuckie <22203973+twuky@users.noreply.github.com> Date: Mon, 27 Mar 2023 16:34:53 -0700 Subject: [PATCH 2/5] run generator; standard fix --- docs/API.md | 52 ++++++++++++++++---------------- src/generated/node-raylib-drm.js | 32 ++++++++++---------- src/generated/node-raylib.cc | 29 ++++++++++-------- src/generated/node-raylib.d.ts | 32 ++++++++++---------- src/generated/node-raylib.js | 32 ++++++++++---------- 5 files changed, 90 insertions(+), 87 deletions(-) diff --git a/docs/API.md b/docs/API.md index ab2e930..94d86ed 100644 --- a/docs/API.md +++ b/docs/API.md @@ -295,7 +295,7 @@
OpenURL(url)undefined

Open URL with default system browser (if available)

-
LoadFileData(fileName, bytesRead)Buffer
+
LoadFileData(fileName, bytesRead)UInt8Array

Load file data as byte array (read)

UnloadFileData(data)undefined
@@ -376,16 +376,16 @@
GetFileModTime(fileName)number

Get file modification time (last write time)

-
CompressData(data, dataSize, compDataSize)Buffer
+
CompressData(data, dataSize, compDataSize)UInt8Array

Compress data (DEFLATE algorithm), memory must be MemFree()

-
DecompressData(compData, compDataSize, dataSize)Buffer
+
DecompressData(compData, compDataSize, dataSize)UInt8Array

Decompress data (DEFLATE algorithm), memory must be MemFree()

EncodeDataBase64(data, dataSize, outputSize)string

Encode data to Base64 string, memory must be MemFree()

-
DecodeDataBase64(data, outputSize)Buffer
+
DecodeDataBase64(data, outputSize)UInt8Array

Decode Base64 string data, memory must be MemFree()

IsKeyPressed(key)boolean
@@ -1891,7 +1891,7 @@
rlReadTexturePixels(id, width, height, format)number

Read texture pixel data

-
rlReadScreenPixels(width, height)Buffer
+
rlReadScreenPixels(width, height)UInt8Array

Read screen pixel data (color buffer)

rlLoadFramebuffer(width, height)number
@@ -3093,11 +3093,11 @@ Open URL with default system browser (if available) -## LoadFileData(fileName, bytesRead) ⇒ Buffer +## LoadFileData(fileName, bytesRead) ⇒ UInt8Array Load file data as byte array (read) **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | @@ -3113,7 +3113,7 @@ Unload file data allocated by LoadFileData() | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | @@ -3139,7 +3139,7 @@ Export data to code (.h), returns true on success | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | size | number | | fileName | string | @@ -3402,29 +3402,29 @@ Get file modification time (last write time) -## CompressData(data, dataSize, compDataSize) ⇒ Buffer +## CompressData(data, dataSize, compDataSize) ⇒ UInt8Array Compress data (DEFLATE algorithm), memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | dataSize | number | | compDataSize | number | -## DecompressData(compData, compDataSize, dataSize) ⇒ Buffer +## DecompressData(compData, compDataSize, dataSize) ⇒ UInt8Array Decompress data (DEFLATE algorithm), memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| compData | Buffer | +| compData | UInt8Array | | compDataSize | number | | dataSize | number | @@ -3438,21 +3438,21 @@ Encode data to Base64 string, memory must be MemFree() | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | dataSize | number | | outputSize | number | -## DecodeDataBase64(data, outputSize) ⇒ Buffer +## DecodeDataBase64(data, outputSize) ⇒ UInt8Array Decode Base64 string data, memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | outputSize | number | @@ -4650,7 +4650,7 @@ Load image from memory buffer, fileType refers to extension: i.e. '.png' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | @@ -5512,7 +5512,7 @@ Load font from memory buffer, fileType refers to extension: i.e. '.ttf' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | | fontSize | number | | fontChars | number | @@ -5540,7 +5540,7 @@ Load font data for further use | Param | Type | | --- | --- | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | | fontSize | number | | fontChars | number | @@ -6968,7 +6968,7 @@ Load wave from memory buffer, fileType refers to extension: i.e. '.wav' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | @@ -7230,7 +7230,7 @@ Load music stream from data | Param | Type | | --- | --- | | fileType | string | -| data | Buffer | +| data | UInt8Array | | dataSize | number | @@ -9622,11 +9622,11 @@ Read texture pixel data -## rlReadScreenPixels(width, height) ⇒ Buffer +## rlReadScreenPixels(width, height) ⇒ UInt8Array Read screen pixel data (color buffer) **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | diff --git a/src/generated/node-raylib-drm.js b/src/generated/node-raylib-drm.js index fc21812..84df6d5 100644 --- a/src/generated/node-raylib-drm.js +++ b/src/generated/node-raylib-drm.js @@ -1381,7 +1381,7 @@ raylib.OpenURL = OpenURL * @param {string} fileName * @param {number} bytesRead * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function LoadFileData (fileName, bytesRead) { return r.BindLoadFileData( @@ -1394,7 +1394,7 @@ raylib.LoadFileData = LoadFileData /** * Unload file data allocated by LoadFileData() * - * @param {Buffer} data + * @param {UInt8Array} data * * @return {undefined} */ @@ -1426,7 +1426,7 @@ raylib.SaveFileData = SaveFileData /** * Export data to code (.h), returns true on success * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} size * @param {string} fileName * @@ -1762,11 +1762,11 @@ raylib.GetFileModTime = GetFileModTime /** * Compress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} compDataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function CompressData (data, dataSize, compDataSize) { return r.BindCompressData( @@ -1780,11 +1780,11 @@ raylib.CompressData = CompressData /** * Decompress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} compData + * @param {UInt8Array} compData * @param {number} compDataSize * @param {number} dataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecompressData (compData, compDataSize, dataSize) { return r.BindDecompressData( @@ -1798,7 +1798,7 @@ raylib.DecompressData = DecompressData /** * Encode data to Base64 string, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} outputSize * @@ -1816,10 +1816,10 @@ raylib.EncodeDataBase64 = EncodeDataBase64 /** * Decode Base64 string data, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} outputSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecodeDataBase64 (data, outputSize) { return r.BindDecodeDataBase64( @@ -3664,7 +3664,7 @@ raylib.LoadImageAnim = LoadImageAnim * Load image from memory buffer, fileType refers to extension: i.e. '.png' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Image} The resulting Image. @@ -5045,7 +5045,7 @@ raylib.LoadFontFromImage = LoadFontFromImage * Load font from memory buffer, fileType refers to extension: i.e. '.ttf' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize * @param {number} fontChars @@ -5091,7 +5091,7 @@ raylib.IsFontReady = IsFontReady /** * Load font data for further use * - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize * @param {number} fontChars @@ -7732,7 +7732,7 @@ raylib.LoadWave = LoadWave * Load wave from memory buffer, fileType refers to extension: i.e. '.wav' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Wave} The resulting Wave. @@ -8141,7 +8141,7 @@ raylib.LoadMusicStream = LoadMusicStream * Load music stream from data * * @param {string} fileType - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * * @return {Music} The resulting Music. @@ -13059,7 +13059,7 @@ raylib.rlReadTexturePixels = rlReadTexturePixels * @param {number} width * @param {number} height * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function rlReadScreenPixels (width, height) { return r.BindrlReadScreenPixels( diff --git a/src/generated/node-raylib.cc b/src/generated/node-raylib.cc index b0ea9d3..d2009b9 100644 --- a/src/generated/node-raylib.cc +++ b/src/generated/node-raylib.cc @@ -61,6 +61,9 @@ inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } +uintptr_t bufferPointerFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } @@ -255,11 +258,11 @@ inline Mesh MeshFromValue(const Napi::CallbackInfo& info, int index) { (float *) pointerFromValue(info, index + 4), (float *) pointerFromValue(info, index + 5), (float *) pointerFromValue(info, index + 6), - (unsigned char *) pointerFromValue(info, index + 7), + (unsigned char *) bufferPointerFromValue(info, index + 7), (unsigned short *) pointerFromValue(info, index + 8), (float *) pointerFromValue(info, index + 9), (float *) pointerFromValue(info, index + 10), - (unsigned char *) pointerFromValue(info, index + 11), + (unsigned char *) bufferPointerFromValue(info, index + 11), (float *) pointerFromValue(info, index + 12), unsignedintFromValue(info, index + 13), (unsigned int *) pointerFromValue(info, index + 14) @@ -1138,7 +1141,7 @@ Napi::Value BindSaveFileData(const Napi::CallbackInfo& info) { Napi::Value BindExportDataAsCode(const Napi::CallbackInfo& info) { return ToValue(info.Env(), ExportDataAsCode( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), unsignedintFromValue(info, 1), (const char *) stringFromValue(info, 2) ) @@ -1312,7 +1315,7 @@ Napi::Value BindGetFileModTime(const Napi::CallbackInfo& info) { Napi::Value BindCompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), CompressData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1322,7 +1325,7 @@ Napi::Value BindCompressData(const Napi::CallbackInfo& info) { Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecompressData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1332,7 +1335,7 @@ Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), EncodeDataBase64( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1342,7 +1345,7 @@ Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { Napi::Value BindDecodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecodeDataBase64( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), (int *) pointerFromValue(info, 1) ) ); @@ -1792,7 +1795,7 @@ Napi::Value BindLoadImageFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadImageFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) bufferPointerFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2230,7 +2233,7 @@ Napi::Value BindLoadFontFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) bufferPointerFromValue(info, 1), intFromValue(info, 2), intFromValue(info, 3), (int *) pointerFromValue(info, 4), @@ -2250,7 +2253,7 @@ Napi::Value BindIsFontReady(const Napi::CallbackInfo& info) { Napi::Value BindLoadFontData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) bufferPointerFromValue(info, 0), intFromValue(info, 1), intFromValue(info, 2), (int *) pointerFromValue(info, 3), @@ -2787,7 +2790,7 @@ Napi::Value BindLoadWaveFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadWaveFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) bufferPointerFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2879,7 +2882,7 @@ Napi::Value BindLoadMusicStreamFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadMusicStreamFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) bufferPointerFromValue(info, 1), intFromValue(info, 2) ) ); @@ -5213,7 +5216,7 @@ void BindOpenURL(const Napi::CallbackInfo& info) { void BindUnloadFileData(const Napi::CallbackInfo& info) { UnloadFileData( - (unsigned char *) pointerFromValue(info, 0) + (unsigned char *) bufferPointerFromValue(info, 0) ); } diff --git a/src/generated/node-raylib.d.ts b/src/generated/node-raylib.d.ts index 54a9521..8d42b3f 100644 --- a/src/generated/node-raylib.d.ts +++ b/src/generated/node-raylib.d.ts @@ -203,7 +203,7 @@ declare module "raylib" { /** Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4). (float *) */ tangents: number /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ - colors: Buffer + colors: UInt8Array /** Vertex indices (in case vertex data comes indexed). (unsigned short *) */ indices: number /** Animated vertex positions (after bones transformations). (float *) */ @@ -211,7 +211,7 @@ declare module "raylib" { /** Animated normals (after bones transformations). (float *) */ animNormals: number /** Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning). (unsigned char *) */ - boneIds: Buffer + boneIds: UInt8Array /** Vertex bone weight, up to 4 bones influence by vertex (skinning). (float *) */ boneWeights: number /** OpenGL Vertex Array Object id. (unsigned int) */ @@ -423,7 +423,7 @@ declare module "raylib" { /** Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1). (float *) */ texcoords: number /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ - colors: Buffer + colors: UInt8Array /** Vertex indices (in case vertex data comes indexed) (6 indices per quad). (unsigned int *) */ indices: number /** OpenGL Vertex Array Object id. (unsigned int) */ @@ -767,16 +767,16 @@ declare module "raylib" { export function OpenURL(url: string): void /** Load file data as byte array (read) */ - export function LoadFileData(fileName: string, bytesRead: number): Buffer + export function LoadFileData(fileName: string, bytesRead: number): UInt8Array /** Unload file data allocated by LoadFileData() */ - export function UnloadFileData(data: Buffer): void + export function UnloadFileData(data: UInt8Array): void /** Save data to file from byte array (write), returns true on success */ export function SaveFileData(fileName: string, data: number, bytesToWrite: number): boolean /** Export data to code (.h), returns true on success */ - export function ExportDataAsCode(data: Buffer, size: number, fileName: string): boolean + export function ExportDataAsCode(data: UInt8Array, size: number, fileName: string): boolean /** Load text data from file (read), returns a '\0' terminated string */ export function LoadFileText(fileName: string): string @@ -848,16 +848,16 @@ declare module "raylib" { export function GetFileModTime(fileName: string): number /** Compress data (DEFLATE algorithm), memory must be MemFree() */ - export function CompressData(data: Buffer, dataSize: number, compDataSize: number): Buffer + export function CompressData(data: UInt8Array, dataSize: number, compDataSize: number): UInt8Array /** Decompress data (DEFLATE algorithm), memory must be MemFree() */ - export function DecompressData(compData: Buffer, compDataSize: number, dataSize: number): Buffer + export function DecompressData(compData: UInt8Array, compDataSize: number, dataSize: number): UInt8Array /** Encode data to Base64 string, memory must be MemFree() */ - export function EncodeDataBase64(data: Buffer, dataSize: number, outputSize: number): string + export function EncodeDataBase64(data: UInt8Array, dataSize: number, outputSize: number): string /** Decode Base64 string data, memory must be MemFree() */ - export function DecodeDataBase64(data: Buffer, outputSize: number): Buffer + export function DecodeDataBase64(data: UInt8Array, outputSize: number): UInt8Array /** Check if a key has been pressed once */ export function IsKeyPressed(key: number): boolean @@ -1151,7 +1151,7 @@ declare module "raylib" { export function LoadImageAnim(fileName: string, frames: number): Image /** Load image from memory buffer, fileType refers to extension: i.e. '.png' */ - export function LoadImageFromMemory(fileType: string, fileData: Buffer, dataSize: number): Image + export function LoadImageFromMemory(fileType: string, fileData: UInt8Array, dataSize: number): Image /** Load image from GPU texture data */ export function LoadImageFromTexture(texture: Texture): Image @@ -1460,13 +1460,13 @@ declare module "raylib" { export function LoadFontFromImage(image: Image, key: Color, firstChar: number): Font /** Load font from memory buffer, fileType refers to extension: i.e. '.ttf' */ - export function LoadFontFromMemory(fileType: string, fileData: Buffer, dataSize: number, fontSize: number, fontChars: number, glyphCount: number): Font + export function LoadFontFromMemory(fileType: string, fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: number, glyphCount: number): Font /** Check if a font is ready */ export function IsFontReady(font: Font): boolean /** Load font data for further use */ - export function LoadFontData(fileData: Buffer, dataSize: number, fontSize: number, fontChars: number, glyphCount: number, type: number): number + export function LoadFontData(fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: number, glyphCount: number, type: number): number /** Generate image font atlas using chars info */ export function GenImageFontAtlas(chars: number, recs: number, glyphCount: number, fontSize: number, padding: number, packMethod: number): Image @@ -1793,7 +1793,7 @@ declare module "raylib" { export function LoadWave(fileName: string): Wave /** Load wave from memory buffer, fileType refers to extension: i.e. '.wav' */ - export function LoadWaveFromMemory(fileType: string, fileData: Buffer, dataSize: number): Wave + export function LoadWaveFromMemory(fileType: string, fileData: UInt8Array, dataSize: number): Wave /** Checks if wave data is ready */ export function IsWaveReady(wave: Wave): boolean @@ -1865,7 +1865,7 @@ declare module "raylib" { export function LoadMusicStream(fileName: string): Music /** Load music stream from data */ - export function LoadMusicStreamFromMemory(fileType: string, data: Buffer, dataSize: number): Music + export function LoadMusicStreamFromMemory(fileType: string, data: UInt8Array, dataSize: number): Music /** Checks if a music stream is ready */ export function IsMusicReady(music: Music): boolean @@ -2855,7 +2855,7 @@ declare module "raylib" { export function rlReadTexturePixels(id: number, width: number, height: number, format: number): number /** Read screen pixel data (color buffer) */ - export function rlReadScreenPixels(width: number, height: number): Buffer + export function rlReadScreenPixels(width: number, height: number): UInt8Array /** Load an empty framebuffer */ export function rlLoadFramebuffer(width: number, height: number): number diff --git a/src/generated/node-raylib.js b/src/generated/node-raylib.js index 7b793ae..f2dbe95 100644 --- a/src/generated/node-raylib.js +++ b/src/generated/node-raylib.js @@ -1381,7 +1381,7 @@ raylib.OpenURL = OpenURL * @param {string} fileName * @param {number} bytesRead * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function LoadFileData (fileName, bytesRead) { return r.BindLoadFileData( @@ -1394,7 +1394,7 @@ raylib.LoadFileData = LoadFileData /** * Unload file data allocated by LoadFileData() * - * @param {Buffer} data + * @param {UInt8Array} data * * @return {undefined} */ @@ -1426,7 +1426,7 @@ raylib.SaveFileData = SaveFileData /** * Export data to code (.h), returns true on success * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} size * @param {string} fileName * @@ -1762,11 +1762,11 @@ raylib.GetFileModTime = GetFileModTime /** * Compress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} compDataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function CompressData (data, dataSize, compDataSize) { return r.BindCompressData( @@ -1780,11 +1780,11 @@ raylib.CompressData = CompressData /** * Decompress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} compData + * @param {UInt8Array} compData * @param {number} compDataSize * @param {number} dataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecompressData (compData, compDataSize, dataSize) { return r.BindDecompressData( @@ -1798,7 +1798,7 @@ raylib.DecompressData = DecompressData /** * Encode data to Base64 string, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} outputSize * @@ -1816,10 +1816,10 @@ raylib.EncodeDataBase64 = EncodeDataBase64 /** * Decode Base64 string data, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} outputSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecodeDataBase64 (data, outputSize) { return r.BindDecodeDataBase64( @@ -3664,7 +3664,7 @@ raylib.LoadImageAnim = LoadImageAnim * Load image from memory buffer, fileType refers to extension: i.e. '.png' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Image} The resulting Image. @@ -5045,7 +5045,7 @@ raylib.LoadFontFromImage = LoadFontFromImage * Load font from memory buffer, fileType refers to extension: i.e. '.ttf' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize * @param {number} fontChars @@ -5091,7 +5091,7 @@ raylib.IsFontReady = IsFontReady /** * Load font data for further use * - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize * @param {number} fontChars @@ -7732,7 +7732,7 @@ raylib.LoadWave = LoadWave * Load wave from memory buffer, fileType refers to extension: i.e. '.wav' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Wave} The resulting Wave. @@ -8141,7 +8141,7 @@ raylib.LoadMusicStream = LoadMusicStream * Load music stream from data * * @param {string} fileType - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * * @return {Music} The resulting Music. @@ -13059,7 +13059,7 @@ raylib.rlReadTexturePixels = rlReadTexturePixels * @param {number} width * @param {number} height * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function rlReadScreenPixels (width, height) { return r.BindrlReadScreenPixels( From 803db61fcbe1fde168e5111e36e42b1d39485a68 Mon Sep 17 00:00:00 2001 From: tuckie <22203973+twuky@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:35:11 -0700 Subject: [PATCH 3/5] add other TypedArray types --- docs/API.md | 172 ++++++++++--- examples/models/models_animation.js | 108 +++++++++ examples/textures/textures_from_memory.js | 4 +- src/generated/node-raylib-drm.js | 229 ++++++++++++++++-- src/generated/node-raylib.cc | 196 +++++++++++---- src/generated/node-raylib.d.ts | 99 +++++--- src/generated/node-raylib.js | 229 ++++++++++++++++-- tools/generate.js | 2 +- .../ArgumentTypeConversion.js | 45 +++- .../node-raylib-bindings.js | 92 +++++-- .../node-raylib-definitions.js | 2 +- .../generate_templates/node-raylib-wrapper.js | 2 +- 12 files changed, 979 insertions(+), 201 deletions(-) create mode 100644 examples/models/models_animation.js diff --git a/docs/API.md b/docs/API.md index 94d86ed..2aa2c79 100644 --- a/docs/API.md +++ b/docs/API.md @@ -934,7 +934,7 @@
UnloadUTF8(text)undefined

Unload UTF-8 text encoded from codepoints array

-
LoadCodepoints(text, count)number
+
LoadCodepoints(text, count)Int32Array

Load all codepoints from a UTF-8 text string, codepoints count returned by parameter

UnloadCodepoints(codepoints)undefined
@@ -1105,6 +1105,12 @@
UnloadMesh(mesh)undefined

Unload mesh data from CPU and GPU

+
DrawMesh(mesh, material, transform)undefined
+

Draw a 3d mesh with material and transform

+
+
DrawMeshInstanced(mesh, material, transforms, instances)undefined
+

Draw multiple mesh instances with material and different transforms

+
ExportMesh(mesh, fileName)boolean

Export mesh data to file, returns true on success

@@ -1144,6 +1150,18 @@
GenMeshCubicmap(cubicmap, cubeSize)Mesh

Generate cubes-based map mesh from image data

+
LoadMaterials(fileName, materialCount)number
+

Load materials from model file

+
+
LoadMaterialDefault()Material
+

Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)

+
+
IsMaterialReady(material)boolean
+

Check if a material is ready

+
+
UnloadMaterial(material)undefined
+

Unload material from GPU memory (VRAM)

+
LoadModelAnimations(fileName, animCount)number

Load model animations from file

@@ -1255,7 +1273,7 @@
WaveCopy(wave)Wave

Copy a wave to a new wave

-
LoadWaveSamples(wave)number
+
LoadWaveSamples(wave)Float32Array

Load samples data from wave as a 32bit float data array

UnloadWaveSamples(samples)undefined
@@ -1585,7 +1603,7 @@
GuiIconText(iconId, text)string

Get text with icon id prepended (if supported)

-
GuiGetIcons()number
+
GuiGetIcons()UInt32Array

Get raygui icons data pointer

GuiLoadIcons(fileName, loadIconsName)number
@@ -1822,7 +1840,7 @@
rlGetShaderIdDefault()number

Get default shader id

-
rlGetShaderLocsDefault()number
+
rlGetShaderLocsDefault()Int32Array

Get default shader locations

rlLoadRenderBatch(numBuffers, bufferElements)rlRenderBatch
@@ -2119,6 +2137,9 @@
GenMeshTangents(mesh)undefined

Compute mesh tangents

+
SetMaterialTexture(material, mapType, texture)undefined
+

Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...)

+
SetModelMeshMaterial(model, meshId, materialId)undefined

Set material for a mesh

@@ -5484,7 +5505,7 @@ Load font from file with extended parameters, use NULL for fontChars and 0 for g | --- | --- | | fileName | string | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | @@ -5515,7 +5536,7 @@ Load font from memory buffer, fileType refers to extension: i.e. '.ttf' | fileData | UInt8Array | | dataSize | number | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | @@ -5543,7 +5564,7 @@ Load font data for further use | fileData | UInt8Array | | dataSize | number | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | | type | number | @@ -5686,7 +5707,7 @@ Draw multiple character (codepoint) | Param | Type | | --- | --- | | font | Font | -| codepoints | number | +| codepoints | Int32Array | | count | number | | position | [Vector2](#Vector2) | | fontSize | number | @@ -5770,7 +5791,7 @@ Load UTF-8 text encoded from codepoints array | Param | Type | | --- | --- | -| codepoints | number | +| codepoints | Int32Array | | length | number | @@ -5786,11 +5807,11 @@ Unload UTF-8 text encoded from codepoints array -## LoadCodepoints(text, count) ⇒ number +## LoadCodepoints(text, count) ⇒ Int32Array Load all codepoints from a UTF-8 text string, codepoints count returned by parameter **Kind**: global function -**Returns**: number - The resulting int *. +**Returns**: Int32Array - The resulting int *. | Param | Type | | --- | --- | @@ -5806,7 +5827,7 @@ Unload codepoints data from memory | Param | Type | | --- | --- | -| codepoints | number | +| codepoints | Int32Array | @@ -5870,7 +5891,7 @@ Encode one codepoint into UTF-8 byte array (array length returned as parameter) | Param | Type | | --- | --- | | codepoint | number | -| utf8Size | number | +| utf8Size | Int32Array | @@ -6560,6 +6581,33 @@ Unload mesh data from CPU and GPU | --- | --- | | mesh | Mesh | + + +## DrawMesh(mesh, material, transform) ⇒ undefined +Draw a 3d mesh with material and transform + +**Kind**: global function + +| Param | Type | +| --- | --- | +| mesh | Mesh | +| material | Material | +| transform | Matrix | + + + +## DrawMeshInstanced(mesh, material, transforms, instances) ⇒ undefined +Draw multiple mesh instances with material and different transforms + +**Kind**: global function + +| Param | Type | +| --- | --- | +| mesh | Mesh | +| material | Material | +| transforms | number | +| instances | number | + ## ExportMesh(mesh, fileName) ⇒ boolean @@ -6739,6 +6787,49 @@ Generate cubes-based map mesh from image data | cubicmap | Image | | cubeSize | [Vector3](#Vector3) | + + +## LoadMaterials(fileName, materialCount) ⇒ number +Load materials from model file + +**Kind**: global function +**Returns**: number - The resulting Material *. + +| Param | Type | +| --- | --- | +| fileName | string | +| materialCount | number | + + + +## LoadMaterialDefault() ⇒ Material +Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) + +**Kind**: global function +**Returns**: Material - The resulting Material. + + +## IsMaterialReady(material) ⇒ boolean +Check if a material is ready + +**Kind**: global function +**Returns**: boolean - The resulting bool. + +| Param | Type | +| --- | --- | +| material | Material | + + + +## UnloadMaterial(material) ⇒ undefined +Unload material from GPU memory (VRAM) + +**Kind**: global function + +| Param | Type | +| --- | --- | +| material | Material | + ## LoadModelAnimations(fileName, animCount) ⇒ number @@ -7186,11 +7277,11 @@ Copy a wave to a new wave -## LoadWaveSamples(wave) ⇒ number +## LoadWaveSamples(wave) ⇒ Float32Array Load samples data from wave as a 32bit float data array **Kind**: global function -**Returns**: number - The resulting float *. +**Returns**: Float32Array - The resulting float *. | Param | Type | | --- | --- | @@ -7205,7 +7296,7 @@ Unload samples data loaded with LoadWaveSamples() | Param | Type | | --- | --- | -| samples | number | +| samples | Float32Array | @@ -8146,7 +8237,7 @@ Tab Bar control, returns TAB to be closed or -1 | bounds | [Rectangle](#Rectangle) | | text | number | | count | number | -| active | number | +| active | Int32Array | @@ -8269,7 +8360,7 @@ Dropdown Box control, returns selected item | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| active | number | +| active | Int32Array | | editMode | boolean | @@ -8284,7 +8375,7 @@ Spinner control, returns selected value | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| value | number | +| value | Int32Array | | minValue | number | | maxValue | number | | editMode | boolean | @@ -8301,7 +8392,7 @@ Value Box control, updates input text with numbers | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| value | number | +| value | Int32Array | | minValue | number | | maxValue | number | | editMode | boolean | @@ -8438,7 +8529,7 @@ List View control, returns selected list item index | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| scrollIndex | number | +| scrollIndex | Int32Array | | active | number | @@ -8454,8 +8545,8 @@ List View with extended parameters | bounds | [Rectangle](#Rectangle) | | text | number | | count | number | -| focus | number | -| scrollIndex | number | +| focus | Int32Array | +| scrollIndex | Int32Array | | active | number | @@ -8489,7 +8580,7 @@ Text Input Box control, ask for text, supports secret | buttons | string | | text | string | | textMaxSize | number | -| secretViewActive | number | +| secretViewActive | Int32Array | @@ -8602,11 +8693,11 @@ Get text with icon id prepended (if supported) -## GuiGetIcons() ⇒ number +## GuiGetIcons() ⇒ UInt32Array Get raygui icons data pointer **Kind**: global function -**Returns**: number - The resulting unsigned int *. +**Returns**: UInt32Array - The resulting unsigned int *. ## GuiLoadIcons(fileName, loadIconsName) ⇒ number @@ -8709,7 +8800,7 @@ Multiply the current matrix by another matrix | Param | Type | | --- | --- | -| matf | number | +| matf | Float32Array | @@ -9335,11 +9426,11 @@ Get default shader id **Returns**: number - The resulting unsigned int. -## rlGetShaderLocsDefault() ⇒ number +## rlGetShaderLocsDefault() ⇒ Int32Array Get default shader locations **Kind**: global function -**Returns**: number - The resulting int *. +**Returns**: Int32Array - The resulting int *. ## rlLoadRenderBatch(numBuffers, bufferElements) ⇒ rlRenderBatch @@ -9563,9 +9654,9 @@ Get OpenGL internal formats | Param | Type | | --- | --- | | format | number | -| glInternalFormat | number | -| glFormat | number | -| glType | number | +| glInternalFormat | UInt32Array | +| glFormat | UInt32Array | +| glType | UInt32Array | @@ -9603,7 +9694,7 @@ Generate mipmap data for selected texture | width | number | | height | number | | format | number | -| mipmaps | number | +| mipmaps | Int32Array | @@ -9808,7 +9899,7 @@ Set shader currently active (id and locations) | Param | Type | | --- | --- | | id | number | -| locs | number | +| locs | Int32Array | @@ -10560,6 +10651,19 @@ Compute mesh tangents | --- | --- | | mesh | Mesh | + + +## SetMaterialTexture(material, mapType, texture) ⇒ undefined +Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) + +**Kind**: global function + +| Param | Type | +| --- | --- | +| material | Material | +| mapType | number | +| texture | Texture | + ## SetModelMeshMaterial(model, meshId, materialId) ⇒ undefined diff --git a/examples/models/models_animation.js b/examples/models/models_animation.js new file mode 100644 index 0000000..d7c4545 --- /dev/null +++ b/examples/models/models_animation.js @@ -0,0 +1,108 @@ +/******************************************************************************************* +* +* raylib [models] example - Load 3d model with animations and play them +* +* Example originally created with raylib 2.5, last time updated with raylib 3.5 +* +* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2023 Culacant (@culacant) and Ramon Santamaria (@raysan5) +* +******************************************************************************************** +* +* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be +* in the same position as they would be in edit mode and the scale of your models is +* set to 0. Scaling can be done from the export menu. +* +********************************************************************************************/ + +const r = require('raylib') +const { join } = require('path') + +// Initialization +// -------------------------------------------------------------------------------------- +const screenWidth = 800 +const screenHeight = 450 + +r.InitWindow(screenWidth, screenHeight, 'raylib [models] example - model animation') + +// Define the camera to look into our 3d world +const camera = { + position: { x: 10, y: 10, z: 10 }, // Camera position + target: { x: 0, y: 0, z: 0 }, // Camera looking at point + up: { x: 0, y: 1, z: 0 }, // Camera up vector (rotation towards target) + fovy: 45, // Camera field-of-view Y + projection: r.CAMERA_PERSPECTIVE // Camera mode type +} + +const model = r.LoadModel(join(__dirname, 'resources', 'guy', 'guy.iqm')) // Load the animated model mesh and basic data +const texture = r.LoadTexture(join(__dirname, 'resources', 'guy', 'guytex.png')) // Load model texture and set material + +// this will fail as it can't return an array of materials +const materials = r.LoadMaterials(join(__dirname, 'resources', 'guy', 'guy.iqm'), 1) +console.log('materials: ', materials) + +r.SetMaterialTexture(model.materials[0], r.MATERIAL_MAP_DIFFUSE, texture) // Set model material map texture + +const position = { x: 0, y: 0, z: 0 } // Set model position + +// Load animation data +let animsCount = 0 +const anims = r.LoadModelAnimations('resources/models/iqm/guyanim.iqm', animsCount) +animsCount = anims.length +let animFrameCounter = 0 + +r.DisableCursor() // Catch cursor +r.SetTargetFPS(60) // Set our game to run at 60 frames-per-second +// -------------------------------------------------------------------------------------- + +// Main game loop +while (!r.WindowShouldClose()) { // Detect window close button or ESC key + // Update + // ---------------------------------------------------------------------------------- + r.UpdateCamera(camera, r.CAMERA_FIRST_PERSON) + + // Play animation when spacebar is held down + if (r.IsKeyDown(r.KEY_SPACE)) { + animFrameCounter++ + r.UpdateModelAnimation(model, anims[0], animFrameCounter) + if (animFrameCounter >= anims[0].frameCount) animFrameCounter = 0 + } + // ---------------------------------------------------------------------------------- + + // Draw + // ---------------------------------------------------------------------------------- + r.BeginDrawing() + + r.ClearBackground(r.RAYWHITE) + + r.BeginMode3D(camera) + + r.DrawModelEx(model, position, { x: 0, y: 0, z: 0 }, -90, { x: 1, y: 1, z: 1 }, r.WHITE) + + for (let i = 0; i < model.boneCount; i++) { + r.DrawCube(anims[0].framePoses[animFrameCounter][i].translation, 0.2, 0.2, 0.2, r.RED) + } + + r.DrawGrid(10, 1) // Draw a grid + + r.EndMode3D() + + r.DrawText('PRESS SPACE to PLAY MODEL ANIMATION', 10, 10, 20, r.MAROON) + r.DrawText('(c) Guy IQM 3D model by @culacant', screenWidth - 200, screenHeight - 20, 10, r.GRAY) + + r.EndDrawing() + // ---------------------------------------------------------------------------------- +} + +// De-Initialization +// -------------------------------------------------------------------------------------- +r.UnloadTexture(texture) // Unload texture +r.UnloadModelAnimations(anims, animsCount) // Unload model animations data +r.UnloadModel(model) // Unload model + +r.CloseWindow() // Close window and OpenGL context +// -------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_from_memory.js b/examples/textures/textures_from_memory.js index 49143ed..4caadd7 100644 --- a/examples/textures/textures_from_memory.js +++ b/examples/textures/textures_from_memory.js @@ -21,12 +21,12 @@ const screenHeight = 450 // Load the image using fs module into a `Buffer` instance. // NOTE: this `Buffer` could come from *anywhere* (statically encoded in your source code, as a // partial read from a custom resource packer file, etc.) -const raw = readFileSync(resolve(__dirname, 'resources', 'wabbit_alpha.png')) +const raw = readFileSync(resolve(__dirname, 'resources', 'raylib_logo.png')) r.InitWindow(screenWidth, screenHeight, 'raylib [textures] example - image loading from memory') // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) -const image = r.LoadImageFromMemory('png', raw, raw.length) // Loaded in CPU memory (RAM) +const image = r.LoadImageFromMemory('.png', raw, raw.length) // Loaded in CPU memory (RAM) if (!image) { console.error('image failed to load!') process.exit(1) diff --git a/src/generated/node-raylib-drm.js b/src/generated/node-raylib-drm.js index 84df6d5..1630c5c 100644 --- a/src/generated/node-raylib-drm.js +++ b/src/generated/node-raylib-drm.js @@ -5001,7 +5001,7 @@ raylib.LoadFont = LoadFont * * @param {string} fileName * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5048,7 +5048,7 @@ raylib.LoadFontFromImage = LoadFontFromImage * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5094,7 +5094,7 @@ raylib.IsFontReady = IsFontReady * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * @param {number} type * @@ -5359,7 +5359,7 @@ raylib.DrawTextCodepoint = DrawTextCodepoint * Draw multiple character (codepoint) * * @param {Font} font - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} count * @param {Vector2} position * @param {number} fontSize @@ -5517,7 +5517,7 @@ raylib.GetGlyphAtlasRec = GetGlyphAtlasRec /** * Load UTF-8 text encoded from codepoints array * - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} length * * @return {string} The resulting char *. @@ -5550,7 +5550,7 @@ raylib.UnloadUTF8 = UnloadUTF8 * @param {string} text * @param {number} count * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function LoadCodepoints (text, count) { return r.BindLoadCodepoints( @@ -5563,7 +5563,7 @@ raylib.LoadCodepoints = LoadCodepoints /** * Unload codepoints data from memory * - * @param {number} codepoints + * @param {Int32Array} codepoints * * @return {undefined} */ @@ -5640,7 +5640,7 @@ raylib.GetCodepointPrevious = GetCodepointPrevious * Encode one codepoint into UTF-8 byte array (array length returned as parameter) * * @param {number} codepoint - * @param {number} utf8Size + * @param {Int32Array} utf8Size * * @return {string} The resulting const char *. */ @@ -7023,6 +7023,93 @@ function UnloadMesh (mesh) { } raylib.UnloadMesh = UnloadMesh +/** + * Draw a 3d mesh with material and transform + * + * @param {Mesh} mesh + * @param {Material} material + * @param {Matrix} transform + * + * @return {undefined} + */ +function DrawMesh (mesh, material, transform) { + return r.BindDrawMesh( + mesh.vertexCount, + mesh.triangleCount, + mesh.vertices, + mesh.texcoords, + mesh.texcoords2, + mesh.normals, + mesh.tangents, + mesh.colors, + mesh.indices, + mesh.animVertices, + mesh.animNormals, + mesh.boneIds, + mesh.boneWeights, + mesh.vaoId, + mesh.vboId, + material.shader.id, + material.shader.locs, + material.maps, + material.params, + transform.m0, + transform.m4, + transform.m8, + transform.m12, + transform.m1, + transform.m5, + transform.m9, + transform.m13, + transform.m2, + transform.m6, + transform.m10, + transform.m14, + transform.m3, + transform.m7, + transform.m11, + transform.m15 + ) +} +raylib.DrawMesh = DrawMesh + +/** + * Draw multiple mesh instances with material and different transforms + * + * @param {Mesh} mesh + * @param {Material} material + * @param {number} transforms + * @param {number} instances + * + * @return {undefined} + */ +function DrawMeshInstanced (mesh, material, transforms, instances) { + return r.BindDrawMeshInstanced( + mesh.vertexCount, + mesh.triangleCount, + mesh.vertices, + mesh.texcoords, + mesh.texcoords2, + mesh.normals, + mesh.tangents, + mesh.colors, + mesh.indices, + mesh.animVertices, + mesh.animNormals, + mesh.boneIds, + mesh.boneWeights, + mesh.vaoId, + mesh.vboId, + material.shader.id, + material.shader.locs, + material.maps, + material.params, + transforms, + instances + ) +} +raylib.DrawMeshInstanced = DrawMeshInstanced + /** * Export mesh data to file, returns true on success * @@ -7291,6 +7378,66 @@ function GenMeshCubicmap (cubicmap, cubeSize) { } raylib.GenMeshCubicmap = GenMeshCubicmap +/** + * Load materials from model file + * + * @param {string} fileName + * @param {number} materialCount + * + * @return {number} The resulting Material *. + */ +function LoadMaterials (fileName, materialCount) { + return r.BindLoadMaterials( + fileName, + materialCount + ) +} +raylib.LoadMaterials = LoadMaterials + +/** + * Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) + * + * @return {Material} The resulting Material. + */ +function LoadMaterialDefault () { + return r.BindLoadMaterialDefault() +} +raylib.LoadMaterialDefault = LoadMaterialDefault + +/** + * Check if a material is ready + * + * @param {Material} material + * + * @return {boolean} The resulting bool. + */ +function IsMaterialReady (material) { + return r.BindIsMaterialReady( + material.shader.id, + material.shader.locs, + material.maps, + material.params + ) +} +raylib.IsMaterialReady = IsMaterialReady + +/** + * Unload material from GPU memory (VRAM) + * + * @param {Material} material + * + * @return {undefined} + */ +function UnloadMaterial (material) { + return r.BindUnloadMaterial( + material.shader.id, + material.shader.locs, + material.maps, + material.params + ) +} +raylib.UnloadMaterial = UnloadMaterial + /** * Load model animations from file * @@ -8096,7 +8243,7 @@ raylib.WaveCopy = WaveCopy * * @param {Wave} wave * - * @return {number} The resulting float *. + * @return {Float32Array} The resulting float *. */ function LoadWaveSamples (wave) { return r.BindLoadWaveSamples( @@ -8112,7 +8259,7 @@ raylib.LoadWaveSamples = LoadWaveSamples /** * Unload samples data loaded with LoadWaveSamples() * - * @param {number} samples + * @param {Float32Array} samples * * @return {undefined} */ @@ -10797,7 +10944,7 @@ raylib.GuiPanel = GuiPanel * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} active + * @param {Int32Array} active * * @return {number} The resulting int. */ @@ -10986,7 +11133,7 @@ raylib.GuiComboBox = GuiComboBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} active + * @param {Int32Array} active * @param {boolean} editMode * * @return {boolean} The resulting bool. @@ -11009,7 +11156,7 @@ raylib.GuiDropdownBox = GuiDropdownBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11036,7 +11183,7 @@ raylib.GuiSpinner = GuiSpinner * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11251,7 +11398,7 @@ raylib.GuiGrid = GuiGrid * * @param {Rectangle} bounds * @param {string} text - * @param {number} scrollIndex + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11275,8 +11422,8 @@ raylib.GuiListView = GuiListView * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} focus - * @param {number} scrollIndex + * @param {Int32Array} focus + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11328,7 +11475,7 @@ raylib.GuiMessageBox = GuiMessageBox * @param {string} buttons * @param {string} text * @param {number} textMaxSize - * @param {number} secretViewActive + * @param {Int32Array} secretViewActive * * @return {number} The resulting int. */ @@ -11515,7 +11662,7 @@ raylib.GuiIconText = GuiIconText /** * Get raygui icons data pointer * - * @return {number} The resulting unsigned int *. + * @return {UInt32Array} The resulting unsigned int *. */ function GuiGetIcons () { return r.BindGuiGetIcons() @@ -11669,7 +11816,7 @@ raylib.rlScalef = rlScalef /** * Multiply the current matrix by another matrix * - * @param {number} matf + * @param {Float32Array} matf * * @return {undefined} */ @@ -12595,7 +12742,7 @@ raylib.rlGetShaderIdDefault = rlGetShaderIdDefault /** * Get default shader locations * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function rlGetShaderLocsDefault () { return r.BindrlGetShaderLocsDefault() @@ -12967,9 +13114,9 @@ raylib.rlUpdateTexture = rlUpdateTexture * Get OpenGL internal formats * * @param {number} format - * @param {number} glInternalFormat - * @param {number} glFormat - * @param {number} glType + * @param {UInt32Array} glInternalFormat + * @param {UInt32Array} glFormat + * @param {UInt32Array} glType * * @return {undefined} */ @@ -13018,7 +13165,7 @@ raylib.rlUnloadTexture = rlUnloadTexture * @param {number} width * @param {number} height * @param {number} format - * @param {number} mipmaps + * @param {Int32Array} mipmaps * * @return {undefined} */ @@ -13300,7 +13447,7 @@ raylib.rlSetUniformSampler = rlSetUniformSampler * Set shader currently active (id and locations) * * @param {number} id - * @param {number} locs + * @param {Int32Array} locs * * @return {undefined} */ @@ -14913,6 +15060,36 @@ function GenMeshTangents (mesh) { } raylib.GenMeshTangents = GenMeshTangents +/** + * Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) + * + * @param {Material} material + * @param {number} mapType + * @param {Texture2D} texture + * + * @return {undefined} + */ +function SetMaterialTexture (material, mapType, texture) { + const obj = r.BindSetMaterialTexture( + material.shader.id, + material.shader.locs, + material.maps, + material.params, + mapType, + texture.id, + texture.width, + texture.height, + texture.mipmaps, + texture.format + ) + if (typeof obj !== 'undefined') { + for (const key in obj) { + material[key] = obj[key] + } + } +} +raylib.SetMaterialTexture = SetMaterialTexture + /** * Set material for a mesh * diff --git a/src/generated/node-raylib.cc b/src/generated/node-raylib.cc index d2009b9..88f7bf0 100644 --- a/src/generated/node-raylib.cc +++ b/src/generated/node-raylib.cc @@ -58,12 +58,30 @@ inline int intFromValue(const Napi::CallbackInfo& info, int index) { inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().DoubleValue(); } + uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } -uintptr_t bufferPointerFromValue(const Napi::CallbackInfo& info, int index) { + +uintptr_t Float32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt8ArrayFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t)info[index].As().Data(); } + inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } @@ -253,26 +271,26 @@ inline Mesh MeshFromValue(const Napi::CallbackInfo& info, int index) { return { intFromValue(info, index + 0), intFromValue(info, index + 1), - (float *) pointerFromValue(info, index + 2), - (float *) pointerFromValue(info, index + 3), - (float *) pointerFromValue(info, index + 4), - (float *) pointerFromValue(info, index + 5), - (float *) pointerFromValue(info, index + 6), - (unsigned char *) bufferPointerFromValue(info, index + 7), - (unsigned short *) pointerFromValue(info, index + 8), - (float *) pointerFromValue(info, index + 9), - (float *) pointerFromValue(info, index + 10), - (unsigned char *) bufferPointerFromValue(info, index + 11), - (float *) pointerFromValue(info, index + 12), + (float *) Float32ArrayFromValue(info, index + 2), + (float *) Float32ArrayFromValue(info, index + 3), + (float *) Float32ArrayFromValue(info, index + 4), + (float *) Float32ArrayFromValue(info, index + 5), + (float *) Float32ArrayFromValue(info, index + 6), + (unsigned char *) UInt8ArrayFromValue(info, index + 7), + (unsigned short *) UInt16ArrayFromValue(info, index + 8), + (float *) Float32ArrayFromValue(info, index + 9), + (float *) Float32ArrayFromValue(info, index + 10), + (unsigned char *) UInt8ArrayFromValue(info, index + 11), + (float *) Float32ArrayFromValue(info, index + 12), unsignedintFromValue(info, index + 13), - (unsigned int *) pointerFromValue(info, index + 14) + (unsigned int *) UInt32ArrayFromValue(info, index + 14) }; } inline Shader ShaderFromValue(const Napi::CallbackInfo& info, int index) { return { unsignedintFromValue(info, index + 0), - (int *) pointerFromValue(info, index + 1) + (int *) Int32ArrayFromValue(info, index + 1) }; } @@ -284,6 +302,14 @@ inline MaterialMap MaterialMapFromValue(const Napi::CallbackInfo& info, int inde }; } +inline Material MaterialFromValue(const Napi::CallbackInfo& info, int index) { + return { + ShaderFromValue(info, index + 0), + (MaterialMap *) pointerFromValue(info, index + 2), + pointerFromValue(info, index + 3) + }; +} + inline Transform TransformFromValue(const Napi::CallbackInfo& info, int index) { return { Vector3FromValue(info, index + 0), @@ -306,7 +332,7 @@ inline Model ModelFromValue(const Napi::CallbackInfo& info, int index) { intFromValue(info, index + 17), (Mesh *) pointerFromValue(info, index + 18), (Material *) pointerFromValue(info, index + 19), - (int *) pointerFromValue(info, index + 20), + (int *) Int32ArrayFromValue(info, index + 20), intFromValue(info, index + 21), (BoneInfo *) pointerFromValue(info, index + 22), (Transform *) pointerFromValue(info, index + 23) @@ -588,6 +614,14 @@ inline Napi::Value ToValue(Napi::Env env, MaterialMap obj) { return out; } +inline Napi::Value ToValue(Napi::Env env, Material obj) { + Napi::Object out = Napi::Object::New(env); + out.Set("shader", ToValue(env, obj.shader)); + out.Set("maps", ToValue(env, obj.maps)); + out.Set("params", ToValue(env, obj.params)); + return out; +} + inline Napi::Value ToValue(Napi::Env env, Transform obj) { Napi::Object out = Napi::Object::New(env); out.Set("translation", ToValue(env, obj.translation)); @@ -1141,7 +1175,7 @@ Napi::Value BindSaveFileData(const Napi::CallbackInfo& info) { Napi::Value BindExportDataAsCode(const Napi::CallbackInfo& info) { return ToValue(info.Env(), ExportDataAsCode( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), unsignedintFromValue(info, 1), (const char *) stringFromValue(info, 2) ) @@ -1315,7 +1349,7 @@ Napi::Value BindGetFileModTime(const Napi::CallbackInfo& info) { Napi::Value BindCompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), CompressData( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1325,7 +1359,7 @@ Napi::Value BindCompressData(const Napi::CallbackInfo& info) { Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecompressData( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1335,7 +1369,7 @@ Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), EncodeDataBase64( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1345,7 +1379,7 @@ Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { Napi::Value BindDecodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecodeDataBase64( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), (int *) pointerFromValue(info, 1) ) ); @@ -1795,7 +1829,7 @@ Napi::Value BindLoadImageFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadImageFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) bufferPointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2213,7 +2247,7 @@ Napi::Value BindLoadFontEx(const Napi::CallbackInfo& info) { LoadFontEx( (const char *) stringFromValue(info, 0), intFromValue(info, 1), - (int *) pointerFromValue(info, 2), + (int *) Int32ArrayFromValue(info, 2), intFromValue(info, 3) ) ); @@ -2233,10 +2267,10 @@ Napi::Value BindLoadFontFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) bufferPointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2), intFromValue(info, 3), - (int *) pointerFromValue(info, 4), + (int *) Int32ArrayFromValue(info, 4), intFromValue(info, 5) ) ); @@ -2253,10 +2287,10 @@ Napi::Value BindIsFontReady(const Napi::CallbackInfo& info) { Napi::Value BindLoadFontData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontData( - (const unsigned char *) bufferPointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), intFromValue(info, 2), - (int *) pointerFromValue(info, 3), + (int *) Int32ArrayFromValue(info, 3), intFromValue(info, 4), intFromValue(info, 5) ) @@ -2335,7 +2369,7 @@ Napi::Value BindGetGlyphAtlasRec(const Napi::CallbackInfo& info) { Napi::Value BindLoadUTF8(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadUTF8( - (const int *) pointerFromValue(info, 0), + (const int *) Int32ArrayFromValue(info, 0), intFromValue(info, 1) ) ); @@ -2389,7 +2423,7 @@ Napi::Value BindCodepointToUTF8(const Napi::CallbackInfo& info) { return ToValue(info.Env(), CodepointToUTF8( intFromValue(info, 0), - (int *) pointerFromValue(info, 1) + (int *) Int32ArrayFromValue(info, 1) ) ); } @@ -2670,6 +2704,31 @@ Napi::Value BindGenMeshCubicmap(const Napi::CallbackInfo& info) { ); } +Napi::Value BindLoadMaterials(const Napi::CallbackInfo& info) { + return ToValue(info.Env(), + LoadMaterials( + (const char *) stringFromValue(info, 0), + (int *) pointerFromValue(info, 1) + ) + ); +} + +Napi::Value BindLoadMaterialDefault(const Napi::CallbackInfo& info) { + return ToValue(info.Env(), + LoadMaterialDefault( + + ) + ); +} + +Napi::Value BindIsMaterialReady(const Napi::CallbackInfo& info) { + return ToValue(info.Env(), + IsMaterialReady( + MaterialFromValue(info, 0) + ) + ); +} + Napi::Value BindLoadModelAnimations(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadModelAnimations( @@ -2790,7 +2849,7 @@ Napi::Value BindLoadWaveFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadWaveFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) bufferPointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2882,7 +2941,7 @@ Napi::Value BindLoadMusicStreamFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadMusicStreamFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) bufferPointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -4286,7 +4345,7 @@ Napi::Value BindGuiTabBar(const Napi::CallbackInfo& info) { RectangleFromValue(info, 0), (const char **) pointerFromValue(info, 4), intFromValue(info, 5), - (int *) pointerFromValue(info, 6) + (int *) Int32ArrayFromValue(info, 6) ) ); } @@ -4365,7 +4424,7 @@ Napi::Value BindGuiDropdownBox(const Napi::CallbackInfo& info) { GuiDropdownBox( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), boolFromValue(info, 6) ) ); @@ -4376,7 +4435,7 @@ Napi::Value BindGuiSpinner(const Napi::CallbackInfo& info) { GuiSpinner( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6), intFromValue(info, 7), boolFromValue(info, 8) @@ -4389,7 +4448,7 @@ Napi::Value BindGuiValueBox(const Napi::CallbackInfo& info) { GuiValueBox( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6), intFromValue(info, 7), boolFromValue(info, 8) @@ -4474,7 +4533,7 @@ Napi::Value BindGuiListView(const Napi::CallbackInfo& info) { GuiListView( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6) ) ); @@ -4486,8 +4545,8 @@ Napi::Value BindGuiListViewEx(const Napi::CallbackInfo& info) { RectangleFromValue(info, 0), (const char **) pointerFromValue(info, 4), intFromValue(info, 5), - (int *) pointerFromValue(info, 6), - (int *) pointerFromValue(info, 7), + (int *) Int32ArrayFromValue(info, 6), + (int *) Int32ArrayFromValue(info, 7), intFromValue(info, 8) ) ); @@ -4513,7 +4572,7 @@ Napi::Value BindGuiTextInputBox(const Napi::CallbackInfo& info) { (const char *) stringFromValue(info, 6), (char *) pointerFromValue(info, 7), intFromValue(info, 8), - (int *) pointerFromValue(info, 9) + (int *) Int32ArrayFromValue(info, 9) ) ); } @@ -5216,7 +5275,7 @@ void BindOpenURL(const Napi::CallbackInfo& info) { void BindUnloadFileData(const Napi::CallbackInfo& info) { UnloadFileData( - (unsigned char *) bufferPointerFromValue(info, 0) + (unsigned char *) UInt8ArrayFromValue(info, 0) ); } @@ -5861,7 +5920,7 @@ void BindDrawTextCodepoint(const Napi::CallbackInfo& info) { void BindDrawTextCodepoints(const Napi::CallbackInfo& info) { DrawTextCodepoints( FontFromValue(info, 0), - (const int *) pointerFromValue(info, 10), + (const int *) Int32ArrayFromValue(info, 10), intFromValue(info, 11), Vector2FromValue(info, 12), floatFromValue(info, 14), @@ -5878,7 +5937,7 @@ void BindUnloadUTF8(const Napi::CallbackInfo& info) { void BindUnloadCodepoints(const Napi::CallbackInfo& info) { UnloadCodepoints( - (int *) pointerFromValue(info, 0) + (int *) Int32ArrayFromValue(info, 0) ); } @@ -6188,6 +6247,29 @@ void BindUnloadMesh(const Napi::CallbackInfo& info) { ); } +void BindDrawMesh(const Napi::CallbackInfo& info) { + DrawMesh( + MeshFromValue(info, 0), + MaterialFromValue(info, 15), + MatrixFromValue(info, 19) + ); +} + +void BindDrawMeshInstanced(const Napi::CallbackInfo& info) { + DrawMeshInstanced( + MeshFromValue(info, 0), + MaterialFromValue(info, 15), + (const Matrix *) pointerFromValue(info, 19), + intFromValue(info, 20) + ); +} + +void BindUnloadMaterial(const Napi::CallbackInfo& info) { + UnloadMaterial( + MaterialFromValue(info, 0) + ); +} + void BindUpdateModelAnimation(const Napi::CallbackInfo& info) { UpdateModelAnimation( ModelFromValue(info, 0), @@ -6294,7 +6376,7 @@ void BindSetSoundPan(const Napi::CallbackInfo& info) { void BindUnloadWaveSamples(const Napi::CallbackInfo& info) { UnloadWaveSamples( - (float *) pointerFromValue(info, 0) + (float *) Float32ArrayFromValue(info, 0) ); } @@ -6438,7 +6520,7 @@ void BindQuaternionToAxisAngle(const Napi::CallbackInfo& info) { QuaternionToAxisAngle( Vector4FromValue(info, 0), (Vector3 *) pointerFromValue(info, 1), - (float *) pointerFromValue(info, 2) + (float *) Float32ArrayFromValue(info, 2) ); } @@ -6631,7 +6713,7 @@ void BindrlScalef(const Napi::CallbackInfo& info) { void BindrlMultMatrixf(const Napi::CallbackInfo& info) { rlMultMatrixf( - (const float *) pointerFromValue(info, 0) + (const float *) Float32ArrayFromValue(info, 0) ); } @@ -7187,9 +7269,9 @@ void BindrlUpdateTexture(const Napi::CallbackInfo& info) { void BindrlGetGlTextureFormats(const Napi::CallbackInfo& info) { rlGetGlTextureFormats( intFromValue(info, 0), - (unsigned int *) pointerFromValue(info, 1), - (unsigned int *) pointerFromValue(info, 2), - (unsigned int *) pointerFromValue(info, 3) + (unsigned int *) UInt32ArrayFromValue(info, 1), + (unsigned int *) UInt32ArrayFromValue(info, 2), + (unsigned int *) UInt32ArrayFromValue(info, 3) ); } @@ -7205,7 +7287,7 @@ void BindrlGenTextureMipmaps(const Napi::CallbackInfo& info) { intFromValue(info, 1), intFromValue(info, 2), intFromValue(info, 3), - (int *) pointerFromValue(info, 4) + (int *) Int32ArrayFromValue(info, 4) ); } @@ -7257,7 +7339,7 @@ void BindrlSetUniformSampler(const Napi::CallbackInfo& info) { void BindrlSetShader(const Napi::CallbackInfo& info) { rlSetShader( unsignedintFromValue(info, 0), - (int *) pointerFromValue(info, 1) + (int *) Int32ArrayFromValue(info, 1) ); } @@ -7734,6 +7816,15 @@ Napi::Value BindGenMeshTangents(const Napi::CallbackInfo& info) { return ToValue(info.Env(), obj); } +Napi::Value BindSetMaterialTexture(const Napi::CallbackInfo& info) { + Material obj = MaterialFromValue(info, 0); + SetMaterialTexture( + &obj, intFromValue(info, 4), + TextureFromValue(info, 5) + ); + return ToValue(info.Env(), obj); +} + Napi::Value BindSetModelMeshMaterial(const Napi::CallbackInfo& info) { Model obj = ModelFromValue(info, 0); SetModelMeshMaterial( @@ -8228,6 +8319,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set("BindUploadMesh", Napi::Function::New(env, BindUploadMesh)); exports.Set("BindUpdateMeshBuffer", Napi::Function::New(env, BindUpdateMeshBuffer)); exports.Set("BindUnloadMesh", Napi::Function::New(env, BindUnloadMesh)); + exports.Set("BindDrawMesh", Napi::Function::New(env, BindDrawMesh)); + exports.Set("BindDrawMeshInstanced", Napi::Function::New(env, BindDrawMeshInstanced)); exports.Set("BindExportMesh", Napi::Function::New(env, BindExportMesh)); exports.Set("BindGetMeshBoundingBox", Napi::Function::New(env, BindGetMeshBoundingBox)); exports.Set("BindGenMeshTangents", Napi::Function::New(env, BindGenMeshTangents)); @@ -8242,6 +8335,11 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set("BindGenMeshKnot", Napi::Function::New(env, BindGenMeshKnot)); exports.Set("BindGenMeshHeightmap", Napi::Function::New(env, BindGenMeshHeightmap)); exports.Set("BindGenMeshCubicmap", Napi::Function::New(env, BindGenMeshCubicmap)); + exports.Set("BindLoadMaterials", Napi::Function::New(env, BindLoadMaterials)); + exports.Set("BindLoadMaterialDefault", Napi::Function::New(env, BindLoadMaterialDefault)); + exports.Set("BindIsMaterialReady", Napi::Function::New(env, BindIsMaterialReady)); + exports.Set("BindUnloadMaterial", Napi::Function::New(env, BindUnloadMaterial)); + exports.Set("BindSetMaterialTexture", Napi::Function::New(env, BindSetMaterialTexture)); exports.Set("BindSetModelMeshMaterial", Napi::Function::New(env, BindSetModelMeshMaterial)); exports.Set("BindLoadModelAnimations", Napi::Function::New(env, BindLoadModelAnimations)); exports.Set("BindUpdateModelAnimation", Napi::Function::New(env, BindUpdateModelAnimation)); diff --git a/src/generated/node-raylib.d.ts b/src/generated/node-raylib.d.ts index 8d42b3f..9b48a58 100644 --- a/src/generated/node-raylib.d.ts +++ b/src/generated/node-raylib.d.ts @@ -193,38 +193,38 @@ declare module "raylib" { /** Number of triangles stored (indexed or not). (int) */ triangleCount: number /** Vertex position (XYZ - 3 components per vertex) (shader-location = 0). (float *) */ - vertices: number + vertices: Float32Array /** Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1). (float *) */ - texcoords: number + texcoords: Float32Array /** Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5). (float *) */ - texcoords2: number + texcoords2: Float32Array /** Vertex normals (XYZ - 3 components per vertex) (shader-location = 2). (float *) */ - normals: number + normals: Float32Array /** Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4). (float *) */ - tangents: number + tangents: Float32Array /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ colors: UInt8Array /** Vertex indices (in case vertex data comes indexed). (unsigned short *) */ - indices: number + indices: UInt16Array /** Animated vertex positions (after bones transformations). (float *) */ - animVertices: number + animVertices: Float32Array /** Animated normals (after bones transformations). (float *) */ - animNormals: number + animNormals: Float32Array /** Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning). (unsigned char *) */ boneIds: UInt8Array /** Vertex bone weight, up to 4 bones influence by vertex (skinning). (float *) */ - boneWeights: number + boneWeights: Float32Array /** OpenGL Vertex Array Object id. (unsigned int) */ vaoId: number /** OpenGL Vertex Buffer Objects id (default vertex data). (unsigned int *) */ - vboId: number + vboId: UInt32Array } /** Shader */ export interface Shader { /** Shader program id. (unsigned int) */ id: number /** Shader locations array (RL_MAX_SHADER_LOCATIONS). (int *) */ - locs: number + locs: Int32Array } /** MaterialMap */ export interface MaterialMap { @@ -273,7 +273,7 @@ declare module "raylib" { /** Materials array. (Material *) */ materials: number /** Mesh material number. (int *) */ - meshMaterial: number + meshMaterial: Int32Array /** Number of bones. (int) */ boneCount: number /** Bones information (skeleton). (BoneInfo *) */ @@ -419,13 +419,13 @@ declare module "raylib" { /** Number of elements in the buffer (QUADS). (int) */ elementCount: number /** Vertex position (XYZ - 3 components per vertex) (shader-location = 0). (float *) */ - vertices: number + vertices: Float32Array /** Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1). (float *) */ - texcoords: number + texcoords: Float32Array /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ colors: UInt8Array /** Vertex indices (in case vertex data comes indexed) (6 indices per quad). (unsigned int *) */ - indices: number + indices: UInt32Array /** OpenGL Vertex Array Object id. (unsigned int) */ vaoId: number /** OpenGL Vertex Buffer Objects id (4 types of vertex data). (unsigned int[4]) */ @@ -1454,19 +1454,19 @@ declare module "raylib" { export function LoadFont(fileName: string): Font /** Load font from file with extended parameters, use NULL for fontChars and 0 for glyphCount to load the default character set */ - export function LoadFontEx(fileName: string, fontSize: number, fontChars: number, glyphCount: number): Font + export function LoadFontEx(fileName: string, fontSize: number, fontChars: Int32Array, glyphCount: number): Font /** Load font from Image (XNA style) */ export function LoadFontFromImage(image: Image, key: Color, firstChar: number): Font /** Load font from memory buffer, fileType refers to extension: i.e. '.ttf' */ - export function LoadFontFromMemory(fileType: string, fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: number, glyphCount: number): Font + export function LoadFontFromMemory(fileType: string, fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: Int32Array, glyphCount: number): Font /** Check if a font is ready */ export function IsFontReady(font: Font): boolean /** Load font data for further use */ - export function LoadFontData(fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: number, glyphCount: number, type: number): number + export function LoadFontData(fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: Int32Array, glyphCount: number, type: number): number /** Generate image font atlas using chars info */ export function GenImageFontAtlas(chars: number, recs: number, glyphCount: number, fontSize: number, padding: number, packMethod: number): Image @@ -1496,7 +1496,7 @@ declare module "raylib" { export function DrawTextCodepoint(font: Font, codepoint: number, position: Vector2, fontSize: number, tint: Color): void /** Draw multiple character (codepoint) */ - export function DrawTextCodepoints(font: Font, codepoints: number, count: number, position: Vector2, fontSize: number, spacing: number, tint: Color): void + export function DrawTextCodepoints(font: Font, codepoints: Int32Array, count: number, position: Vector2, fontSize: number, spacing: number, tint: Color): void /** Measure string width for default font */ export function MeasureText(text: string, fontSize: number): number @@ -1514,16 +1514,16 @@ declare module "raylib" { export function GetGlyphAtlasRec(font: Font, codepoint: number): Rectangle /** Load UTF-8 text encoded from codepoints array */ - export function LoadUTF8(codepoints: number, length: number): string + export function LoadUTF8(codepoints: Int32Array, length: number): string /** Unload UTF-8 text encoded from codepoints array */ export function UnloadUTF8(text: string): void /** Load all codepoints from a UTF-8 text string, codepoints count returned by parameter */ - export function LoadCodepoints(text: string, count: number): number + export function LoadCodepoints(text: string, count: number): Int32Array /** Unload codepoints data from memory */ - export function UnloadCodepoints(codepoints: number): void + export function UnloadCodepoints(codepoints: Int32Array): void /** Get total number of codepoints in a UTF-8 encoded string */ export function GetCodepointCount(text: string): number @@ -1538,7 +1538,7 @@ declare module "raylib" { export function GetCodepointPrevious(text: string, codepointSize: number): number /** Encode one codepoint into UTF-8 byte array (array length returned as parameter) */ - export function CodepointToUTF8(codepoint: number, utf8Size: number): string + export function CodepointToUTF8(codepoint: number, utf8Size: Int32Array): string /** Copy one string to another, returns bytes copied */ export function TextCopy(dst: string, src: string): number @@ -1693,6 +1693,12 @@ declare module "raylib" { /** Unload mesh data from CPU and GPU */ export function UnloadMesh(mesh: Mesh): void + /** Draw a 3d mesh with material and transform */ + export function DrawMesh(mesh: Mesh, material: Material, transform: Matrix): void + + /** Draw multiple mesh instances with material and different transforms */ + export function DrawMeshInstanced(mesh: Mesh, material: Material, transforms: number, instances: number): void + /** Export mesh data to file, returns true on success */ export function ExportMesh(mesh: Mesh, fileName: string): boolean @@ -1735,6 +1741,21 @@ declare module "raylib" { /** Generate cubes-based map mesh from image data */ export function GenMeshCubicmap(cubicmap: Image, cubeSize: Vector3): Mesh + /** Load materials from model file */ + export function LoadMaterials(fileName: string, materialCount: number): number + + /** Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) */ + export function LoadMaterialDefault(): Material + + /** Check if a material is ready */ + export function IsMaterialReady(material: Material): boolean + + /** Unload material from GPU memory (VRAM) */ + export function UnloadMaterial(material: Material): void + + /** Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) */ + export function SetMaterialTexture(material: Material, mapType: number, texture: Texture): void + /** Set material for a mesh */ export function SetModelMeshMaterial(model: Model, meshId: number, materialId: number): void @@ -1856,10 +1877,10 @@ declare module "raylib" { export function WaveFormat(wave: Wave, sampleRate: number, sampleSize: number, channels: number): void /** Load samples data from wave as a 32bit float data array */ - export function LoadWaveSamples(wave: Wave): number + export function LoadWaveSamples(wave: Wave): Float32Array /** Unload samples data loaded with LoadWaveSamples() */ - export function UnloadWaveSamples(samples: number): void + export function UnloadWaveSamples(samples: Float32Array): void /** Load music stream from file */ export function LoadMusicStream(fileName: string): Music @@ -2351,7 +2372,7 @@ declare module "raylib" { export function QuaternionFromAxisAngle(axis: Vector3, angle: number): Quaternion /** */ - export function QuaternionToAxisAngle(q: Quaternion, outAxis: number, outAngle: number): void + export function QuaternionToAxisAngle(q: Quaternion, outAxis: number, outAngle: Float32Array): void /** */ export function QuaternionFromEuler(pitch: number, yaw: number, roll: number): Quaternion @@ -2414,7 +2435,7 @@ declare module "raylib" { export function GuiPanel(bounds: Rectangle, text: string): void /** Tab Bar control, returns TAB to be closed or -1 */ - export function GuiTabBar(bounds: Rectangle, text: number, count: number, active: number): number + export function GuiTabBar(bounds: Rectangle, text: number, count: number, active: Int32Array): number /** Scroll Panel control */ export function GuiScrollPanel(bounds: Rectangle, text: string, content: Rectangle, scroll: number): Rectangle @@ -2441,13 +2462,13 @@ declare module "raylib" { export function GuiComboBox(bounds: Rectangle, text: string, active: number): number /** Dropdown Box control, returns selected item */ - export function GuiDropdownBox(bounds: Rectangle, text: string, active: number, editMode: boolean): boolean + export function GuiDropdownBox(bounds: Rectangle, text: string, active: Int32Array, editMode: boolean): boolean /** Spinner control, returns selected value */ - export function GuiSpinner(bounds: Rectangle, text: string, value: number, minValue: number, maxValue: number, editMode: boolean): boolean + export function GuiSpinner(bounds: Rectangle, text: string, value: Int32Array, minValue: number, maxValue: number, editMode: boolean): boolean /** Value Box control, updates input text with numbers */ - export function GuiValueBox(bounds: Rectangle, text: string, value: number, minValue: number, maxValue: number, editMode: boolean): boolean + export function GuiValueBox(bounds: Rectangle, text: string, value: Int32Array, minValue: number, maxValue: number, editMode: boolean): boolean /** Text Box control, updates input text */ export function GuiTextBox(bounds: Rectangle, text: string, textSize: number, editMode: boolean): boolean @@ -2474,16 +2495,16 @@ declare module "raylib" { export function GuiGrid(bounds: Rectangle, text: string, spacing: number, subdivs: number): Vector2 /** List View control, returns selected list item index */ - export function GuiListView(bounds: Rectangle, text: string, scrollIndex: number, active: number): number + export function GuiListView(bounds: Rectangle, text: string, scrollIndex: Int32Array, active: number): number /** List View with extended parameters */ - export function GuiListViewEx(bounds: Rectangle, text: number, count: number, focus: number, scrollIndex: number, active: number): number + export function GuiListViewEx(bounds: Rectangle, text: number, count: number, focus: Int32Array, scrollIndex: Int32Array, active: number): number /** Message Box control, displays a message */ export function GuiMessageBox(bounds: Rectangle, title: string, message: string, buttons: string): number /** Text Input Box control, ask for text, supports secret */ - export function GuiTextInputBox(bounds: Rectangle, title: string, message: string, buttons: string, text: string, textMaxSize: number, secretViewActive: number): number + export function GuiTextInputBox(bounds: Rectangle, title: string, message: string, buttons: string, text: string, textMaxSize: number, secretViewActive: Int32Array): number /** Color Picker control (multiple color controls) */ export function GuiColorPicker(bounds: Rectangle, text: string, color: Color): Color @@ -2516,7 +2537,7 @@ declare module "raylib" { export function GuiIconText(iconId: number, text: string): string /** Get raygui icons data pointer */ - export function GuiGetIcons(): number + export function GuiGetIcons(): UInt32Array /** Load raygui icons file (.rgi) into internal icons data */ export function GuiLoadIcons(fileName: string, loadIconsName: boolean): number @@ -2549,7 +2570,7 @@ declare module "raylib" { export function rlScalef(x: number, y: number, z: number): void /** Multiply the current matrix by another matrix */ - export function rlMultMatrixf(matf: number): void + export function rlMultMatrixf(matf: Float32Array): void /** */ export function rlFrustum(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): void @@ -2762,7 +2783,7 @@ declare module "raylib" { export function rlGetShaderIdDefault(): number /** Get default shader locations */ - export function rlGetShaderLocsDefault(): number + export function rlGetShaderLocsDefault(): Int32Array /** Load a render batch system */ export function rlLoadRenderBatch(numBuffers: number, bufferElements: number): rlRenderBatch @@ -2840,7 +2861,7 @@ declare module "raylib" { export function rlUpdateTexture(id: number, offsetX: number, offsetY: number, width: number, height: number, format: number, data: number): void /** Get OpenGL internal formats */ - export function rlGetGlTextureFormats(format: number, glInternalFormat: number, glFormat: number, glType: number): void + export function rlGetGlTextureFormats(format: number, glInternalFormat: UInt32Array, glFormat: UInt32Array, glType: UInt32Array): void /** Get name string for pixel format */ export function rlGetPixelFormatName(format: number): string @@ -2849,7 +2870,7 @@ declare module "raylib" { export function rlUnloadTexture(id: number): void /** Generate mipmap data for selected texture */ - export function rlGenTextureMipmaps(id: number, width: number, height: number, format: number, mipmaps: number): void + export function rlGenTextureMipmaps(id: number, width: number, height: number, format: number, mipmaps: Int32Array): void /** Read texture pixel data */ export function rlReadTexturePixels(id: number, width: number, height: number, format: number): number @@ -2897,7 +2918,7 @@ declare module "raylib" { export function rlSetUniformSampler(locIndex: number, textureId: number): void /** Set shader currently active (id and locations) */ - export function rlSetShader(id: number, locs: number): void + export function rlSetShader(id: number, locs: Int32Array): void /** Load compute shader program */ export function rlLoadComputeShaderProgram(shaderId: number): number diff --git a/src/generated/node-raylib.js b/src/generated/node-raylib.js index f2dbe95..f602c18 100644 --- a/src/generated/node-raylib.js +++ b/src/generated/node-raylib.js @@ -5001,7 +5001,7 @@ raylib.LoadFont = LoadFont * * @param {string} fileName * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5048,7 +5048,7 @@ raylib.LoadFontFromImage = LoadFontFromImage * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5094,7 +5094,7 @@ raylib.IsFontReady = IsFontReady * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * @param {number} type * @@ -5359,7 +5359,7 @@ raylib.DrawTextCodepoint = DrawTextCodepoint * Draw multiple character (codepoint) * * @param {Font} font - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} count * @param {Vector2} position * @param {number} fontSize @@ -5517,7 +5517,7 @@ raylib.GetGlyphAtlasRec = GetGlyphAtlasRec /** * Load UTF-8 text encoded from codepoints array * - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} length * * @return {string} The resulting char *. @@ -5550,7 +5550,7 @@ raylib.UnloadUTF8 = UnloadUTF8 * @param {string} text * @param {number} count * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function LoadCodepoints (text, count) { return r.BindLoadCodepoints( @@ -5563,7 +5563,7 @@ raylib.LoadCodepoints = LoadCodepoints /** * Unload codepoints data from memory * - * @param {number} codepoints + * @param {Int32Array} codepoints * * @return {undefined} */ @@ -5640,7 +5640,7 @@ raylib.GetCodepointPrevious = GetCodepointPrevious * Encode one codepoint into UTF-8 byte array (array length returned as parameter) * * @param {number} codepoint - * @param {number} utf8Size + * @param {Int32Array} utf8Size * * @return {string} The resulting const char *. */ @@ -7023,6 +7023,93 @@ function UnloadMesh (mesh) { } raylib.UnloadMesh = UnloadMesh +/** + * Draw a 3d mesh with material and transform + * + * @param {Mesh} mesh + * @param {Material} material + * @param {Matrix} transform + * + * @return {undefined} + */ +function DrawMesh (mesh, material, transform) { + return r.BindDrawMesh( + mesh.vertexCount, + mesh.triangleCount, + mesh.vertices, + mesh.texcoords, + mesh.texcoords2, + mesh.normals, + mesh.tangents, + mesh.colors, + mesh.indices, + mesh.animVertices, + mesh.animNormals, + mesh.boneIds, + mesh.boneWeights, + mesh.vaoId, + mesh.vboId, + material.shader.id, + material.shader.locs, + material.maps, + material.params, + transform.m0, + transform.m4, + transform.m8, + transform.m12, + transform.m1, + transform.m5, + transform.m9, + transform.m13, + transform.m2, + transform.m6, + transform.m10, + transform.m14, + transform.m3, + transform.m7, + transform.m11, + transform.m15 + ) +} +raylib.DrawMesh = DrawMesh + +/** + * Draw multiple mesh instances with material and different transforms + * + * @param {Mesh} mesh + * @param {Material} material + * @param {number} transforms + * @param {number} instances + * + * @return {undefined} + */ +function DrawMeshInstanced (mesh, material, transforms, instances) { + return r.BindDrawMeshInstanced( + mesh.vertexCount, + mesh.triangleCount, + mesh.vertices, + mesh.texcoords, + mesh.texcoords2, + mesh.normals, + mesh.tangents, + mesh.colors, + mesh.indices, + mesh.animVertices, + mesh.animNormals, + mesh.boneIds, + mesh.boneWeights, + mesh.vaoId, + mesh.vboId, + material.shader.id, + material.shader.locs, + material.maps, + material.params, + transforms, + instances + ) +} +raylib.DrawMeshInstanced = DrawMeshInstanced + /** * Export mesh data to file, returns true on success * @@ -7291,6 +7378,66 @@ function GenMeshCubicmap (cubicmap, cubeSize) { } raylib.GenMeshCubicmap = GenMeshCubicmap +/** + * Load materials from model file + * + * @param {string} fileName + * @param {number} materialCount + * + * @return {number} The resulting Material *. + */ +function LoadMaterials (fileName, materialCount) { + return r.BindLoadMaterials( + fileName, + materialCount + ) +} +raylib.LoadMaterials = LoadMaterials + +/** + * Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) + * + * @return {Material} The resulting Material. + */ +function LoadMaterialDefault () { + return r.BindLoadMaterialDefault() +} +raylib.LoadMaterialDefault = LoadMaterialDefault + +/** + * Check if a material is ready + * + * @param {Material} material + * + * @return {boolean} The resulting bool. + */ +function IsMaterialReady (material) { + return r.BindIsMaterialReady( + material.shader.id, + material.shader.locs, + material.maps, + material.params + ) +} +raylib.IsMaterialReady = IsMaterialReady + +/** + * Unload material from GPU memory (VRAM) + * + * @param {Material} material + * + * @return {undefined} + */ +function UnloadMaterial (material) { + return r.BindUnloadMaterial( + material.shader.id, + material.shader.locs, + material.maps, + material.params + ) +} +raylib.UnloadMaterial = UnloadMaterial + /** * Load model animations from file * @@ -8096,7 +8243,7 @@ raylib.WaveCopy = WaveCopy * * @param {Wave} wave * - * @return {number} The resulting float *. + * @return {Float32Array} The resulting float *. */ function LoadWaveSamples (wave) { return r.BindLoadWaveSamples( @@ -8112,7 +8259,7 @@ raylib.LoadWaveSamples = LoadWaveSamples /** * Unload samples data loaded with LoadWaveSamples() * - * @param {number} samples + * @param {Float32Array} samples * * @return {undefined} */ @@ -10797,7 +10944,7 @@ raylib.GuiPanel = GuiPanel * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} active + * @param {Int32Array} active * * @return {number} The resulting int. */ @@ -10986,7 +11133,7 @@ raylib.GuiComboBox = GuiComboBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} active + * @param {Int32Array} active * @param {boolean} editMode * * @return {boolean} The resulting bool. @@ -11009,7 +11156,7 @@ raylib.GuiDropdownBox = GuiDropdownBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11036,7 +11183,7 @@ raylib.GuiSpinner = GuiSpinner * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11251,7 +11398,7 @@ raylib.GuiGrid = GuiGrid * * @param {Rectangle} bounds * @param {string} text - * @param {number} scrollIndex + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11275,8 +11422,8 @@ raylib.GuiListView = GuiListView * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} focus - * @param {number} scrollIndex + * @param {Int32Array} focus + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11328,7 +11475,7 @@ raylib.GuiMessageBox = GuiMessageBox * @param {string} buttons * @param {string} text * @param {number} textMaxSize - * @param {number} secretViewActive + * @param {Int32Array} secretViewActive * * @return {number} The resulting int. */ @@ -11515,7 +11662,7 @@ raylib.GuiIconText = GuiIconText /** * Get raygui icons data pointer * - * @return {number} The resulting unsigned int *. + * @return {UInt32Array} The resulting unsigned int *. */ function GuiGetIcons () { return r.BindGuiGetIcons() @@ -11669,7 +11816,7 @@ raylib.rlScalef = rlScalef /** * Multiply the current matrix by another matrix * - * @param {number} matf + * @param {Float32Array} matf * * @return {undefined} */ @@ -12595,7 +12742,7 @@ raylib.rlGetShaderIdDefault = rlGetShaderIdDefault /** * Get default shader locations * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function rlGetShaderLocsDefault () { return r.BindrlGetShaderLocsDefault() @@ -12967,9 +13114,9 @@ raylib.rlUpdateTexture = rlUpdateTexture * Get OpenGL internal formats * * @param {number} format - * @param {number} glInternalFormat - * @param {number} glFormat - * @param {number} glType + * @param {UInt32Array} glInternalFormat + * @param {UInt32Array} glFormat + * @param {UInt32Array} glType * * @return {undefined} */ @@ -13018,7 +13165,7 @@ raylib.rlUnloadTexture = rlUnloadTexture * @param {number} width * @param {number} height * @param {number} format - * @param {number} mipmaps + * @param {Int32Array} mipmaps * * @return {undefined} */ @@ -13300,7 +13447,7 @@ raylib.rlSetUniformSampler = rlSetUniformSampler * Set shader currently active (id and locations) * * @param {number} id - * @param {number} locs + * @param {Int32Array} locs * * @return {undefined} */ @@ -14913,6 +15060,36 @@ function GenMeshTangents (mesh) { } raylib.GenMeshTangents = GenMeshTangents +/** + * Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) + * + * @param {Material} material + * @param {number} mapType + * @param {Texture} texture + * + * @return {undefined} + */ +function SetMaterialTexture (material, mapType, texture) { + const obj = r.BindSetMaterialTexture( + material.shader.id, + material.shader.locs, + material.maps, + material.params, + mapType, + texture.id, + texture.width, + texture.height, + texture.mipmaps, + texture.format + ) + if (typeof obj !== 'undefined') { + for (const key in obj) { + material[key] = obj[key] + } + } +} +raylib.SetMaterialTexture = SetMaterialTexture + /** * Set material for a mesh * diff --git a/tools/generate.js b/tools/generate.js index a27a691..6239922 100644 --- a/tools/generate.js +++ b/tools/generate.js @@ -34,7 +34,7 @@ const blocklist = [ // @todo Verify Structs that have array properties 'VrStereoConfig', // Matrix[2], float[2] 'VrDeviceInfo', // float[4] - 'Material', // float[4] + // 'Material', // float[4] // raymath // @todo Fix helper structs for float arrays diff --git a/tools/generate_templates/ArgumentTypeConversion.js b/tools/generate_templates/ArgumentTypeConversion.js index 357896b..db973fa 100644 --- a/tools/generate_templates/ArgumentTypeConversion.js +++ b/tools/generate_templates/ArgumentTypeConversion.js @@ -1,6 +1,47 @@ -function ArgumentTypeConversion (arg) { - if (arg === 'const unsigned char *') { return 'UInt8Array' } + +// Some raylib functions expect the last argument to be a pointer +// to a number that it will update after completing an operation, usually +// when its reading a large chunk of data. for example LoadImagePalette or CompressData +const ints = [ + 'bytesRead', // LoadFileData + 'compDataSize', // CompressData + 'dataSize', // DecompressData + 'outputSize', // En/De codeDataBase64 + 'frames', // LoadImageAnim + 'colorCount', // LoadImagePalette + 'count', // LoadCodepoints, TextSplit + 'codepointSize', // GetCodepoint, GetCodepointNext, GetCodepointPrevious + 'position', // TextAppend + 'materialCount', // LoadMaterials + 'animCount' // LoadModelAnimations +] + +function ArgumentTypeConversion (arg, name = '') { + if (arg === 'float *') { return 'Float32Array' } + if (arg === 'const float *') { return 'Float32Array' } + + // we check for when int and unsigned int * are meant to only reference one int, not an array + // so far it's based on name but I'm not sure if theres another way + if (arg === 'int *') { + if (ints.includes(name)) { return 'number' } + return 'Int32Array' + } + if (arg === 'const int *') { return 'Int32Array' } + + if (arg === 'unsigned int *') { + if (ints.includes(name)) { return 'number' } + return 'UInt32Array' + } + if (arg === 'const unsigned int *') { return 'UInt32Array' } + + if (arg === 'short *') { return 'Int16Array' } + if (arg === 'const short *') { return 'Int16Array' } + + if (arg === 'unsigned short *') { return 'UInt16Array' } + if (arg === 'const unsigned short *') { return 'UInt16Array' } + if (arg === 'unsigned char *') { return 'UInt8Array' } + if (arg === 'const unsigned char *') { return 'UInt8Array' } if (arg === 'char') { return 'string' } if (arg === 'char *') { return 'string' } diff --git a/tools/generate_templates/node-raylib-bindings.js b/tools/generate_templates/node-raylib-bindings.js index b79daee..0106ff8 100644 --- a/tools/generate_templates/node-raylib-bindings.js +++ b/tools/generate_templates/node-raylib-bindings.js @@ -1,53 +1,87 @@ +// Some raylib functions expect the last argument to be a pointer +// to a number that it will update after completing an operation, usually +// when its reading a large chunk of data. for example LoadImagePalette or CompressData +const ints = [ + 'bytesRead', // LoadFileData + 'compDataSize', // CompressData + 'dataSize', // DecompressData + 'outputSize', // En/De codeDataBase64 + 'frames', // LoadImageAnim + 'colorCount', // LoadImagePalette + 'count', // LoadCodepoints, TextSplit + 'codepointSize', // GetCodepoint, GetCodepointNext, GetCodepointPrevious + 'position', // TextAppend + 'materialCount', // LoadMaterials + 'animCount' // LoadModelAnimations +] + /** * Sanitizes a type (primitive or struct) into a string that can be used as part of a function name. * Converts anything ending with '*' to 'pointer' * @param {*} name * @returns */ -const SanitizeTypeName = name => { - if (name === 'const Vector3') { +const SanitizeTypeName = (type, name = '') => { + if (type === 'const Vector3') { return 'Vector3' } - if (name === 'float[2]') { + if (type === 'float[2]') { return 'pointer' } - if (name === 'char[32]') { + if (type === 'char[32]') { return 'pointer' } - if (name === 'float[4]') { + if (type === 'float[4]') { return 'pointer' } - if (name === 'unsigned int[4]') { + if (type === 'unsigned int[4]') { return '(unsigned int) pointer' } - if (name === 'Matrix[2]') { + if (type === 'Matrix[2]') { return 'pointer' } - if (name === 'const char *') { + if (type === 'const char *') { return 'string' } - if (name === 'const unsigned char *') { - return 'bufferPointer' + + if (type === 'float *') { return 'Float32Array' } + if (type === 'const float *') { return 'Float32Array' } + + if (type === 'int *' && !ints.includes(name)) { return 'Int32Array' } + if (type === 'const int *') { return 'Int32Array' } + + if (type === 'unsigned int *' && !ints.includes(name)) { return 'UInt32Array' } + if (type === 'const unsigned int *') { return 'UInt32Array' } + + if (type === 'short *') { return 'Int16Array' } + if (type === 'const short *') { return 'Int16Array' } + + if (type === 'unsigned short *') { return 'UInt16Array' } + if (type === 'const unsigned short *') { return 'UInt16Array' } + + if (type === 'const unsigned char *') { + return 'UInt8Array' } - if (name === 'unsigned char *') { - return 'bufferPointer' + if (type === 'unsigned char *') { + return 'UInt8Array' } - if (name.endsWith('*')) { + + if (type.endsWith('*')) { return 'pointer' } - if (name.endsWith('Callback')) { + if (type.endsWith('Callback')) { return 'function' } - if (name === 'Camera') { + if (type === 'Camera') { return 'Camera3D' } - if (name === 'Quaternion') { + if (type === 'Quaternion') { return 'Vector4' } - if (name === 'Texture2D') { + if (type === 'Texture2D') { return 'Texture' } - return name.replace(/ /g, '') + return type.replace(/ /g, '') } const TypeUnwrappedLength = (structs, type) => { @@ -88,7 +122,7 @@ const UnwrappedFuncArguments = (structs, func) => { return func.params .map(param => { - const out = `${param.type.endsWith('*') ? ` (${param.type})` : ''} ${SanitizeTypeName(param.type)}FromValue(info, ${length})` + const out = `${param.type.endsWith('*') ? ` (${param.type})` : ''} ${SanitizeTypeName(param.type, param.name)}FromValue(info, ${length})` length += TypeUnwrappedLength(structs, param.type) return out }) @@ -244,12 +278,30 @@ inline int intFromValue(const Napi::CallbackInfo& info, int index) { inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().DoubleValue(); } + uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } -uintptr_t bufferPointerFromValue(const Napi::CallbackInfo& info, int index) { + +uintptr_t Float32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt8ArrayFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t)info[index].As().Data(); } + inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } diff --git a/tools/generate_templates/node-raylib-definitions.js b/tools/generate_templates/node-raylib-definitions.js index c8b5021..d341797 100644 --- a/tools/generate_templates/node-raylib-definitions.js +++ b/tools/generate_templates/node-raylib-definitions.js @@ -5,7 +5,7 @@ const FunctionDefinition = (func) => { export function ${func.name}(${!func.params ? '' : func.params - .map(param => `${param.name}: ${ArgumentTypeConversion(param.type)}`) + .map(param => `${param.name}: ${ArgumentTypeConversion(param.type, param.name)}`) .join(', ') }): ${ArgumentTypeConversion(func.returnType)} ` diff --git a/tools/generate_templates/node-raylib-wrapper.js b/tools/generate_templates/node-raylib-wrapper.js index ee39dd9..387d1a3 100644 --- a/tools/generate_templates/node-raylib-wrapper.js +++ b/tools/generate_templates/node-raylib-wrapper.js @@ -45,7 +45,7 @@ const JSDocsForFunction = (structs, func) => { if (func.params) { params = '\n *' for (const param of func.params) { - params += `\n * @param {${ArgumentTypeConversion(param.type)}} ${param.name}` + params += `\n * @param {${ArgumentTypeConversion(param.type, param.name)}} ${param.name}` } } From 3d9fb24e29247f348644dadcc1d047be1b8ec713 Mon Sep 17 00:00:00 2001 From: tuckie <22203973+twuky@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:35:22 -0700 Subject: [PATCH 4/5] 0.15.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6ada57a..357a1d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "hasInstallScript": true, "license": "Zlib", "dependencies": { diff --git a/package.json b/package.json index 2ef28f4..04144b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "description": "Node.js bindings for raylib.", "main": "index.js", "types": "src/generated/node-raylib.d.ts", From 24c6f2574e652a92e141b0a831cf022d48ff4fab Mon Sep 17 00:00:00 2001 From: tuckie <22203973+twuky@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:58:50 -0700 Subject: [PATCH 5/5] Disable Materials again --- docs/API.md | 104 ------------------ src/generated/node-raylib-drm.js | 177 ------------------------------- src/generated/node-raylib.cc | 80 -------------- src/generated/node-raylib.d.ts | 21 ---- src/generated/node-raylib.js | 177 ------------------------------- tools/generate.js | 2 +- 6 files changed, 1 insertion(+), 560 deletions(-) diff --git a/docs/API.md b/docs/API.md index 2aa2c79..271e58f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1105,12 +1105,6 @@
UnloadMesh(mesh)undefined

Unload mesh data from CPU and GPU

-
DrawMesh(mesh, material, transform)undefined
-

Draw a 3d mesh with material and transform

-
-
DrawMeshInstanced(mesh, material, transforms, instances)undefined
-

Draw multiple mesh instances with material and different transforms

-
ExportMesh(mesh, fileName)boolean

Export mesh data to file, returns true on success

@@ -1150,18 +1144,6 @@
GenMeshCubicmap(cubicmap, cubeSize)Mesh

Generate cubes-based map mesh from image data

-
LoadMaterials(fileName, materialCount)number
-

Load materials from model file

-
-
LoadMaterialDefault()Material
-

Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps)

-
-
IsMaterialReady(material)boolean
-

Check if a material is ready

-
-
UnloadMaterial(material)undefined
-

Unload material from GPU memory (VRAM)

-
LoadModelAnimations(fileName, animCount)number

Load model animations from file

@@ -2137,9 +2119,6 @@
GenMeshTangents(mesh)undefined

Compute mesh tangents

-
SetMaterialTexture(material, mapType, texture)undefined
-

Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...)

-
SetModelMeshMaterial(model, meshId, materialId)undefined

Set material for a mesh

@@ -6581,33 +6560,6 @@ Unload mesh data from CPU and GPU | --- | --- | | mesh | Mesh | - - -## DrawMesh(mesh, material, transform) ⇒ undefined -Draw a 3d mesh with material and transform - -**Kind**: global function - -| Param | Type | -| --- | --- | -| mesh | Mesh | -| material | Material | -| transform | Matrix | - - - -## DrawMeshInstanced(mesh, material, transforms, instances) ⇒ undefined -Draw multiple mesh instances with material and different transforms - -**Kind**: global function - -| Param | Type | -| --- | --- | -| mesh | Mesh | -| material | Material | -| transforms | number | -| instances | number | - ## ExportMesh(mesh, fileName) ⇒ boolean @@ -6787,49 +6739,6 @@ Generate cubes-based map mesh from image data | cubicmap | Image | | cubeSize | [Vector3](#Vector3) | - - -## LoadMaterials(fileName, materialCount) ⇒ number -Load materials from model file - -**Kind**: global function -**Returns**: number - The resulting Material *. - -| Param | Type | -| --- | --- | -| fileName | string | -| materialCount | number | - - - -## LoadMaterialDefault() ⇒ Material -Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) - -**Kind**: global function -**Returns**: Material - The resulting Material. - - -## IsMaterialReady(material) ⇒ boolean -Check if a material is ready - -**Kind**: global function -**Returns**: boolean - The resulting bool. - -| Param | Type | -| --- | --- | -| material | Material | - - - -## UnloadMaterial(material) ⇒ undefined -Unload material from GPU memory (VRAM) - -**Kind**: global function - -| Param | Type | -| --- | --- | -| material | Material | - ## LoadModelAnimations(fileName, animCount) ⇒ number @@ -10651,19 +10560,6 @@ Compute mesh tangents | --- | --- | | mesh | Mesh | - - -## SetMaterialTexture(material, mapType, texture) ⇒ undefined -Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) - -**Kind**: global function - -| Param | Type | -| --- | --- | -| material | Material | -| mapType | number | -| texture | Texture | - ## SetModelMeshMaterial(model, meshId, materialId) ⇒ undefined diff --git a/src/generated/node-raylib-drm.js b/src/generated/node-raylib-drm.js index 1630c5c..b4c32a3 100644 --- a/src/generated/node-raylib-drm.js +++ b/src/generated/node-raylib-drm.js @@ -7023,93 +7023,6 @@ function UnloadMesh (mesh) { } raylib.UnloadMesh = UnloadMesh -/** - * Draw a 3d mesh with material and transform - * - * @param {Mesh} mesh - * @param {Material} material - * @param {Matrix} transform - * - * @return {undefined} - */ -function DrawMesh (mesh, material, transform) { - return r.BindDrawMesh( - mesh.vertexCount, - mesh.triangleCount, - mesh.vertices, - mesh.texcoords, - mesh.texcoords2, - mesh.normals, - mesh.tangents, - mesh.colors, - mesh.indices, - mesh.animVertices, - mesh.animNormals, - mesh.boneIds, - mesh.boneWeights, - mesh.vaoId, - mesh.vboId, - material.shader.id, - material.shader.locs, - material.maps, - material.params, - transform.m0, - transform.m4, - transform.m8, - transform.m12, - transform.m1, - transform.m5, - transform.m9, - transform.m13, - transform.m2, - transform.m6, - transform.m10, - transform.m14, - transform.m3, - transform.m7, - transform.m11, - transform.m15 - ) -} -raylib.DrawMesh = DrawMesh - -/** - * Draw multiple mesh instances with material and different transforms - * - * @param {Mesh} mesh - * @param {Material} material - * @param {number} transforms - * @param {number} instances - * - * @return {undefined} - */ -function DrawMeshInstanced (mesh, material, transforms, instances) { - return r.BindDrawMeshInstanced( - mesh.vertexCount, - mesh.triangleCount, - mesh.vertices, - mesh.texcoords, - mesh.texcoords2, - mesh.normals, - mesh.tangents, - mesh.colors, - mesh.indices, - mesh.animVertices, - mesh.animNormals, - mesh.boneIds, - mesh.boneWeights, - mesh.vaoId, - mesh.vboId, - material.shader.id, - material.shader.locs, - material.maps, - material.params, - transforms, - instances - ) -} -raylib.DrawMeshInstanced = DrawMeshInstanced - /** * Export mesh data to file, returns true on success * @@ -7378,66 +7291,6 @@ function GenMeshCubicmap (cubicmap, cubeSize) { } raylib.GenMeshCubicmap = GenMeshCubicmap -/** - * Load materials from model file - * - * @param {string} fileName - * @param {number} materialCount - * - * @return {number} The resulting Material *. - */ -function LoadMaterials (fileName, materialCount) { - return r.BindLoadMaterials( - fileName, - materialCount - ) -} -raylib.LoadMaterials = LoadMaterials - -/** - * Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) - * - * @return {Material} The resulting Material. - */ -function LoadMaterialDefault () { - return r.BindLoadMaterialDefault() -} -raylib.LoadMaterialDefault = LoadMaterialDefault - -/** - * Check if a material is ready - * - * @param {Material} material - * - * @return {boolean} The resulting bool. - */ -function IsMaterialReady (material) { - return r.BindIsMaterialReady( - material.shader.id, - material.shader.locs, - material.maps, - material.params - ) -} -raylib.IsMaterialReady = IsMaterialReady - -/** - * Unload material from GPU memory (VRAM) - * - * @param {Material} material - * - * @return {undefined} - */ -function UnloadMaterial (material) { - return r.BindUnloadMaterial( - material.shader.id, - material.shader.locs, - material.maps, - material.params - ) -} -raylib.UnloadMaterial = UnloadMaterial - /** * Load model animations from file * @@ -15060,36 +14913,6 @@ function GenMeshTangents (mesh) { } raylib.GenMeshTangents = GenMeshTangents -/** - * Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) - * - * @param {Material} material - * @param {number} mapType - * @param {Texture2D} texture - * - * @return {undefined} - */ -function SetMaterialTexture (material, mapType, texture) { - const obj = r.BindSetMaterialTexture( - material.shader.id, - material.shader.locs, - material.maps, - material.params, - mapType, - texture.id, - texture.width, - texture.height, - texture.mipmaps, - texture.format - ) - if (typeof obj !== 'undefined') { - for (const key in obj) { - material[key] = obj[key] - } - } -} -raylib.SetMaterialTexture = SetMaterialTexture - /** * Set material for a mesh * diff --git a/src/generated/node-raylib.cc b/src/generated/node-raylib.cc index 88f7bf0..07a96d6 100644 --- a/src/generated/node-raylib.cc +++ b/src/generated/node-raylib.cc @@ -302,14 +302,6 @@ inline MaterialMap MaterialMapFromValue(const Napi::CallbackInfo& info, int inde }; } -inline Material MaterialFromValue(const Napi::CallbackInfo& info, int index) { - return { - ShaderFromValue(info, index + 0), - (MaterialMap *) pointerFromValue(info, index + 2), - pointerFromValue(info, index + 3) - }; -} - inline Transform TransformFromValue(const Napi::CallbackInfo& info, int index) { return { Vector3FromValue(info, index + 0), @@ -614,14 +606,6 @@ inline Napi::Value ToValue(Napi::Env env, MaterialMap obj) { return out; } -inline Napi::Value ToValue(Napi::Env env, Material obj) { - Napi::Object out = Napi::Object::New(env); - out.Set("shader", ToValue(env, obj.shader)); - out.Set("maps", ToValue(env, obj.maps)); - out.Set("params", ToValue(env, obj.params)); - return out; -} - inline Napi::Value ToValue(Napi::Env env, Transform obj) { Napi::Object out = Napi::Object::New(env); out.Set("translation", ToValue(env, obj.translation)); @@ -2704,31 +2688,6 @@ Napi::Value BindGenMeshCubicmap(const Napi::CallbackInfo& info) { ); } -Napi::Value BindLoadMaterials(const Napi::CallbackInfo& info) { - return ToValue(info.Env(), - LoadMaterials( - (const char *) stringFromValue(info, 0), - (int *) pointerFromValue(info, 1) - ) - ); -} - -Napi::Value BindLoadMaterialDefault(const Napi::CallbackInfo& info) { - return ToValue(info.Env(), - LoadMaterialDefault( - - ) - ); -} - -Napi::Value BindIsMaterialReady(const Napi::CallbackInfo& info) { - return ToValue(info.Env(), - IsMaterialReady( - MaterialFromValue(info, 0) - ) - ); -} - Napi::Value BindLoadModelAnimations(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadModelAnimations( @@ -6247,29 +6206,6 @@ void BindUnloadMesh(const Napi::CallbackInfo& info) { ); } -void BindDrawMesh(const Napi::CallbackInfo& info) { - DrawMesh( - MeshFromValue(info, 0), - MaterialFromValue(info, 15), - MatrixFromValue(info, 19) - ); -} - -void BindDrawMeshInstanced(const Napi::CallbackInfo& info) { - DrawMeshInstanced( - MeshFromValue(info, 0), - MaterialFromValue(info, 15), - (const Matrix *) pointerFromValue(info, 19), - intFromValue(info, 20) - ); -} - -void BindUnloadMaterial(const Napi::CallbackInfo& info) { - UnloadMaterial( - MaterialFromValue(info, 0) - ); -} - void BindUpdateModelAnimation(const Napi::CallbackInfo& info) { UpdateModelAnimation( ModelFromValue(info, 0), @@ -7816,15 +7752,6 @@ Napi::Value BindGenMeshTangents(const Napi::CallbackInfo& info) { return ToValue(info.Env(), obj); } -Napi::Value BindSetMaterialTexture(const Napi::CallbackInfo& info) { - Material obj = MaterialFromValue(info, 0); - SetMaterialTexture( - &obj, intFromValue(info, 4), - TextureFromValue(info, 5) - ); - return ToValue(info.Env(), obj); -} - Napi::Value BindSetModelMeshMaterial(const Napi::CallbackInfo& info) { Model obj = ModelFromValue(info, 0); SetModelMeshMaterial( @@ -8319,8 +8246,6 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set("BindUploadMesh", Napi::Function::New(env, BindUploadMesh)); exports.Set("BindUpdateMeshBuffer", Napi::Function::New(env, BindUpdateMeshBuffer)); exports.Set("BindUnloadMesh", Napi::Function::New(env, BindUnloadMesh)); - exports.Set("BindDrawMesh", Napi::Function::New(env, BindDrawMesh)); - exports.Set("BindDrawMeshInstanced", Napi::Function::New(env, BindDrawMeshInstanced)); exports.Set("BindExportMesh", Napi::Function::New(env, BindExportMesh)); exports.Set("BindGetMeshBoundingBox", Napi::Function::New(env, BindGetMeshBoundingBox)); exports.Set("BindGenMeshTangents", Napi::Function::New(env, BindGenMeshTangents)); @@ -8335,11 +8260,6 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { exports.Set("BindGenMeshKnot", Napi::Function::New(env, BindGenMeshKnot)); exports.Set("BindGenMeshHeightmap", Napi::Function::New(env, BindGenMeshHeightmap)); exports.Set("BindGenMeshCubicmap", Napi::Function::New(env, BindGenMeshCubicmap)); - exports.Set("BindLoadMaterials", Napi::Function::New(env, BindLoadMaterials)); - exports.Set("BindLoadMaterialDefault", Napi::Function::New(env, BindLoadMaterialDefault)); - exports.Set("BindIsMaterialReady", Napi::Function::New(env, BindIsMaterialReady)); - exports.Set("BindUnloadMaterial", Napi::Function::New(env, BindUnloadMaterial)); - exports.Set("BindSetMaterialTexture", Napi::Function::New(env, BindSetMaterialTexture)); exports.Set("BindSetModelMeshMaterial", Napi::Function::New(env, BindSetModelMeshMaterial)); exports.Set("BindLoadModelAnimations", Napi::Function::New(env, BindLoadModelAnimations)); exports.Set("BindUpdateModelAnimation", Napi::Function::New(env, BindUpdateModelAnimation)); diff --git a/src/generated/node-raylib.d.ts b/src/generated/node-raylib.d.ts index 9b48a58..f4d0c93 100644 --- a/src/generated/node-raylib.d.ts +++ b/src/generated/node-raylib.d.ts @@ -1693,12 +1693,6 @@ declare module "raylib" { /** Unload mesh data from CPU and GPU */ export function UnloadMesh(mesh: Mesh): void - /** Draw a 3d mesh with material and transform */ - export function DrawMesh(mesh: Mesh, material: Material, transform: Matrix): void - - /** Draw multiple mesh instances with material and different transforms */ - export function DrawMeshInstanced(mesh: Mesh, material: Material, transforms: number, instances: number): void - /** Export mesh data to file, returns true on success */ export function ExportMesh(mesh: Mesh, fileName: string): boolean @@ -1741,21 +1735,6 @@ declare module "raylib" { /** Generate cubes-based map mesh from image data */ export function GenMeshCubicmap(cubicmap: Image, cubeSize: Vector3): Mesh - /** Load materials from model file */ - export function LoadMaterials(fileName: string, materialCount: number): number - - /** Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) */ - export function LoadMaterialDefault(): Material - - /** Check if a material is ready */ - export function IsMaterialReady(material: Material): boolean - - /** Unload material from GPU memory (VRAM) */ - export function UnloadMaterial(material: Material): void - - /** Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) */ - export function SetMaterialTexture(material: Material, mapType: number, texture: Texture): void - /** Set material for a mesh */ export function SetModelMeshMaterial(model: Model, meshId: number, materialId: number): void diff --git a/src/generated/node-raylib.js b/src/generated/node-raylib.js index f602c18..a42c94d 100644 --- a/src/generated/node-raylib.js +++ b/src/generated/node-raylib.js @@ -7023,93 +7023,6 @@ function UnloadMesh (mesh) { } raylib.UnloadMesh = UnloadMesh -/** - * Draw a 3d mesh with material and transform - * - * @param {Mesh} mesh - * @param {Material} material - * @param {Matrix} transform - * - * @return {undefined} - */ -function DrawMesh (mesh, material, transform) { - return r.BindDrawMesh( - mesh.vertexCount, - mesh.triangleCount, - mesh.vertices, - mesh.texcoords, - mesh.texcoords2, - mesh.normals, - mesh.tangents, - mesh.colors, - mesh.indices, - mesh.animVertices, - mesh.animNormals, - mesh.boneIds, - mesh.boneWeights, - mesh.vaoId, - mesh.vboId, - material.shader.id, - material.shader.locs, - material.maps, - material.params, - transform.m0, - transform.m4, - transform.m8, - transform.m12, - transform.m1, - transform.m5, - transform.m9, - transform.m13, - transform.m2, - transform.m6, - transform.m10, - transform.m14, - transform.m3, - transform.m7, - transform.m11, - transform.m15 - ) -} -raylib.DrawMesh = DrawMesh - -/** - * Draw multiple mesh instances with material and different transforms - * - * @param {Mesh} mesh - * @param {Material} material - * @param {number} transforms - * @param {number} instances - * - * @return {undefined} - */ -function DrawMeshInstanced (mesh, material, transforms, instances) { - return r.BindDrawMeshInstanced( - mesh.vertexCount, - mesh.triangleCount, - mesh.vertices, - mesh.texcoords, - mesh.texcoords2, - mesh.normals, - mesh.tangents, - mesh.colors, - mesh.indices, - mesh.animVertices, - mesh.animNormals, - mesh.boneIds, - mesh.boneWeights, - mesh.vaoId, - mesh.vboId, - material.shader.id, - material.shader.locs, - material.maps, - material.params, - transforms, - instances - ) -} -raylib.DrawMeshInstanced = DrawMeshInstanced - /** * Export mesh data to file, returns true on success * @@ -7378,66 +7291,6 @@ function GenMeshCubicmap (cubicmap, cubeSize) { } raylib.GenMeshCubicmap = GenMeshCubicmap -/** - * Load materials from model file - * - * @param {string} fileName - * @param {number} materialCount - * - * @return {number} The resulting Material *. - */ -function LoadMaterials (fileName, materialCount) { - return r.BindLoadMaterials( - fileName, - materialCount - ) -} -raylib.LoadMaterials = LoadMaterials - -/** - * Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) - * - * @return {Material} The resulting Material. - */ -function LoadMaterialDefault () { - return r.BindLoadMaterialDefault() -} -raylib.LoadMaterialDefault = LoadMaterialDefault - -/** - * Check if a material is ready - * - * @param {Material} material - * - * @return {boolean} The resulting bool. - */ -function IsMaterialReady (material) { - return r.BindIsMaterialReady( - material.shader.id, - material.shader.locs, - material.maps, - material.params - ) -} -raylib.IsMaterialReady = IsMaterialReady - -/** - * Unload material from GPU memory (VRAM) - * - * @param {Material} material - * - * @return {undefined} - */ -function UnloadMaterial (material) { - return r.BindUnloadMaterial( - material.shader.id, - material.shader.locs, - material.maps, - material.params - ) -} -raylib.UnloadMaterial = UnloadMaterial - /** * Load model animations from file * @@ -15060,36 +14913,6 @@ function GenMeshTangents (mesh) { } raylib.GenMeshTangents = GenMeshTangents -/** - * Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) - * - * @param {Material} material - * @param {number} mapType - * @param {Texture} texture - * - * @return {undefined} - */ -function SetMaterialTexture (material, mapType, texture) { - const obj = r.BindSetMaterialTexture( - material.shader.id, - material.shader.locs, - material.maps, - material.params, - mapType, - texture.id, - texture.width, - texture.height, - texture.mipmaps, - texture.format - ) - if (typeof obj !== 'undefined') { - for (const key in obj) { - material[key] = obj[key] - } - } -} -raylib.SetMaterialTexture = SetMaterialTexture - /** * Set material for a mesh * diff --git a/tools/generate.js b/tools/generate.js index 6239922..a27a691 100644 --- a/tools/generate.js +++ b/tools/generate.js @@ -34,7 +34,7 @@ const blocklist = [ // @todo Verify Structs that have array properties 'VrStereoConfig', // Matrix[2], float[2] 'VrDeviceInfo', // float[4] - // 'Material', // float[4] + 'Material', // float[4] // raymath // @todo Fix helper structs for float arrays