Merge branch 'master' of github.com:raysan5/raylib
This commit is contained in:
commit
3f1052db99
|
|
@ -9,7 +9,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
|||
| [raylib](https://github.com/raysan5/raylib) | **5.0** | [C/C++](https://en.wikipedia.org/wiki/C_(programming_language)) | Zlib |
|
||||
| [raylib-beef](https://github.com/Starpelly/raylib-beef) | **5.0** | [Beef](https://www.beeflang.org) | MIT |
|
||||
| [raylib-boo](https://github.com/Rabios/raylib-boo) | 3.7 | [Boo](http://boo-language.github.io) | MIT |
|
||||
| [raybit](https://github.com/Alex-Velez/raybit) | 3.7 | [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) | MIT |
|
||||
| [raybit](https://github.com/Alex-Velez/raybit) | **5.0** | [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) | MIT |
|
||||
| [Raylib-cs](https://github.com/ChrisDill/Raylib-cs) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib |
|
||||
| [Raylib-CsLo](https://github.com/NotNotTech/Raylib-CsLo) | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 |
|
||||
| [Raylib-CSharp-Vinculum](https://github.com/ZeroElectric/Raylib-CSharp-Vinculum) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 |
|
||||
|
|
@ -78,10 +78,10 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
|||
| [raylib-zig-bindings](https://github.com/L-Briand/raylib-zig-bindings) | **5.0** | [Zig](https://ziglang.org) | Zlib |
|
||||
| [hare-raylib](https://git.sr.ht/~evantj/hare-raylib) | **auto** | [Hare](https://harelang.org) | Zlib |
|
||||
| [raylib-sunder](https://github.com/ashn-dot-dev/raylib-sunder) | **auto** | [Sunder](https://github.com/ashn-dot-dev/sunder) | 0BSD |
|
||||
| [rayed-bqn](https://github.com/Brian-ED/rayed-bqn) | **auto** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
|
||||
| [raylib-bqn](https://github.com/Brian-ED/raylib-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
|
||||
| [rayjs](https://github.com/mode777/rayjs) | 4.6-dev | [QuickJS](https://bellard.org/quickjs) | MIT |
|
||||
| [raylib-raku](https://github.com/vushu/raylib-raku) | **auto** | [Raku](https://www.raku.org) | Artistic License 2.0 |
|
||||
| [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | 4.5 | [Lean4](https://lean-lang.org) | BSD-3-Clause |
|
||||
| [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | **5.5-dev** | [Lean4](https://lean-lang.org) | BSD-3-Clause |
|
||||
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
|
||||
| [raylib-apl](https://github.com/Brian-ED/raylib-apl) | **5.0** | [Dyalog APL](https://www.dyalog.com/) | MIT |
|
||||
|
||||
|
|
@ -92,6 +92,7 @@ These are utility wrappers for specific languages, they are not required to use
|
|||
| ---------------------------------------------------- | :------------: | :------------------------------------------: | :-----: |
|
||||
| [raylib-cpp](https://github.com/robloach/raylib-cpp) | **5.0** | [C++](https://en.wikipedia.org/wiki/C%2B%2B) | Zlib |
|
||||
| [claylib](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib |
|
||||
| [rayed-bqn](https://github.com/Brian-ED/rayed-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
|
||||
|
||||
### Older or Unmaintained Language Bindings
|
||||
|
||||
|
|
|
|||
|
|
@ -70,8 +70,9 @@ RAYLIB_SRC_PATH ?= ../src
|
|||
|
||||
# Locations of raylib.h and libraylib.a/libraylib.so
|
||||
# NOTE: Those variables are only used for PLATFORM_OS: LINUX, BSD
|
||||
RAYLIB_INCLUDE_PATH ?= /usr/local/include
|
||||
RAYLIB_LIB_PATH ?= /usr/local/lib
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INCLUDE_PATH ?= $(DESTDIR)/include
|
||||
RAYLIB_LIB_PATH ?= $(DESTDIR)/lib
|
||||
|
||||
# Library type compilation: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
|
@ -586,7 +587,8 @@ MODELS = \
|
|||
models/models_rlgl_solar_system \
|
||||
models/models_skybox \
|
||||
models/models_waving_cubes \
|
||||
models/models_yaw_pitch_roll
|
||||
models/models_yaw_pitch_roll \
|
||||
models/models_gpu_skinning
|
||||
|
||||
SHADERS = \
|
||||
shaders/shaders_basic_lighting \
|
||||
|
|
|
|||
|
|
@ -35,8 +35,9 @@ RAYLIB_PATH ?= ..
|
|||
|
||||
# Locations of raylib.h and libraylib.a/libraylib.so
|
||||
# NOTE: Those variables are only used for PLATFORM_OS: LINUX, BSD
|
||||
RAYLIB_INCLUDE_PATH ?= /usr/local/include
|
||||
RAYLIB_LIB_PATH ?= /usr/local/lib
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INCLUDE_PATH ?= $(DESTDIR)/include
|
||||
RAYLIB_LIB_PATH ?= $(DESTDIR)/lib
|
||||
|
||||
# Library type compilation: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
|
|
|||
117
examples/models/models_gpu_skinning.c
Normal file
117
examples/models/models_gpu_skinning.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - Doing skinning on the gpu using a vertex shader
|
||||
*
|
||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||
*
|
||||
* Example contributed by Daniel Holden (@orangeduck) 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) 2024 Daniel Holden (@orangeduck)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include "raymath.h"
|
||||
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
#define GLSL_VERSION 330
|
||||
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
||||
#define GLSL_VERSION 100
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - GPU skinning");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
||||
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||
|
||||
// Load gltf model
|
||||
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
|
||||
|
||||
// Load skinning shader
|
||||
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||
|
||||
characterModel.materials[1].shader = skinningShader;
|
||||
|
||||
// Load gltf model animations
|
||||
int animsCount = 0;
|
||||
unsigned int animIndex = 0;
|
||||
unsigned int animCurrentFrame = 0;
|
||||
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/greenman.glb", &animsCount);
|
||||
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||
|
||||
// Select current animation
|
||||
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
|
||||
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
|
||||
|
||||
// Update model animation
|
||||
ModelAnimation anim = modelAnimations[animIndex];
|
||||
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
|
||||
UpdateModelAnimationBoneMatrices(characterModel, anim, animCurrentFrame);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
// Draw character
|
||||
characterModel.transform = MatrixTranslate(position.x, position.y, position.z);
|
||||
UpdateModelAnimationBoneMatrices(characterModel, anim, animCurrentFrame);
|
||||
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModelAnimations(modelAnimations, animsCount);
|
||||
UnloadModel(characterModel); // Unload character model and meshes/material
|
||||
UnloadShader(skinningShader);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
examples/models/resources/shaders/glsl100/skinning.fs
Normal file
17
examples/models/resources/shaders/glsl100/skinning.fs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 100
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
34
examples/models/resources/shaders/glsl100/skinning.vs
Normal file
34
examples/models/resources/shaders/glsl100/skinning.vs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#version 100
|
||||
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec4 vertexColor;
|
||||
in vec4 vertexBoneIds;
|
||||
in vec4 vertexBoneWeights;
|
||||
|
||||
#define MAX_BONE_NUM 128
|
||||
uniform mat4 boneMatrices[MAX_BONE_NUM];
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
int boneIndex0 = int(vertexBoneIds.x);
|
||||
int boneIndex1 = int(vertexBoneIds.y);
|
||||
int boneIndex2 = int(vertexBoneIds.z);
|
||||
int boneIndex3 = int(vertexBoneIds.w);
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x * (boneMatrices[boneIndex0] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.y * (boneMatrices[boneIndex1] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.z * (boneMatrices[boneIndex2] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.w * (boneMatrices[boneIndex3] * vec4(vertexPosition, 1.0f));
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
gl_Position = mvp * skinnedPosition;
|
||||
}
|
||||
17
examples/models/resources/shaders/glsl330/skinning.fs
Normal file
17
examples/models/resources/shaders/glsl330/skinning.fs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
finalColor = texelColor*colDiffuse*fragColor;
|
||||
}
|
||||
34
examples/models/resources/shaders/glsl330/skinning.vs
Normal file
34
examples/models/resources/shaders/glsl330/skinning.vs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#version 330
|
||||
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec4 vertexColor;
|
||||
in vec4 vertexBoneIds;
|
||||
in vec4 vertexBoneWeights;
|
||||
|
||||
#define MAX_BONE_NUM 128
|
||||
uniform mat4 boneMatrices[MAX_BONE_NUM];
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
int boneIndex0 = int(vertexBoneIds.x);
|
||||
int boneIndex1 = int(vertexBoneIds.y);
|
||||
int boneIndex2 = int(vertexBoneIds.z);
|
||||
int boneIndex3 = int(vertexBoneIds.w);
|
||||
|
||||
vec4 skinnedPosition =
|
||||
vertexBoneWeights.x * (boneMatrices[boneIndex0] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.y * (boneMatrices[boneIndex1] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.z * (boneMatrices[boneIndex2] * vec4(vertexPosition, 1.0f)) +
|
||||
vertexBoneWeights.w * (boneMatrices[boneIndex3] * vec4(vertexPosition, 1.0f));
|
||||
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
|
||||
gl_Position = mvp * skinnedPosition;
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ OPTIONS:
|
|||
-f, --format <type> : Define output format for parser data.
|
||||
Supported types: DEFAULT, JSON, XML, LUA
|
||||
|
||||
-d, --define <DEF> : Define functions specifiers (i.e. RLAPI for raylib.h, RMDEF for raymath.h, etc.)
|
||||
-d, --define <DEF> : Define functions specifiers (i.e. RLAPI for raylib.h, RMAPI for raymath.h, etc.)
|
||||
NOTE: If no specifier defined, defaults to: RLAPI
|
||||
|
||||
-t, --truncate <after> : Define string to truncate input after (i.e. "RLGL IMPLEMENTATION" for rlgl.h)
|
||||
|
|
@ -56,7 +56,7 @@ EXAMPLES:
|
|||
> raylib_parser --output raylib_data.info --format XML
|
||||
Process <raylib.h> to generate <raylib_data.info> as XML text data
|
||||
|
||||
> raylib_parser --input raymath.h --output raymath_data.info --format XML
|
||||
> raylib_parser --input raymath.h --output raymath_data.info --format XML --define RMAPI
|
||||
Process <raymath.h> to generate <raymath_data.info> as XML text data
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -850,12 +850,22 @@
|
|||
{
|
||||
"type": "unsigned char *",
|
||||
"name": "boneIds",
|
||||
"description": "Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning)"
|
||||
"description": "Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6)"
|
||||
},
|
||||
{
|
||||
"type": "float *",
|
||||
"name": "boneWeights",
|
||||
"description": "Vertex bone weight, up to 4 bones influence by vertex (skinning)"
|
||||
"description": "Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)"
|
||||
},
|
||||
{
|
||||
"type": "Matrix *",
|
||||
"name": "boneMatrices",
|
||||
"description": "Bones animated transformation matrices"
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"name": "boneCount",
|
||||
"description": "Number of bones"
|
||||
},
|
||||
{
|
||||
"type": "unsigned int",
|
||||
|
|
@ -2518,6 +2528,21 @@
|
|||
"name": "SHADER_LOC_MAP_BRDF",
|
||||
"value": 25,
|
||||
"description": "Shader location: sampler2d texture: brdf"
|
||||
},
|
||||
{
|
||||
"name": "SHADER_LOC_VERTEX_BONEIDS",
|
||||
"value": 26,
|
||||
"description": "Shader location: vertex attribute: boneIds"
|
||||
},
|
||||
{
|
||||
"name": "SHADER_LOC_VERTEX_BONEWEIGHTS",
|
||||
"value": 27,
|
||||
"description": "Shader location: vertex attribute: boneWeights"
|
||||
},
|
||||
{
|
||||
"name": "SHADER_LOC_BONE_MATRICES",
|
||||
"value": 28,
|
||||
"description": "Shader location: array of matrices uniform: boneMatrices"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -4477,6 +4502,17 @@
|
|||
"description": "Get the directory of the running application (uses static string)",
|
||||
"returnType": "const char *"
|
||||
},
|
||||
{
|
||||
"name": "MakeDirectory",
|
||||
"description": "Create directories (including full path requested), returns 0 on success",
|
||||
"returnType": "int",
|
||||
"params": [
|
||||
{
|
||||
"type": "const char *",
|
||||
"name": "dirPath"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ChangeDirectory",
|
||||
"description": "Change working directory, return true on success",
|
||||
|
|
@ -4523,7 +4559,7 @@
|
|||
},
|
||||
{
|
||||
"name": "LoadDirectoryFilesEx",
|
||||
"description": "Load directory filepaths with extension filtering and recursive directory scan",
|
||||
"description": "Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result",
|
||||
"returnType": "FilePathList",
|
||||
"params": [
|
||||
{
|
||||
|
|
@ -8780,6 +8816,25 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ColorLerp",
|
||||
"description": "Get color lerp interpolation between two colors, factor [0.0f..1.0f]",
|
||||
"returnType": "Color",
|
||||
"params": [
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "color1"
|
||||
},
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "color2"
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"name": "factor"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "GetColor",
|
||||
"description": "Get Color structure from hexadecimal value",
|
||||
|
|
@ -8862,7 +8917,7 @@
|
|||
},
|
||||
{
|
||||
"name": "LoadFontEx",
|
||||
"description": "Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character setFont",
|
||||
"description": "Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height",
|
||||
"returnType": "Font",
|
||||
"params": [
|
||||
{
|
||||
|
|
@ -11047,6 +11102,25 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "UpdateModelAnimationBoneMatrices",
|
||||
"description": "Update model animation mesh bone matrices",
|
||||
"returnType": "void",
|
||||
"params": [
|
||||
{
|
||||
"type": "Model",
|
||||
"name": "model"
|
||||
},
|
||||
{
|
||||
"type": "ModelAnimation",
|
||||
"name": "anim"
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"name": "frame"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CheckCollisionSpheres",
|
||||
"description": "Check collision between two spheres",
|
||||
|
|
|
|||
|
|
@ -850,12 +850,22 @@ return {
|
|||
{
|
||||
type = "unsigned char *",
|
||||
name = "boneIds",
|
||||
description = "Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning)"
|
||||
description = "Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6)"
|
||||
},
|
||||
{
|
||||
type = "float *",
|
||||
name = "boneWeights",
|
||||
description = "Vertex bone weight, up to 4 bones influence by vertex (skinning)"
|
||||
description = "Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)"
|
||||
},
|
||||
{
|
||||
type = "Matrix *",
|
||||
name = "boneMatrices",
|
||||
description = "Bones animated transformation matrices"
|
||||
},
|
||||
{
|
||||
type = "int",
|
||||
name = "boneCount",
|
||||
description = "Number of bones"
|
||||
},
|
||||
{
|
||||
type = "unsigned int",
|
||||
|
|
@ -2518,6 +2528,21 @@ return {
|
|||
name = "SHADER_LOC_MAP_BRDF",
|
||||
value = 25,
|
||||
description = "Shader location: sampler2d texture: brdf"
|
||||
},
|
||||
{
|
||||
name = "SHADER_LOC_VERTEX_BONEIDS",
|
||||
value = 26,
|
||||
description = "Shader location: vertex attribute: boneIds"
|
||||
},
|
||||
{
|
||||
name = "SHADER_LOC_VERTEX_BONEWEIGHTS",
|
||||
value = 27,
|
||||
description = "Shader location: vertex attribute: boneWeights"
|
||||
},
|
||||
{
|
||||
name = "SHADER_LOC_BONE_MATRICES",
|
||||
value = 28,
|
||||
description = "Shader location: array of matrices uniform: boneMatrices"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -4042,6 +4067,14 @@ return {
|
|||
description = "Get the directory of the running application (uses static string)",
|
||||
returnType = "const char *"
|
||||
},
|
||||
{
|
||||
name = "MakeDirectory",
|
||||
description = "Create directories (including full path requested), returns 0 on success",
|
||||
returnType = "int",
|
||||
params = {
|
||||
{type = "const char *", name = "dirPath"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "ChangeDirectory",
|
||||
description = "Change working directory, return true on success",
|
||||
|
|
@ -4076,7 +4109,7 @@ return {
|
|||
},
|
||||
{
|
||||
name = "LoadDirectoryFilesEx",
|
||||
description = "Load directory filepaths with extension filtering and recursive directory scan",
|
||||
description = "Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result",
|
||||
returnType = "FilePathList",
|
||||
params = {
|
||||
{type = "const char *", name = "basePath"},
|
||||
|
|
@ -6377,6 +6410,16 @@ return {
|
|||
{type = "Color", name = "tint"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "ColorLerp",
|
||||
description = "Get color lerp interpolation between two colors, factor [0.0f..1.0f]",
|
||||
returnType = "Color",
|
||||
params = {
|
||||
{type = "Color", name = "color1"},
|
||||
{type = "Color", name = "color2"},
|
||||
{type = "float", name = "factor"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "GetColor",
|
||||
description = "Get Color structure from hexadecimal value",
|
||||
|
|
@ -6429,7 +6472,7 @@ return {
|
|||
},
|
||||
{
|
||||
name = "LoadFontEx",
|
||||
description = "Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character setFont",
|
||||
description = "Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height",
|
||||
returnType = "Font",
|
||||
params = {
|
||||
{type = "const char *", name = "fileName"},
|
||||
|
|
@ -7576,6 +7619,16 @@ return {
|
|||
{type = "ModelAnimation", name = "anim"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "UpdateModelAnimationBoneMatrices",
|
||||
description = "Update model animation mesh bone matrices",
|
||||
returnType = "void",
|
||||
params = {
|
||||
{type = "Model", name = "model"},
|
||||
{type = "ModelAnimation", name = "anim"},
|
||||
{type = "int", name = "frame"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "CheckCollisionSpheres",
|
||||
description = "Check collision between two spheres",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -160,7 +160,7 @@
|
|||
<Field type="float" name="rotation" desc="Camera rotation in degrees" />
|
||||
<Field type="float" name="zoom" desc="Camera zoom (scaling), should be 1.0f by default" />
|
||||
</Struct>
|
||||
<Struct name="Mesh" fieldCount="15" desc="Mesh, vertex data and vao/vbo">
|
||||
<Struct name="Mesh" fieldCount="17" desc="Mesh, vertex data and vao/vbo">
|
||||
<Field type="int" name="vertexCount" desc="Number of vertices stored in arrays" />
|
||||
<Field type="int" name="triangleCount" desc="Number of triangles stored (indexed or not)" />
|
||||
<Field type="float *" name="vertices" desc="Vertex position (XYZ - 3 components per vertex) (shader-location = 0)" />
|
||||
|
|
@ -172,8 +172,10 @@
|
|||
<Field type="unsigned short *" name="indices" desc="Vertex indices (in case vertex data comes indexed)" />
|
||||
<Field type="float *" name="animVertices" desc="Animated vertex positions (after bones transformations)" />
|
||||
<Field type="float *" name="animNormals" desc="Animated normals (after bones transformations)" />
|
||||
<Field type="unsigned char *" name="boneIds" desc="Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning)" />
|
||||
<Field type="float *" name="boneWeights" desc="Vertex bone weight, up to 4 bones influence by vertex (skinning)" />
|
||||
<Field type="unsigned char *" name="boneIds" desc="Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6)" />
|
||||
<Field type="float *" name="boneWeights" desc="Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)" />
|
||||
<Field type="Matrix *" name="boneMatrices" desc="Bones animated transformation matrices" />
|
||||
<Field type="int" name="boneCount" desc="Number of bones" />
|
||||
<Field type="unsigned int" name="vaoId" desc="OpenGL Vertex Array Object id" />
|
||||
<Field type="unsigned int *" name="vboId" desc="OpenGL Vertex Buffer Objects id (default vertex data)" />
|
||||
</Struct>
|
||||
|
|
@ -505,7 +507,7 @@
|
|||
<Value name="MATERIAL_MAP_PREFILTER" integer="9" desc="Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP)" />
|
||||
<Value name="MATERIAL_MAP_BRDF" integer="10" desc="Brdf material" />
|
||||
</Enum>
|
||||
<Enum name="ShaderLocationIndex" valueCount="26" desc="Shader location index">
|
||||
<Enum name="ShaderLocationIndex" valueCount="29" desc="Shader location index">
|
||||
<Value name="SHADER_LOC_VERTEX_POSITION" integer="0" desc="Shader location: vertex attribute: position" />
|
||||
<Value name="SHADER_LOC_VERTEX_TEXCOORD01" integer="1" desc="Shader location: vertex attribute: texcoord01" />
|
||||
<Value name="SHADER_LOC_VERTEX_TEXCOORD02" integer="2" desc="Shader location: vertex attribute: texcoord02" />
|
||||
|
|
@ -532,6 +534,9 @@
|
|||
<Value name="SHADER_LOC_MAP_IRRADIANCE" integer="23" desc="Shader location: samplerCube texture: irradiance" />
|
||||
<Value name="SHADER_LOC_MAP_PREFILTER" integer="24" desc="Shader location: samplerCube texture: prefilter" />
|
||||
<Value name="SHADER_LOC_MAP_BRDF" integer="25" desc="Shader location: sampler2d texture: brdf" />
|
||||
<Value name="SHADER_LOC_VERTEX_BONEIDS" integer="26" desc="Shader location: vertex attribute: boneIds" />
|
||||
<Value name="SHADER_LOC_VERTEX_BONEWEIGHTS" integer="27" desc="Shader location: vertex attribute: boneWeights" />
|
||||
<Value name="SHADER_LOC_BONE_MATRICES" integer="28" desc="Shader location: array of matrices uniform: boneMatrices" />
|
||||
</Enum>
|
||||
<Enum name="ShaderUniformDataType" valueCount="9" desc="Shader uniform data type">
|
||||
<Value name="SHADER_UNIFORM_FLOAT" integer="0" desc="Shader uniform type: float" />
|
||||
|
|
@ -670,7 +675,7 @@
|
|||
<Param type="unsigned int" name="frames" desc="" />
|
||||
</Callback>
|
||||
</Callbacks>
|
||||
<Functions count="575">
|
||||
<Functions count="578">
|
||||
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
|
||||
<Param type="int" name="width" desc="" />
|
||||
<Param type="int" name="height" desc="" />
|
||||
|
|
@ -1069,6 +1074,9 @@
|
|||
</Function>
|
||||
<Function name="GetApplicationDirectory" retType="const char *" paramCount="0" desc="Get the directory of the running application (uses static string)">
|
||||
</Function>
|
||||
<Function name="MakeDirectory" retType="int" paramCount="1" desc="Create directories (including full path requested), returns 0 on success">
|
||||
<Param type="const char *" name="dirPath" desc="" />
|
||||
</Function>
|
||||
<Function name="ChangeDirectory" retType="bool" paramCount="1" desc="Change working directory, return true on success">
|
||||
<Param type="const char *" name="dir" desc="" />
|
||||
</Function>
|
||||
|
|
@ -1081,7 +1089,7 @@
|
|||
<Function name="LoadDirectoryFiles" retType="FilePathList" paramCount="1" desc="Load directory filepaths">
|
||||
<Param type="const char *" name="dirPath" desc="" />
|
||||
</Function>
|
||||
<Function name="LoadDirectoryFilesEx" retType="FilePathList" paramCount="3" desc="Load directory filepaths with extension filtering and recursive directory scan">
|
||||
<Function name="LoadDirectoryFilesEx" retType="FilePathList" paramCount="3" desc="Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result">
|
||||
<Param type="const char *" name="basePath" desc="" />
|
||||
<Param type="const char *" name="filter" desc="" />
|
||||
<Param type="bool" name="scanSubdirs" desc="" />
|
||||
|
|
@ -2219,6 +2227,11 @@
|
|||
<Param type="Color" name="src" desc="" />
|
||||
<Param type="Color" name="tint" desc="" />
|
||||
</Function>
|
||||
<Function name="ColorLerp" retType="Color" paramCount="3" desc="Get color lerp interpolation between two colors, factor [0.0f..1.0f]">
|
||||
<Param type="Color" name="color1" desc="" />
|
||||
<Param type="Color" name="color2" desc="" />
|
||||
<Param type="float" name="factor" desc="" />
|
||||
</Function>
|
||||
<Function name="GetColor" retType="Color" paramCount="1" desc="Get Color structure from hexadecimal value">
|
||||
<Param type="unsigned int" name="hexValue" desc="" />
|
||||
</Function>
|
||||
|
|
@ -2241,7 +2254,7 @@
|
|||
<Function name="LoadFont" retType="Font" paramCount="1" desc="Load font from file into GPU memory (VRAM)">
|
||||
<Param type="const char *" name="fileName" desc="" />
|
||||
</Function>
|
||||
<Function name="LoadFontEx" retType="Font" paramCount="4" desc="Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character setFont">
|
||||
<Function name="LoadFontEx" retType="Font" paramCount="4" desc="Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height">
|
||||
<Param type="const char *" name="fileName" desc="" />
|
||||
<Param type="int" name="fontSize" desc="" />
|
||||
<Param type="int *" name="codepoints" desc="" />
|
||||
|
|
@ -2817,6 +2830,11 @@
|
|||
<Param type="Model" name="model" desc="" />
|
||||
<Param type="ModelAnimation" name="anim" desc="" />
|
||||
</Function>
|
||||
<Function name="UpdateModelAnimationBoneMatrices" retType="void" paramCount="3" desc="Update model animation mesh bone matrices">
|
||||
<Param type="Model" name="model" desc="" />
|
||||
<Param type="ModelAnimation" name="anim" desc="" />
|
||||
<Param type="int" name="frame" desc="" />
|
||||
</Function>
|
||||
<Function name="CheckCollisionSpheres" retType="bool" paramCount="4" desc="Check collision between two spheres">
|
||||
<Param type="Vector3" name="center1" desc="" />
|
||||
<Param type="float" name="radius1" desc="" />
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@
|
|||
#define MAX_CALLBACKS_TO_PARSE 64 // Maximum number of callbacks to parse
|
||||
#define MAX_FUNCS_TO_PARSE 1024 // Maximum number of functions to parse
|
||||
|
||||
#define MAX_LINE_LENGTH 512 // Maximum length of one line (including comments)
|
||||
#define MAX_LINE_LENGTH 1024 // Maximum length of one line (including comments)
|
||||
|
||||
#define MAX_STRUCT_FIELDS 64 // Maximum number of struct fields
|
||||
#define MAX_ENUM_VALUES 512 // Maximum number of enum values
|
||||
|
|
@ -139,7 +139,7 @@ typedef struct EnumInfo {
|
|||
// Function info data
|
||||
typedef struct FunctionInfo {
|
||||
char name[64]; // Function name
|
||||
char desc[128]; // Function description (comment at the end)
|
||||
char desc[512]; // Function description (comment at the end)
|
||||
char retType[32]; // Return value type
|
||||
int paramCount; // Number of function parameters
|
||||
char paramType[MAX_FUNCTION_PARAMETERS][32]; // Parameters type
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ target_link_libraries(${PROJECT_NAME} raylib)
|
|||
|
||||
# Web Configurations
|
||||
if (${PLATFORM} STREQUAL "Web")
|
||||
# Tell Emscripten to build an example.html file.
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html") # Tell Emscripten to build an example.html file.
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s GL_ENABLE_GET_PROC_ADDRESS=1")
|
||||
endif()
|
||||
|
||||
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,6 @@ Compiling for the web requires the [Emscripten SDK](https://emscripten.org/docs/
|
|||
``` bash
|
||||
mkdir build
|
||||
cd build
|
||||
emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3" -DCMAKE_EXECUTABLE_SUFFIX=".html"
|
||||
emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXECUTABLE_SUFFIX=".html"
|
||||
emmake make
|
||||
```
|
||||
|
|
@ -119,6 +119,9 @@
|
|||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 6
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 7
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 8
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||
|
|
|
|||
1
src/external/glfw/src/mappings.h
vendored
1
src/external/glfw/src/mappings.h
vendored
|
|
@ -996,6 +996,7 @@ const char* _glfwDefaultMappings[] =
|
|||
"03000000c0160000e105000001010000,Xin-Mo Xin-Mo Dual Arcade,a:b4,b:b3,back:b6,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b9,leftshoulder:b2,leftx:a0,lefty:a1,rightshoulder:b5,start:b7,x:b1,y:b0,platform:Linux,",
|
||||
"03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,",
|
||||
"03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,",
|
||||
"03000000af1e00002400000010010000,Clockwork Pi DevTerm,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,start:b9,x:b3,y:b0,platform:Linux,",
|
||||
#endif // GLFW_BUILD_LINUX_JOYSTICK
|
||||
};
|
||||
|
||||
|
|
|
|||
2
src/external/par_shapes.h
vendored
2
src/external/par_shapes.h
vendored
|
|
@ -1130,7 +1130,7 @@ static par_shapes__rule* par_shapes__pick_rule(const char* name,
|
|||
total += rule->weight;
|
||||
}
|
||||
}
|
||||
float r = (float) rand() / RAND_MAX;
|
||||
float r = (float) rand() / (float) RAND_MAX;
|
||||
float t = 0;
|
||||
for (int i = 0; i < nrules; i++) {
|
||||
rule = rules + i;
|
||||
|
|
|
|||
507
src/external/stb_image_resize2.h
vendored
507
src/external/stb_image_resize2.h
vendored
File diff suppressed because it is too large
Load Diff
|
|
@ -694,11 +694,12 @@ void PollInputEvents(void)
|
|||
// Process this event
|
||||
if (platform.source != NULL) platform.source->process(platform.app, platform.source);
|
||||
|
||||
// NOTE: Never close window, native activity is controlled by the system!
|
||||
// NOTE: Allow closing the window in case a configuration change happened.
|
||||
// The android_main function should be allowed to return to its caller in order for the
|
||||
// Android OS to relaunch the activity.
|
||||
if (platform.app->destroyRequested != 0)
|
||||
{
|
||||
//CORE.Window.shouldClose = true;
|
||||
//ANativeActivity_finish(platform.app->activity);
|
||||
CORE.Window.shouldClose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -781,7 +782,7 @@ int InitPlatform(void)
|
|||
// Process this event
|
||||
if (platform.source != NULL) platform.source->process(platform.app, platform.source);
|
||||
|
||||
// NOTE: Never close window, native activity is controlled by the system!
|
||||
// NOTE: It's highly likely destroyRequested will never be non-zero at the start of the activity lifecycle.
|
||||
//if (platform.app->destroyRequested != 0) CORE.Window.shouldClose = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -812,6 +813,12 @@ void ClosePlatform(void)
|
|||
eglTerminate(platform.device);
|
||||
platform.device = EGL_NO_DISPLAY;
|
||||
}
|
||||
|
||||
// NOTE: Reset global state in case the activity is being relaunched.
|
||||
if (platform.app->destroyRequested != 0) {
|
||||
CORE = (CoreData){0};
|
||||
platform = (PlatformData){0};
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize display device and framebuffer
|
||||
|
|
|
|||
|
|
@ -940,7 +940,7 @@ void PollInputEvents(void)
|
|||
SetupViewport(platform.window->r.w, platform.window->r.h);
|
||||
CORE.Window.screen.width = platform.window->r.w;
|
||||
CORE.Window.screen.height = platform.window->r.h;
|
||||
CORE.Window.currentFbo.width = platform.window->r.w;;
|
||||
CORE.Window.currentFbo.width = platform.window->r.w;
|
||||
CORE.Window.currentFbo.height = platform.window->r.h;
|
||||
CORE.Window.resizedLastFrame = true;
|
||||
} break;
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ static const short linuxToRaylibMap[KEYMAP_SIZE] = {
|
|||
[BTN_TL] = GAMEPAD_BUTTON_LEFT_TRIGGER_1,
|
||||
[BTN_TL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2,
|
||||
[BTN_TR] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1,
|
||||
[BTN_TR2] GAMEPAD_BUTTON_RIGHT_TRIGGER_2,
|
||||
[BTN_TR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2,
|
||||
[BTN_SELECT] = GAMEPAD_BUTTON_MIDDLE_LEFT,
|
||||
[BTN_MODE] = GAMEPAD_BUTTON_MIDDLE,
|
||||
[BTN_START] = GAMEPAD_BUTTON_MIDDLE_RIGHT,
|
||||
|
|
@ -764,7 +764,9 @@ int InitPlatform(void)
|
|||
drmModeConnector *con = drmModeGetConnector(platform.fd, res->connectors[i]);
|
||||
TRACELOG(LOG_TRACE, "DISPLAY: Connector modes detected: %i", con->count_modes);
|
||||
|
||||
if ((con->connection == DRM_MODE_CONNECTED) && (con->encoder_id))
|
||||
// In certain cases the status of the conneciton is reported as UKNOWN, but it is still connected.
|
||||
// This might be a hardware or software limitation like on Raspberry Pi Zero with composite output.
|
||||
if (((con->connection == DRM_MODE_CONNECTED) || (con->connection == DRM_MODE_UNKNOWNCONNECTION)) && (con->encoder_id))
|
||||
{
|
||||
TRACELOG(LOG_TRACE, "DISPLAY: DRM mode connected");
|
||||
platform.connector = con;
|
||||
|
|
|
|||
18
src/raylib.h
18
src/raylib.h
|
|
@ -352,8 +352,10 @@ typedef struct Mesh {
|
|||
// Animation vertex data
|
||||
float *animVertices; // Animated vertex positions (after bones transformations)
|
||||
float *animNormals; // Animated normals (after bones transformations)
|
||||
unsigned char *boneIds; // Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning)
|
||||
float *boneWeights; // Vertex bone weight, up to 4 bones influence by vertex (skinning)
|
||||
unsigned char *boneIds; // Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6)
|
||||
float *boneWeights; // Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7)
|
||||
Matrix *boneMatrices; // Bones animated transformation matrices
|
||||
int boneCount; // Number of bones
|
||||
|
||||
// OpenGL identifiers
|
||||
unsigned int vaoId; // OpenGL Vertex Array Object id
|
||||
|
|
@ -790,7 +792,10 @@ typedef enum {
|
|||
SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
||||
SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
||||
SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
||||
SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
||||
SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf
|
||||
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds
|
||||
SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: boneWeights
|
||||
SHADER_LOC_BONE_MATRICES // Shader location: array of matrices uniform: boneMatrices
|
||||
} ShaderLocationIndex;
|
||||
|
||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
||||
|
|
@ -1122,11 +1127,12 @@ RLAPI const char *GetDirectoryPath(const char *filePath); // Get full pa
|
|||
RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string)
|
||||
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)
|
||||
RLAPI const char *GetApplicationDirectory(void); // Get the directory of the running application (uses static string)
|
||||
RLAPI int MakeDirectory(const char *dirPath); // Create directories (including full path requested), returns 0 on success
|
||||
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success
|
||||
RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory
|
||||
RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS
|
||||
RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths
|
||||
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan
|
||||
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result
|
||||
RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths
|
||||
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
|
||||
RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths
|
||||
|
|
@ -1431,6 +1437,7 @@ RLAPI Color ColorBrightness(Color color, float factor); // G
|
|||
RLAPI Color ColorContrast(Color color, float contrast); // Get color with contrast correction, contrast values between -1.0f and 1.0f
|
||||
RLAPI Color ColorAlpha(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
|
||||
RLAPI Color ColorAlphaBlend(Color dst, Color src, Color tint); // Get src alpha-blended into dst color with tint
|
||||
RLAPI Color ColorLerp(Color color1, Color color2, float factor); // Get color lerp interpolation between two colors, factor [0.0f..1.0f]
|
||||
RLAPI Color GetColor(unsigned int hexValue); // Get Color structure from hexadecimal value
|
||||
RLAPI Color GetPixelColor(void *srcPtr, int format); // Get Color from a source pixel pointer of certain format
|
||||
RLAPI void SetPixelColor(void *dstPtr, Color color, int format); // Set color formatted into destination pixel pointer
|
||||
|
|
@ -1443,7 +1450,7 @@ RLAPI int GetPixelDataSize(int width, int height, int format); // G
|
|||
// Font loading/unloading functions
|
||||
RLAPI Font GetFontDefault(void); // Get the default Font
|
||||
RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM)
|
||||
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set
|
||||
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set, font size is provided in pixels height
|
||||
RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style)
|
||||
RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
|
||||
RLAPI bool IsFontReady(Font font); // Check if a font is ready
|
||||
|
|
@ -1590,6 +1597,7 @@ RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame);
|
|||
RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data
|
||||
RLAPI void UnloadModelAnimations(ModelAnimation *animations, int animCount); // Unload animation array data
|
||||
RLAPI bool IsModelAnimationValid(Model model, ModelAnimation anim); // Check model animation skeleton match
|
||||
RLAPI void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame); // Update model animation mesh bone matrices
|
||||
|
||||
// Collision detection functions
|
||||
RLAPI bool CheckCollisionSpheres(Vector3 center1, float radius1, Vector3 center2, float radius2); // Check collision between two spheres
|
||||
|
|
|
|||
114
src/rcore.c
114
src/rcore.c
|
|
@ -165,6 +165,10 @@ unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
|
|||
unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
|
||||
#elif defined(__linux__)
|
||||
#include <unistd.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <unistd.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <sys/syslimits.h>
|
||||
#include <mach-o/dyld.h>
|
||||
|
|
@ -187,16 +191,29 @@ unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
|
|||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <direct.h> // Required for: _getch(), _chdir()
|
||||
#include <io.h> // Required for: _access() [Used in FileExists()]
|
||||
#include <direct.h> // Required for: _getch(), _chdir(), _mkdir()
|
||||
#define GETCWD _getcwd // NOTE: MSDN recommends not to use getcwd(), chdir()
|
||||
#define CHDIR _chdir
|
||||
#include <io.h> // Required for: _access() [Used in FileExists()]
|
||||
#else
|
||||
#include <unistd.h> // Required for: getch(), chdir() (POSIX), access()
|
||||
#define GETCWD getcwd
|
||||
#define CHDIR chdir
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && ((defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__))
|
||||
#include <direct.h> // Required for: _mkdir()
|
||||
#define MKDIR(dir) _mkdir(dir)
|
||||
#elif defined __GNUC__
|
||||
#if defined(__linux__)
|
||||
#define MKDIR(dir) mkdir(dir, 0777);
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h> // Required for: mkdir()
|
||||
#define MKDIR(dir) _mkdir(dir) // OLD: mkdir(dir, 0777) -> w64devkit complaints!
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -247,6 +264,10 @@ unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
|
|||
#define MAX_AUTOMATION_EVENTS 16384 // Maximum number of automation events to record
|
||||
#endif
|
||||
|
||||
#ifndef DIRECTORY_FILTER_TAG
|
||||
#define DIRECTORY_FILTER_TAG "DIR" // Name tag used to request directory inclusion on directory scan
|
||||
#endif // NOTE: Used in ScanDirectoryFiles(), ScanDirectoryFilesRecursively() and LoadDirectoryFilesEx()
|
||||
|
||||
// Flags operation macros
|
||||
#define FLAG_SET(n, f) ((n) |= (f))
|
||||
#define FLAG_CLEAR(n, f) ((n) &= ~(f))
|
||||
|
|
@ -1295,6 +1316,8 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
// vertex color location = 3
|
||||
// vertex tangent location = 4
|
||||
// vertex texcoord2 location = 5
|
||||
// vertex boneIds location = 6
|
||||
// vertex boneWeights location = 7
|
||||
|
||||
// NOTE: If any location is not found, loc point becomes -1
|
||||
|
||||
|
|
@ -1310,6 +1333,8 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
shader.locs[SHADER_LOC_VERTEX_NORMAL] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_VERTEX_TANGENT] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
shader.locs[SHADER_LOC_VERTEX_BONEIDS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
||||
shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
|
||||
|
||||
// Get handles to GLSL uniform locations (vertex shader)
|
||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||
|
|
@ -1317,6 +1342,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
shader.locs[SHADER_LOC_MATRIX_PROJECTION] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION);
|
||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL);
|
||||
shader.locs[SHADER_LOC_MATRIX_NORMAL] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL);
|
||||
shader.locs[SHADER_LOC_BONE_MATRICES] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_BONE_MATRICES);
|
||||
|
||||
// Get handles to GLSL uniform locations (fragment shader)
|
||||
shader.locs[SHADER_LOC_COLOR_DIFFUSE] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR);
|
||||
|
|
@ -2161,6 +2187,28 @@ const char *GetApplicationDirectory(void)
|
|||
appDir[0] = '.';
|
||||
appDir[1] = '/';
|
||||
}
|
||||
#elif defined(__FreeBSD__)
|
||||
size_t size = sizeof(appDir);
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
||||
|
||||
if (sysctl(mib, 4, appDir, &size, NULL, 0) == 0)
|
||||
{
|
||||
int len = strlen(appDir);
|
||||
for (int i = len; i >= 0; --i)
|
||||
{
|
||||
if (appDir[i] == '/')
|
||||
{
|
||||
appDir[i + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
appDir[0] = '.';
|
||||
appDir[1] = '/';
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return appDir;
|
||||
|
|
@ -2232,6 +2280,40 @@ void UnloadDirectoryFiles(FilePathList files)
|
|||
RL_FREE(files.paths);
|
||||
}
|
||||
|
||||
// Create directories (including full path requested), returns 0 on success
|
||||
int MakeDirectory(const char *dirPath)
|
||||
{
|
||||
if ((dirPath == NULL) || (dirPath[0] == '\0')) return 1; // Path is not valid
|
||||
if (DirectoryExists(dirPath)) return 0; // Path already exists (is valid)
|
||||
|
||||
// Copy path string to avoid modifying original
|
||||
int len = (int)strlen(dirPath) + 1;
|
||||
char *pathcpy = (char *)RL_CALLOC(len, 1);
|
||||
memcpy(pathcpy, dirPath, len);
|
||||
|
||||
// Iterate over pathcpy, create each subdirectory as needed
|
||||
for (int i = 0; (i < len) && (pathcpy[i] != '\0'); i++)
|
||||
{
|
||||
if (pathcpy[i] == ':') i++;
|
||||
else
|
||||
{
|
||||
if ((pathcpy[i] == '\\') || (pathcpy[i] == '/'))
|
||||
{
|
||||
pathcpy[i] = '\0';
|
||||
if (!DirectoryExists(pathcpy)) MKDIR(pathcpy);
|
||||
pathcpy[i] = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create final directory
|
||||
if (!DirectoryExists(pathcpy)) MKDIR(pathcpy);
|
||||
|
||||
RL_FREE(pathcpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Change working directory, returns true on success
|
||||
bool ChangeDirectory(const char *dir)
|
||||
{
|
||||
|
|
@ -3312,6 +3394,8 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const
|
|||
#endif
|
||||
|
||||
if (filter != NULL)
|
||||
{
|
||||
if (IsPathFile(path))
|
||||
{
|
||||
if (IsFileExtension(path, filter))
|
||||
{
|
||||
|
|
@ -3320,6 +3404,15 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TextFindIndex(filter, DIRECTORY_FILTER_TAG) >= 0)
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
|
|
@ -3376,7 +3469,22 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi
|
|||
break;
|
||||
}
|
||||
}
|
||||
else ScanDirectoryFilesRecursively(path, files, filter);
|
||||
else
|
||||
{
|
||||
if ((filter != NULL) && (TextFindIndex(filter, DIRECTORY_FILTER_TAG) >= 0))
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
}
|
||||
|
||||
if (files->count >= files->capacity)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "FILEIO: Maximum filepath scan capacity reached (%i files)", files->capacity);
|
||||
break;
|
||||
}
|
||||
|
||||
ScanDirectoryFilesRecursively(path, files, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
42
src/rlgl.h
42
src/rlgl.h
|
|
@ -68,12 +68,15 @@
|
|||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS "vertexBoneIds" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS
|
||||
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView)))
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_BONE_MATRICES "boneMatrices" // bone matrices
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||
|
|
@ -341,6 +344,15 @@
|
|||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2 5
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 6
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 7
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES 8
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
|
@ -527,6 +539,10 @@ typedef enum {
|
|||
RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int)
|
||||
RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
||||
RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int)
|
||||
RL_SHADER_UNIFORM_UINT, // Shader uniform type: unsigned int
|
||||
RL_SHADER_UNIFORM_UIVEC2, // Shader uniform type: uivec2 (2 unsigned int)
|
||||
RL_SHADER_UNIFORM_UIVEC3, // Shader uniform type: uivec3 (3 unsigned int)
|
||||
RL_SHADER_UNIFORM_UIVEC4, // Shader uniform type: uivec4 (4 unsigned int)
|
||||
RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
||||
} rlShaderUniformDataType;
|
||||
|
||||
|
|
@ -755,6 +771,7 @@ RLAPI int rlGetLocationUniform(unsigned int shaderId, const char *uniformName);
|
|||
RLAPI int rlGetLocationAttrib(unsigned int shaderId, const char *attribName); // Get shader location attribute
|
||||
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
||||
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
|
||||
RLAPI void rlSetUniformMatrices(int locIndex, const Matrix *mat, int count); // Set shader value matrices
|
||||
RLAPI void rlSetUniformSampler(int locIndex, unsigned int textureId); // Set shader value sampler
|
||||
RLAPI void rlSetShader(unsigned int id, int *locs); // Set shader currently active (id and locations)
|
||||
|
||||
|
|
@ -973,6 +990,12 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS "vertexBoneIds" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
||||
#endif
|
||||
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
|
|
@ -992,6 +1015,9 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_BONE_MATRICES
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_BONE_MATRICES "boneMatrices" // bone matrices
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
#endif
|
||||
|
|
@ -4144,6 +4170,8 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
|||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
|
||||
|
||||
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
|
||||
|
||||
|
|
@ -4236,6 +4264,12 @@ void rlSetUniform(int locIndex, const void *value, int uniformType, int count)
|
|||
case RL_SHADER_UNIFORM_IVEC2: glUniform2iv(locIndex, count, (int *)value); break;
|
||||
case RL_SHADER_UNIFORM_IVEC3: glUniform3iv(locIndex, count, (int *)value); break;
|
||||
case RL_SHADER_UNIFORM_IVEC4: glUniform4iv(locIndex, count, (int *)value); break;
|
||||
#if !defined(GRAPHICS_API_OPENGL_ES2)
|
||||
case RL_SHADER_UNIFORM_UINT: glUniform1uiv(locIndex, count, (unsigned int *)value); break;
|
||||
case RL_SHADER_UNIFORM_UIVEC2: glUniform2uiv(locIndex, count, (unsigned int *)value); break;
|
||||
case RL_SHADER_UNIFORM_UIVEC3: glUniform3uiv(locIndex, count, (unsigned int *)value); break;
|
||||
case RL_SHADER_UNIFORM_UIVEC4: glUniform4uiv(locIndex, count, (unsigned int *)value); break;
|
||||
#endif
|
||||
case RL_SHADER_UNIFORM_SAMPLER2D: glUniform1iv(locIndex, count, (int *)value); break;
|
||||
default: TRACELOG(RL_LOG_WARNING, "SHADER: Failed to set uniform value, data type not recognized");
|
||||
|
||||
|
|
@ -4273,6 +4307,14 @@ void rlSetUniformMatrix(int locIndex, Matrix mat)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Set shader value uniform matrix
|
||||
void rlSetUniformMatrices(int locIndex, const Matrix *matrices, int count)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glUniformMatrix4fv(locIndex, count, true, (const float*)matrices);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set shader value uniform sampler
|
||||
void rlSetUniformSampler(int locIndex, unsigned int textureId)
|
||||
{
|
||||
|
|
|
|||
520
src/rmodels.c
520
src/rmodels.c
|
|
@ -130,7 +130,7 @@
|
|||
#define MAX_MATERIAL_MAPS 12 // Maximum number of maps supported
|
||||
#endif
|
||||
#ifndef MAX_MESH_VERTEX_BUFFERS
|
||||
#define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh
|
||||
#define MAX_MESH_VERTEX_BUFFERS 9 // Maximum vertex buffers (VBO) per mesh
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1246,13 +1246,15 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
mesh->vboId = (unsigned int *)RL_CALLOC(MAX_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
mesh->vaoId = 0; // Vertex Array Object
|
||||
mesh->vboId[0] = 0; // Vertex buffer: positions
|
||||
mesh->vboId[1] = 0; // Vertex buffer: texcoords
|
||||
mesh->vboId[2] = 0; // Vertex buffer: normals
|
||||
mesh->vboId[3] = 0; // Vertex buffer: colors
|
||||
mesh->vboId[4] = 0; // Vertex buffer: tangents
|
||||
mesh->vboId[5] = 0; // Vertex buffer: texcoords2
|
||||
mesh->vboId[6] = 0; // Vertex buffer: indices
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION] = 0; // Vertex buffer: positions
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = 0; // Vertex buffer: texcoords
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL] = 0; // Vertex buffer: normals
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR] = 0; // Vertex buffer: colors
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT] = 0; // Vertex buffer: tangents
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2] = 0; // Vertex buffer: texcoords2
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS] = 0; // Vertex buffer: boneIds
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS] = 0; // Vertex buffer: boneWeights
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES] = 0; // Vertex buffer: indices
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
mesh->vaoId = rlLoadVertexArray();
|
||||
|
|
@ -1262,12 +1264,12 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
|
||||
// Enable vertex attributes: position (shader-location = 0)
|
||||
void *vertices = (mesh->animVertices != NULL)? mesh->animVertices : mesh->vertices;
|
||||
mesh->vboId[0] = rlLoadVertexBuffer(vertices, mesh->vertexCount*3*sizeof(float), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION] = rlLoadVertexBuffer(vertices, mesh->vertexCount*3*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION, 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION);
|
||||
|
||||
// Enable vertex attributes: texcoords (shader-location = 1)
|
||||
mesh->vboId[1] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD] = rlLoadVertexBuffer(mesh->texcoords, mesh->vertexCount*2*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD, 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD);
|
||||
|
||||
|
|
@ -1278,7 +1280,7 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
{
|
||||
// Enable vertex attributes: normals (shader-location = 2)
|
||||
void *normals = (mesh->animNormals != NULL)? mesh->animNormals : mesh->normals;
|
||||
mesh->vboId[2] = rlLoadVertexBuffer(normals, mesh->vertexCount*3*sizeof(float), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL] = rlLoadVertexBuffer(normals, mesh->vertexCount*3*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL, 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL);
|
||||
}
|
||||
|
|
@ -1294,7 +1296,7 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
if (mesh->colors != NULL)
|
||||
{
|
||||
// Enable vertex attribute: color (shader-location = 3)
|
||||
mesh->vboId[3] = rlLoadVertexBuffer(mesh->colors, mesh->vertexCount*4*sizeof(unsigned char), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR] = rlLoadVertexBuffer(mesh->colors, mesh->vertexCount*4*sizeof(unsigned char), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, 4, RL_UNSIGNED_BYTE, 1, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR);
|
||||
}
|
||||
|
|
@ -1310,7 +1312,7 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
if (mesh->tangents != NULL)
|
||||
{
|
||||
// Enable vertex attribute: tangent (shader-location = 4)
|
||||
mesh->vboId[4] = rlLoadVertexBuffer(mesh->tangents, mesh->vertexCount*4*sizeof(float), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT] = rlLoadVertexBuffer(mesh->tangents, mesh->vertexCount*4*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT);
|
||||
}
|
||||
|
|
@ -1326,7 +1328,7 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
if (mesh->texcoords2 != NULL)
|
||||
{
|
||||
// Enable vertex attribute: texcoord2 (shader-location = 5)
|
||||
mesh->vboId[5] = rlLoadVertexBuffer(mesh->texcoords2, mesh->vertexCount*2*sizeof(float), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2] = rlLoadVertexBuffer(mesh->texcoords2, mesh->vertexCount*2*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2);
|
||||
}
|
||||
|
|
@ -1339,9 +1341,41 @@ void UploadMesh(Mesh *mesh, bool dynamic)
|
|||
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2);
|
||||
}
|
||||
|
||||
if (mesh->boneIds != NULL)
|
||||
{
|
||||
// Enable vertex attribute: boneIds (shader-location = 6)
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS] = rlLoadVertexBuffer(mesh->boneIds, mesh->vertexCount*4*sizeof(unsigned char), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, 4, RL_UNSIGNED_BYTE, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default vertex attribute: boneIds
|
||||
// WARNING: Default value provided to shader if location available
|
||||
float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, value, SHADER_ATTRIB_VEC4, 4);
|
||||
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS);
|
||||
}
|
||||
|
||||
if (mesh->boneWeights != NULL)
|
||||
{
|
||||
// Enable vertex attribute: boneWeights (shader-location = 7)
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS] = rlLoadVertexBuffer(mesh->boneWeights, mesh->vertexCount*4*sizeof(float), dynamic);
|
||||
rlSetVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default vertex attribute: boneWeights
|
||||
// WARNING: Default value provided to shader if location available
|
||||
float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
rlSetVertexAttributeDefault(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS, value, SHADER_ATTRIB_VEC4, 2);
|
||||
rlDisableVertexAttribute(RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS);
|
||||
}
|
||||
|
||||
if (mesh->indices != NULL)
|
||||
{
|
||||
mesh->vboId[6] = rlLoadVertexBufferElement(mesh->indices, mesh->triangleCount*3*sizeof(unsigned short), dynamic);
|
||||
mesh->vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES] = rlLoadVertexBufferElement(mesh->indices, mesh->triangleCount*3*sizeof(unsigned short), dynamic);
|
||||
}
|
||||
|
||||
if (mesh->vaoId > 0) TRACELOG(LOG_INFO, "VAO: [ID %i] Mesh uploaded successfully to VRAM (GPU)", mesh->vaoId);
|
||||
|
|
@ -1451,6 +1485,13 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
|
||||
// Upload model normal matrix (if locations available)
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], MatrixTranspose(MatrixInvert(matModel)));
|
||||
|
||||
// Upload Bone Transforms
|
||||
if (material.shader.locs[SHADER_LOC_BONE_MATRICES] != -1 && mesh.boneMatrices)
|
||||
{
|
||||
rlSetUniformMatrices(material.shader.locs[SHADER_LOC_BONE_MATRICES], mesh.boneMatrices, mesh.boneCount);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
// Bind active texture maps (if available)
|
||||
|
|
@ -1478,19 +1519,19 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
if (!rlEnableVertexArray(mesh.vaoId))
|
||||
{
|
||||
// Bind mesh VBO data: vertex position (shader-location = 0)
|
||||
rlEnableVertexBuffer(mesh.vboId[0]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_POSITION], 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_POSITION]);
|
||||
|
||||
// Bind mesh VBO data: vertex texcoords (shader-location = 1)
|
||||
rlEnableVertexBuffer(mesh.vboId[1]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD01], 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_NORMAL] != -1)
|
||||
{
|
||||
// Bind mesh VBO data: vertex normals (shader-location = 2)
|
||||
rlEnableVertexBuffer(mesh.vboId[2]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_NORMAL], 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_NORMAL]);
|
||||
}
|
||||
|
|
@ -1498,9 +1539,9 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
// Bind mesh VBO data: vertex colors (shader-location = 3, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_COLOR] != -1)
|
||||
{
|
||||
if (mesh.vboId[3] != 0)
|
||||
if (mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR] != 0)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[3]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_COLOR], 4, RL_UNSIGNED_BYTE, 1, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_COLOR]);
|
||||
}
|
||||
|
|
@ -1517,7 +1558,7 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
// Bind mesh VBO data: vertex tangents (shader-location = 4, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_TANGENT] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[4]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TANGENT], 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TANGENT]);
|
||||
}
|
||||
|
|
@ -1525,12 +1566,28 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||
// Bind mesh VBO data: vertex texcoords2 (shader-location = 5, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[5]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02], 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02]);
|
||||
}
|
||||
|
||||
if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[6]);
|
||||
// Bind mesh VBO data: vertex bone ids (shader-location = 6, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_BONEIDS] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEIDS], 4, RL_UNSIGNED_BYTE, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEIDS]);
|
||||
}
|
||||
|
||||
// Bind mesh VBO data: vertex bone weights (shader-location = 7, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS], 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS]);
|
||||
}
|
||||
|
||||
if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES]);
|
||||
}
|
||||
|
||||
int eyeCount = 1;
|
||||
|
|
@ -1671,6 +1728,13 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
|
||||
// Upload model normal matrix (if locations available)
|
||||
if (material.shader.locs[SHADER_LOC_MATRIX_NORMAL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_NORMAL], MatrixTranspose(MatrixInvert(matModel)));
|
||||
|
||||
// Upload Bone Transforms
|
||||
if (material.shader.locs[SHADER_LOC_BONE_MATRICES] != -1 && mesh.boneMatrices)
|
||||
{
|
||||
rlSetUniformMatrices(material.shader.locs[SHADER_LOC_BONE_MATRICES], mesh.boneMatrices, mesh.boneCount);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
||||
// Bind active texture maps (if available)
|
||||
|
|
@ -1696,19 +1760,19 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
if (!rlEnableVertexArray(mesh.vaoId))
|
||||
{
|
||||
// Bind mesh VBO data: vertex position (shader-location = 0)
|
||||
rlEnableVertexBuffer(mesh.vboId[0]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_POSITION]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_POSITION], 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_POSITION]);
|
||||
|
||||
// Bind mesh VBO data: vertex texcoords (shader-location = 1)
|
||||
rlEnableVertexBuffer(mesh.vboId[1]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD01], 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD01]);
|
||||
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_NORMAL] != -1)
|
||||
{
|
||||
// Bind mesh VBO data: vertex normals (shader-location = 2)
|
||||
rlEnableVertexBuffer(mesh.vboId[2]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_NORMAL]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_NORMAL], 3, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_NORMAL]);
|
||||
}
|
||||
|
|
@ -1716,9 +1780,9 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
// Bind mesh VBO data: vertex colors (shader-location = 3, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_COLOR] != -1)
|
||||
{
|
||||
if (mesh.vboId[3] != 0)
|
||||
if (mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR] != 0)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[3]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_COLOR], 4, RL_UNSIGNED_BYTE, 1, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_COLOR]);
|
||||
}
|
||||
|
|
@ -1735,7 +1799,7 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
// Bind mesh VBO data: vertex tangents (shader-location = 4, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_TANGENT] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[4]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TANGENT], 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TANGENT]);
|
||||
}
|
||||
|
|
@ -1743,12 +1807,28 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
// Bind mesh VBO data: vertex texcoords2 (shader-location = 5, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[5]);
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02], 2, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_TEXCOORD02]);
|
||||
}
|
||||
|
||||
if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[6]);
|
||||
// Bind mesh VBO data: vertex bone ids (shader-location = 6, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_BONEIDS] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEIDS], 4, RL_UNSIGNED_BYTE, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEIDS]);
|
||||
}
|
||||
|
||||
// Bind mesh VBO data: vertex bone weights (shader-location = 7, if available)
|
||||
if (material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] != -1)
|
||||
{
|
||||
rlEnableVertexBuffer(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS]);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS], 4, RL_FLOAT, 0, 0, 0);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS]);
|
||||
}
|
||||
|
||||
if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[RL_DEFAULT_SHADER_ATTRIB_LOCATION_INDICES]);
|
||||
}
|
||||
|
||||
int eyeCount = 1;
|
||||
|
|
@ -1825,6 +1905,7 @@ void UnloadMesh(Mesh mesh)
|
|||
RL_FREE(mesh.animNormals);
|
||||
RL_FREE(mesh.boneWeights);
|
||||
RL_FREE(mesh.boneIds);
|
||||
RL_FREE(mesh.boneMatrices);
|
||||
}
|
||||
|
||||
// Export mesh data to file
|
||||
|
|
@ -2016,6 +2097,8 @@ static void ProcessMaterialsOBJ(Material *materials, tinyobj_material_t *mats, i
|
|||
// NOTE: Uses default shader, which only supports MATERIAL_MAP_DIFFUSE
|
||||
materials[m] = LoadMaterialDefault();
|
||||
|
||||
if (mats == NULL) continue;
|
||||
|
||||
// Get default texture, in case no texture is defined
|
||||
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
||||
materials[m].maps[MATERIAL_MAP_DIFFUSE].texture = (Texture2D){ rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
||||
|
|
@ -2253,6 +2336,50 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateModelAnimationBoneMatrices(Model model, ModelAnimation anim, int frame)
|
||||
{
|
||||
if ((anim.frameCount > 0) && (anim.bones != NULL) && (anim.framePoses != NULL))
|
||||
{
|
||||
if (frame >= anim.frameCount) frame = frame%anim.frameCount;
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
{
|
||||
if (model.meshes[i].boneMatrices)
|
||||
{
|
||||
assert(model.meshes[i].boneCount == anim.boneCount);
|
||||
|
||||
for (int boneId = 0; boneId < model.meshes[i].boneCount; boneId++)
|
||||
{
|
||||
Vector3 inTranslation = model.bindPose[boneId].translation;
|
||||
Quaternion inRotation = model.bindPose[boneId].rotation;
|
||||
Vector3 inScale = model.bindPose[boneId].scale;
|
||||
|
||||
Vector3 outTranslation = anim.framePoses[frame][boneId].translation;
|
||||
Quaternion outRotation = anim.framePoses[frame][boneId].rotation;
|
||||
Vector3 outScale = anim.framePoses[frame][boneId].scale;
|
||||
|
||||
Vector3 invTranslation = Vector3RotateByQuaternion(Vector3Negate(inTranslation), QuaternionInvert(inRotation));
|
||||
Quaternion invRotation = QuaternionInvert(inRotation);
|
||||
Vector3 invScale = Vector3Divide((Vector3){ 1.0f, 1.0f, 1.0f }, inScale);
|
||||
|
||||
Vector3 boneTranslation = Vector3Add(
|
||||
Vector3RotateByQuaternion(Vector3Multiply(outScale, invTranslation),
|
||||
outRotation), outTranslation);
|
||||
Quaternion boneRotation = QuaternionMultiply(outRotation, invRotation);
|
||||
Vector3 boneScale = Vector3Multiply(outScale, invScale);
|
||||
|
||||
Matrix boneMatrix = MatrixMultiply(MatrixMultiply(
|
||||
QuaternionToMatrix(boneRotation),
|
||||
MatrixTranslate(boneTranslation.x, boneTranslation.y, boneTranslation.z)),
|
||||
MatrixScale(boneScale.x, boneScale.y, boneScale.z));
|
||||
|
||||
model.meshes[i].boneMatrices[boneId] = boneMatrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unload animation array data
|
||||
void UnloadModelAnimations(ModelAnimation *animations, int animCount)
|
||||
{
|
||||
|
|
@ -4073,20 +4200,23 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform
|
|||
// - the mesh is automatically triangulated by tinyobj
|
||||
static Model LoadOBJ(const char *fileName)
|
||||
{
|
||||
tinyobj_attrib_t objAttributes = { 0 };
|
||||
tinyobj_shape_t* objShapes = NULL;
|
||||
unsigned int objShapeCount = 0;
|
||||
|
||||
tinyobj_material_t* objMaterials = NULL;
|
||||
unsigned int objMaterialCount = 0;
|
||||
|
||||
Model model = { 0 };
|
||||
|
||||
tinyobj_attrib_t attrib = { 0 };
|
||||
tinyobj_shape_t *meshes = NULL;
|
||||
unsigned int meshCount = 0;
|
||||
|
||||
tinyobj_material_t *materials = NULL;
|
||||
unsigned int materialCount = 0;
|
||||
model.transform = MatrixIdentity();
|
||||
|
||||
char* fileText = LoadFileText(fileName);
|
||||
|
||||
if (fileText != NULL)
|
||||
if (fileText == NULL)
|
||||
{
|
||||
unsigned int dataSize = (unsigned int)strlen(fileText);
|
||||
TRACELOG(LOG_ERROR, "MODEL Unable to read obj file %s", fileName);
|
||||
return model;
|
||||
}
|
||||
|
||||
char currentDir[1024] = { 0 };
|
||||
strcpy(currentDir, GetWorkingDirectory()); // Save current working directory
|
||||
|
|
@ -4096,108 +4226,211 @@ static Model LoadOBJ(const char *fileName)
|
|||
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
||||
}
|
||||
|
||||
unsigned int dataSize = (unsigned int)strlen(fileText);
|
||||
|
||||
unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
|
||||
int ret = tinyobj_parse_obj(&attrib, &meshes, &meshCount, &materials, &materialCount, fileText, dataSize, flags);
|
||||
int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
|
||||
|
||||
if (ret != TINYOBJ_SUCCESS) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load OBJ data", fileName);
|
||||
else TRACELOG(LOG_INFO, "MODEL: [%s] OBJ data loaded successfully: %i meshes/%i materials", fileName, meshCount, materialCount);
|
||||
|
||||
// WARNING: We are not splitting meshes by materials (previous implementation)
|
||||
// Depending on the provided OBJ that was not the best option and it just crashed
|
||||
// so, implementation was simplified to prioritize parsed meshes
|
||||
model.meshCount = meshCount;
|
||||
|
||||
// Set number of materials available
|
||||
// NOTE: There could be more materials available than meshes but it will be resolved at
|
||||
// model.meshMaterial, just assigning the right material to corresponding mesh
|
||||
model.materialCount = materialCount;
|
||||
if (model.materialCount == 0)
|
||||
if (ret != TINYOBJ_SUCCESS)
|
||||
{
|
||||
model.materialCount = 1;
|
||||
TRACELOG(LOG_INFO, "MODEL: No materials provided, setting one default material for all meshes");
|
||||
TRACELOG(LOG_ERROR, "MODEL Unable to read obj data %s", fileName);
|
||||
return model;
|
||||
}
|
||||
else if (model.materialCount > 1 && model.meshCount > 1)
|
||||
{
|
||||
// TEMP warning about multiple materials, to be removed when proper splitting code is implemented
|
||||
// any obj with multiple materials will need to have it's materials assigned by the user in code to work at this time
|
||||
TRACELOG(LOG_INFO, "MODEL: OBJ has multiple materials, manual material assignment will be required.");
|
||||
}
|
||||
|
||||
// Init model meshes and materials
|
||||
model.meshes = (Mesh *)RL_CALLOC(model.meshCount, sizeof(Mesh));
|
||||
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); // Material index assigned to each mesh
|
||||
model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material));
|
||||
|
||||
// Process each provided mesh
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
{
|
||||
// WARNING: We need to calculate the mesh triangles manually using meshes[i].face_offset
|
||||
// because in case of triangulated quads, meshes[i].length actually report quads,
|
||||
// despite the triangulation that is efectively considered on attrib.num_faces
|
||||
unsigned int tris = 0;
|
||||
if (i == model.meshCount - 1) tris = attrib.num_faces - meshes[i].face_offset;
|
||||
else tris = meshes[i + 1].face_offset;
|
||||
|
||||
model.meshes[i].vertexCount = tris*3;
|
||||
model.meshes[i].triangleCount = tris; // Face count (triangulated)
|
||||
model.meshes[i].vertices = (float *)RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
|
||||
model.meshes[i].texcoords = (float *)RL_CALLOC(model.meshes[i].vertexCount*2, sizeof(float));
|
||||
model.meshes[i].normals = (float *)RL_CALLOC(model.meshes[i].vertexCount*3, sizeof(float));
|
||||
model.meshMaterial[i] = 0; // By default, assign material 0 to each mesh
|
||||
|
||||
// Process all mesh faces
|
||||
for (unsigned int face = 0, f = meshes[i].face_offset, v = 0, vt = 0, vn = 0; face < tris; face++, f++, v += 3, vt += 3, vn += 3)
|
||||
{
|
||||
// Get indices for the face
|
||||
tinyobj_vertex_index_t idx0 = attrib.faces[f*3 + 0];
|
||||
tinyobj_vertex_index_t idx1 = attrib.faces[f*3 + 1];
|
||||
tinyobj_vertex_index_t idx2 = attrib.faces[f*3 + 2];
|
||||
|
||||
// Fill vertices buffer (float) using vertex index of the face
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].vertices[v*3 + n] = attrib.vertices[idx0.v_idx*3 + n]; }
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].vertices[(v + 1)*3 + n] = attrib.vertices[idx1.v_idx*3 + n]; }
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].vertices[(v + 2)*3 + n] = attrib.vertices[idx2.v_idx*3 + n]; }
|
||||
|
||||
if (attrib.num_texcoords > 0)
|
||||
{
|
||||
// Fill texcoords buffer (float) using vertex index of the face
|
||||
// NOTE: Y-coordinate must be flipped upside-down
|
||||
model.meshes[i].texcoords[vt*2 + 0] = attrib.texcoords[idx0.vt_idx*2 + 0];
|
||||
model.meshes[i].texcoords[vt*2 + 1] = 1.0f - attrib.texcoords[idx0.vt_idx*2 + 1];
|
||||
|
||||
model.meshes[i].texcoords[(vt + 1)*2 + 0] = attrib.texcoords[idx1.vt_idx*2 + 0];
|
||||
model.meshes[i].texcoords[(vt + 1)*2 + 1] = 1.0f - attrib.texcoords[idx1.vt_idx*2 + 1];
|
||||
|
||||
model.meshes[i].texcoords[(vt + 2)*2 + 0] = attrib.texcoords[idx2.vt_idx*2 + 0];
|
||||
model.meshes[i].texcoords[(vt + 2)*2 + 1] = 1.0f - attrib.texcoords[idx2.vt_idx*2 + 1];
|
||||
}
|
||||
|
||||
if (attrib.num_normals > 0)
|
||||
{
|
||||
// Fill normals buffer (float) using vertex index of the face
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].normals[vn*3 + n] = attrib.normals[idx0.vn_idx*3 + n]; }
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].normals[(vn + 1)*3 + n] = attrib.normals[idx1.vn_idx*3 + n]; }
|
||||
for (int n = 0; n < 3; n++) { model.meshes[i].normals[(vn + 2)*3 + n] = attrib.normals[idx2.vn_idx*3 + n]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Init model materials
|
||||
if (materialCount > 0) ProcessMaterialsOBJ(model.materials, materials, materialCount);
|
||||
else model.materials[0] = LoadMaterialDefault(); // Set default material for the mesh
|
||||
|
||||
tinyobj_attrib_free(&attrib);
|
||||
tinyobj_shapes_free(meshes, model.meshCount);
|
||||
tinyobj_materials_free(materials, materialCount);
|
||||
|
||||
UnloadFileText(fileText);
|
||||
|
||||
unsigned int faceVertIndex = 0;
|
||||
unsigned int nextShape = 1;
|
||||
int lastMaterial = -1;
|
||||
unsigned int meshIndex = 0;
|
||||
|
||||
// count meshes
|
||||
unsigned int nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
|
||||
// see how many verts till the next shape
|
||||
|
||||
if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
|
||||
// walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
if (faceVertIndex >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
meshIndex++;
|
||||
}
|
||||
else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
|
||||
{
|
||||
meshIndex++;// if this is a new material, we need to allocate a new mesh
|
||||
}
|
||||
|
||||
lastMaterial = objAttributes.material_ids[faceId];
|
||||
faceVertIndex += objAttributes.face_num_verts[faceId];
|
||||
}
|
||||
|
||||
// allocate the base meshes and materials
|
||||
model.meshCount = meshIndex + 1;
|
||||
model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount);
|
||||
|
||||
if (objMaterialCount > 0)
|
||||
{
|
||||
model.materialCount = objMaterialCount;
|
||||
model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount);
|
||||
}
|
||||
else // we must allocate at least one material
|
||||
{
|
||||
model.materialCount = 1;
|
||||
model.materials = (Material*)MemAlloc(sizeof(Material) * 1);
|
||||
}
|
||||
|
||||
model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount);
|
||||
|
||||
// see how many verts are in each mesh
|
||||
unsigned int* localMeshVertexCounts = (unsigned int*)MemAlloc(sizeof(unsigned int) * model.meshCount);
|
||||
|
||||
faceVertIndex = 0;
|
||||
nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
lastMaterial = -1;
|
||||
meshIndex = 0;
|
||||
unsigned int localMeshVertexCount = 0;
|
||||
|
||||
nextShape = 1;
|
||||
if (objShapeCount > 1)
|
||||
nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
|
||||
// walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
bool newMesh = false; // do we need a new mesh?
|
||||
if (faceVertIndex >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
|
||||
newMesh = true;
|
||||
}
|
||||
else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
|
||||
{
|
||||
newMesh = true;
|
||||
}
|
||||
|
||||
lastMaterial = objAttributes.material_ids[faceId];
|
||||
|
||||
if (newMesh)
|
||||
{
|
||||
localMeshVertexCounts[meshIndex] = localMeshVertexCount;
|
||||
|
||||
localMeshVertexCount = 0;
|
||||
meshIndex++;
|
||||
}
|
||||
|
||||
faceVertIndex += objAttributes.face_num_verts[faceId];
|
||||
localMeshVertexCount += objAttributes.face_num_verts[faceId];
|
||||
}
|
||||
localMeshVertexCounts[meshIndex] = localMeshVertexCount;
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
{
|
||||
// allocate the buffers for each mesh
|
||||
unsigned int vertexCount = localMeshVertexCounts[i];
|
||||
|
||||
model.meshes[i].vertexCount = vertexCount;
|
||||
model.meshes[i].triangleCount = vertexCount / 3;
|
||||
|
||||
model.meshes[i].vertices = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
|
||||
model.meshes[i].normals = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
|
||||
model.meshes[i].texcoords = (float*)MemAlloc(sizeof(float) * vertexCount * 2);
|
||||
model.meshes[i].colors = (unsigned char*)MemAlloc(sizeof(unsigned char) * vertexCount * 4);
|
||||
}
|
||||
|
||||
MemFree(localMeshVertexCounts);
|
||||
localMeshVertexCounts = NULL;
|
||||
|
||||
// fill meshes
|
||||
faceVertIndex = 0;
|
||||
|
||||
nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
|
||||
// see how many verts till the next shape
|
||||
nextShape = 1;
|
||||
if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
lastMaterial = -1;
|
||||
meshIndex = 0;
|
||||
localMeshVertexCount = 0;
|
||||
|
||||
// walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
bool newMesh = false; // do we need a new mesh?
|
||||
if (faceVertIndex >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
newMesh = true;
|
||||
}
|
||||
// if this is a new material, we need to allocate a new mesh
|
||||
if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) newMesh = true;
|
||||
lastMaterial = objAttributes.material_ids[faceId];
|
||||
|
||||
if (newMesh)
|
||||
{
|
||||
localMeshVertexCount = 0;
|
||||
meshIndex++;
|
||||
}
|
||||
|
||||
int matId = 0;
|
||||
if (lastMaterial >= 0 && lastMaterial < (int)objMaterialCount)
|
||||
matId = lastMaterial;
|
||||
|
||||
model.meshMaterial[meshIndex] = matId;
|
||||
|
||||
for (int f = 0; f < objAttributes.face_num_verts[faceId]; f++)
|
||||
{
|
||||
int vertIndex = objAttributes.faces[faceVertIndex].v_idx;
|
||||
int normalIndex = objAttributes.faces[faceVertIndex].vn_idx;
|
||||
int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
model.meshes[meshIndex].normals[localMeshVertexCount * 3 + i] = objAttributes.normals[normalIndex * 3 + i];
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + i] = objAttributes.texcoords[texcordIndex * 2 + i];
|
||||
|
||||
model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
model.meshes[meshIndex].colors[localMeshVertexCount * 4 + i] = 255;
|
||||
|
||||
faceVertIndex++;
|
||||
localMeshVertexCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (objMaterialCount > 0) ProcessMaterialsOBJ(model.materials, objMaterials, objMaterialCount);
|
||||
else model.materials[0] = LoadMaterialDefault(); // Set default material for the mesh
|
||||
|
||||
tinyobj_attrib_free(&objAttributes);
|
||||
tinyobj_shapes_free(objShapes, objShapeCount);
|
||||
tinyobj_materials_free(objMaterials, objMaterialCount);
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
UploadMesh(model.meshes + i, true);
|
||||
|
||||
// Restore current working directory
|
||||
if (CHDIR(currentDir) != 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", currentDir);
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
@ -4564,6 +4797,17 @@ static Model LoadIQM(const char *fileName)
|
|||
|
||||
BuildPoseFromParentJoints(model.bones, model.boneCount, model.bindPose);
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
{
|
||||
model.meshes[i].boneCount = model.boneCount;
|
||||
model.meshes[i].boneMatrices = RL_CALLOC(model.meshes[i].boneCount, sizeof(Matrix));
|
||||
|
||||
for (int j = 0; j < model.meshes[i].boneCount; j++)
|
||||
{
|
||||
model.meshes[i].boneMatrices[j] = MatrixIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
UnloadFileData(fileData);
|
||||
|
||||
RL_FREE(imesh);
|
||||
|
|
@ -5647,6 +5891,15 @@ static Model LoadGLTF(const char *fileName)
|
|||
memcpy(model.meshes[meshIndex].animNormals, model.meshes[meshIndex].normals, model.meshes[meshIndex].vertexCount*3*sizeof(float));
|
||||
}
|
||||
|
||||
// Bone Transform Matrices
|
||||
model.meshes[meshIndex].boneCount = model.boneCount;
|
||||
model.meshes[meshIndex].boneMatrices = RL_CALLOC(model.meshes[meshIndex].boneCount, sizeof(Matrix));
|
||||
|
||||
for (int j = 0; j < model.meshes[meshIndex].boneCount; j++)
|
||||
{
|
||||
model.meshes[meshIndex].boneMatrices[j] = MatrixIdentity();
|
||||
}
|
||||
|
||||
meshIndex++; // Move to next mesh
|
||||
}
|
||||
|
||||
|
|
@ -6414,6 +6667,13 @@ static Model LoadM3D(const char *fileName)
|
|||
{
|
||||
memcpy(model.meshes[i].animVertices, model.meshes[i].vertices, model.meshes[i].vertexCount*3*sizeof(float));
|
||||
memcpy(model.meshes[i].animNormals, model.meshes[i].normals, model.meshes[i].vertexCount*3*sizeof(float));
|
||||
|
||||
model.meshes[i].boneCount = model.boneCount;
|
||||
model.meshes[i].boneMatrices = RL_CALLOC(model.meshes[i].boneCount, sizeof(Matrix));
|
||||
for (j = 0; j < model.meshes[i].boneCount; j++)
|
||||
{
|
||||
model.meshes[i].boneMatrices[j] = MatrixIdentity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -260,8 +260,8 @@ extern void LoadFontDefault(void)
|
|||
|
||||
// Allocate space for our characters info data
|
||||
// NOTE: This memory must be freed at end! --> Done by CloseWindow()
|
||||
defaultFont.glyphs = (GlyphInfo *)RL_MALLOC(defaultFont.glyphCount*sizeof(GlyphInfo));
|
||||
defaultFont.recs = (Rectangle *)RL_MALLOC(defaultFont.glyphCount*sizeof(Rectangle));
|
||||
defaultFont.glyphs = (GlyphInfo *)RL_CALLOC(defaultFont.glyphCount, sizeof(GlyphInfo));
|
||||
defaultFont.recs = (Rectangle *)RL_CALLOC(defaultFont.glyphCount, sizeof(Rectangle));
|
||||
|
||||
int currentLine = 0;
|
||||
int currentPosX = charsDivisor;
|
||||
|
|
@ -678,6 +678,8 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
|
|||
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
|
||||
chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
|
||||
|
||||
if (chh > fontSize) TRACELOG(LOG_WARNING, "FONT: Character [0x%08x] size is bigger than expected font size", ch);
|
||||
|
||||
// Load characters images
|
||||
chars[i].image.width = chw;
|
||||
chars[i].image.height = chh;
|
||||
|
|
|
|||
|
|
@ -4566,6 +4566,9 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2
|
|||
if (source.width < 0) { flipX = true; source.width *= -1; }
|
||||
if (source.height < 0) source.y -= source.height;
|
||||
|
||||
if (dest.width < 0) dest.width *= -1;
|
||||
if (dest.height < 0) dest.height *= -1;
|
||||
|
||||
Vector2 topLeft = { 0 };
|
||||
Vector2 topRight = { 0 };
|
||||
Vector2 bottomLeft = { 0 };
|
||||
|
|
@ -4985,6 +4988,8 @@ Vector3 ColorToHSV(Color color)
|
|||
return hsv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get a Color from HSV values
|
||||
// Implementation reference: https://en.wikipedia.org/wiki/HSL_and_HSV#Alternative_HSV_conversion
|
||||
// NOTE: Color->HSV->Color conversion will not yield exactly the same color due to rounding errors
|
||||
|
|
@ -5183,6 +5188,22 @@ Color ColorAlphaBlend(Color dst, Color src, Color tint)
|
|||
return out;
|
||||
}
|
||||
|
||||
// Get color lerp interpolation between two colors, factor [0.0f..1.0f]
|
||||
Color ColorLerp(Color color1, Color color2, float factor)
|
||||
{
|
||||
Color color = { 0 };
|
||||
|
||||
if (factor < 0.0f) factor = 0.0f;
|
||||
else if (factor > 1.0f) factor = 1.0f;
|
||||
|
||||
color.r = (unsigned char)((1.0f - factor)*color1.r + factor*color2.r);
|
||||
color.g = (unsigned char)((1.0f - factor)*color1.g + factor*color2.g);
|
||||
color.b = (unsigned char)((1.0f - factor)*color1.b + factor*color2.b);
|
||||
color.a = (unsigned char)((1.0f - factor)*color1.a + factor*color2.a);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// Get a Color struct from hexadecimal value
|
||||
Color GetColor(unsigned int hexValue)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user