@lampdotdev/lamp 0.0.0-stage → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +357 -2
- package/Resources/Devices/roku.json +410 -0
- package/Resources/Devices/xbox-one.json +367 -0
- package/Resources/GameKit/NOTICE.md +63 -0
- package/Resources/GameKit/apple/LampPage.swift +1646 -0
- package/Resources/GameKit/apple/LampPlayer.swift +46 -0
- package/Resources/GameKit/apple/LampWebApp.swift +63 -0
- package/Resources/GameKit/apple/LampWebGame.swift +87 -0
- package/Resources/GameKit/apple/Native.swift +12 -0
- package/Resources/GameKit/build.sh +55 -0
- package/Resources/GameKit/lamp_game.h +116 -0
- package/Resources/GameKit/lamp_host.h +19 -0
- package/Resources/GameKit/lamp_kit.cpp +61 -0
- package/Resources/GameKit/lamp_sound.cpp +455 -0
- package/Resources/GameKit/lamp_xbox.cpp +374 -0
- package/Resources/GameKit/libraries/HandmadeMath.h +3940 -0
- package/Resources/GameKit/libraries/cgltf.h +7240 -0
- package/Resources/GameKit/libraries/dr_mp3.h +5430 -0
- package/Resources/GameKit/libraries/dr_wav.h +9209 -0
- package/Resources/GameKit/libraries/sokol_debugtext.h +4754 -0
- package/Resources/GameKit/libraries/sokol_gfx.h +29558 -0
- package/Resources/GameKit/libraries/sokol_gl.h +4538 -0
- package/Resources/GameKit/libraries/sokol_log.h +335 -0
- package/Resources/GameKit/libraries/sokol_shape.h +1531 -0
- package/Resources/GameKit/libraries/stb_image.h +7988 -0
- package/Resources/GameKit/libraries/stb_vorbis.c +5584 -0
- package/Resources/GameKit/scaffold/Game/game.cpp +142 -0
- package/Resources/GameKit/scaffold/Game/scene.glsl +49 -0
- package/Resources/GameKit/scaffold-web/Web/game.js +31 -0
- package/Resources/GameKit/scaffold-web/Web/index.html +13 -0
- package/Resources/GameKit/scaffold-web/Web/making.js +33 -0
- package/Resources/GameKit/scaffold-web/Web/world.js +33 -0
- package/Resources/GameKit/web/lamp-game.js +3036 -0
- package/Resources/GameKit/web/lamp-phaser.js +128 -0
- package/Resources/WebHost/App.exe +0 -0
- package/Resources/WebHost/Microsoft.Web.WebView2.Core.dll +0 -0
- package/Resources/WebHost/WebView2-LICENSE.txt +27 -0
- package/Resources/WebHost/lamp_controllers.h +1506 -0
- package/Resources/WebHost/lamp_web_host.cpp +1173 -0
- package/Resources/WebLibraries/earlier.txt +318 -0
- package/Resources/WebLibraries/phaser/LICENSE.md +20 -0
- package/Resources/WebLibraries/phaser/NOTICE.md +2 -0
- package/Resources/WebLibraries/phaser/phaser.esm.min.js +1 -0
- package/Resources/WebLibraries/qrcode/LICENSE +21 -0
- package/Resources/WebLibraries/qrcode/NOTICE.md +4 -0
- package/Resources/WebLibraries/qrcode/qrcode.js +2297 -0
- package/Resources/WebLibraries/rapier/LICENSE +201 -0
- package/Resources/WebLibraries/rapier/NOTICE.md +3 -0
- package/Resources/WebLibraries/rapier/rapier.js +2 -0
- package/Resources/WebLibraries/three/LICENSE +21 -0
- package/Resources/WebLibraries/three/NOTICE.md +4 -0
- package/Resources/WebLibraries/three/addons/animation/AnimationClipCreator.js +168 -0
- package/Resources/WebLibraries/three/addons/animation/CCDIKSolver.js +607 -0
- package/Resources/WebLibraries/three/addons/controls/ArcballControls.js +3543 -0
- package/Resources/WebLibraries/three/addons/controls/DragControls.js +452 -0
- package/Resources/WebLibraries/three/addons/controls/FirstPersonControls.js +512 -0
- package/Resources/WebLibraries/three/addons/controls/FlyControls.js +384 -0
- package/Resources/WebLibraries/three/addons/controls/MapControls.js +116 -0
- package/Resources/WebLibraries/three/addons/controls/OrbitControls.js +1985 -0
- package/Resources/WebLibraries/three/addons/controls/PointerLockControls.js +264 -0
- package/Resources/WebLibraries/three/addons/controls/TrackballControls.js +1106 -0
- package/Resources/WebLibraries/three/addons/controls/TransformControls.js +2003 -0
- package/Resources/WebLibraries/three/addons/curves/CurveExtras.js +694 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSCurve.js +169 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSSurface.js +98 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSUtils.js +532 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSVolume.js +82 -0
- package/Resources/WebLibraries/three/addons/effects/AnaglyphEffect.js +274 -0
- package/Resources/WebLibraries/three/addons/effects/AsciiEffect.js +323 -0
- package/Resources/WebLibraries/three/addons/effects/OutlineEffect.js +489 -0
- package/Resources/WebLibraries/three/addons/effects/ParallaxBarrierEffect.js +155 -0
- package/Resources/WebLibraries/three/addons/effects/StereoEffect.js +91 -0
- package/Resources/WebLibraries/three/addons/environments/ColorEnvironment.js +59 -0
- package/Resources/WebLibraries/three/addons/environments/DebugEnvironment.js +102 -0
- package/Resources/WebLibraries/three/addons/environments/RoomEnvironment.js +185 -0
- package/Resources/WebLibraries/three/addons/geometries/BoxLineGeometry.js +92 -0
- package/Resources/WebLibraries/three/addons/geometries/ConvexGeometry.js +72 -0
- package/Resources/WebLibraries/three/addons/geometries/DecalGeometry.js +420 -0
- package/Resources/WebLibraries/three/addons/geometries/LoftGeometry.js +355 -0
- package/Resources/WebLibraries/three/addons/geometries/ParametricFunctions.js +100 -0
- package/Resources/WebLibraries/three/addons/geometries/ParametricGeometry.js +172 -0
- package/Resources/WebLibraries/three/addons/geometries/RoundedBoxGeometry.js +216 -0
- package/Resources/WebLibraries/three/addons/geometries/TeapotGeometry.js +689 -0
- package/Resources/WebLibraries/three/addons/geometries/TextGeometry.js +102 -0
- package/Resources/WebLibraries/three/addons/helpers/AnimationPathHelper.js +302 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelper.js +166 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelperWebGL.js +221 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeHelper.js +166 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeHelperGPU.js +102 -0
- package/Resources/WebLibraries/three/addons/helpers/OctreeHelper.js +109 -0
- package/Resources/WebLibraries/three/addons/helpers/PositionalAudioHelper.js +169 -0
- package/Resources/WebLibraries/three/addons/helpers/RapierHelper.js +59 -0
- package/Resources/WebLibraries/three/addons/helpers/RectAreaLightHelper.js +118 -0
- package/Resources/WebLibraries/three/addons/helpers/TextureHelper.js +265 -0
- package/Resources/WebLibraries/three/addons/helpers/TextureHelperGPU.js +214 -0
- package/Resources/WebLibraries/three/addons/helpers/VertexNormalsHelper.js +155 -0
- package/Resources/WebLibraries/three/addons/helpers/VertexTangentsHelper.js +133 -0
- package/Resources/WebLibraries/three/addons/helpers/ViewHelper.js +529 -0
- package/Resources/WebLibraries/three/addons/interactive/HTMLMesh.js +617 -0
- package/Resources/WebLibraries/three/addons/interactive/InteractiveGroup.js +224 -0
- package/Resources/WebLibraries/three/addons/interactive/SelectionBox.js +324 -0
- package/Resources/WebLibraries/three/addons/interactive/SelectionHelper.js +150 -0
- package/Resources/WebLibraries/three/addons/libs/fflate.module.js +2699 -0
- package/Resources/WebLibraries/three/addons/libs/lil-gui.module.min.js +8 -0
- package/Resources/WebLibraries/three/addons/libs/meshopt_decoder.module.js +196 -0
- package/Resources/WebLibraries/three/addons/libs/potpack.module.js +125 -0
- package/Resources/WebLibraries/three/addons/libs/stats.module.js +167 -0
- package/Resources/WebLibraries/three/addons/libs/tween.module.js +876 -0
- package/Resources/WebLibraries/three/addons/lighting/ClusteredLighting.js +153 -0
- package/Resources/WebLibraries/three/addons/lighting/DynamicLighting.js +82 -0
- package/Resources/WebLibraries/three/addons/lighting/LightMapper.js +295 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGrid.js +923 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGridUtils.js +107 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGridWebGL.js +846 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIConeTracer.js +243 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIIrradiance.js +43 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGINode.js +617 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGISceneCollector.js +793 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIVolume.js +1440 -0
- package/Resources/WebLibraries/three/addons/lights/LightProbeGenerator.js +337 -0
- package/Resources/WebLibraries/three/addons/lights/RectAreaLightTexturesLib.js +127 -0
- package/Resources/WebLibraries/three/addons/lights/RectAreaLightUniformsLib.js +40 -0
- package/Resources/WebLibraries/three/addons/lights/SunLight.js +100 -0
- package/Resources/WebLibraries/three/addons/lights/SunLightNode.js +56 -0
- package/Resources/WebLibraries/three/addons/lights/SunLightShadow.js +319 -0
- package/Resources/WebLibraries/three/addons/lights/SunShadowNode.js +312 -0
- package/Resources/WebLibraries/three/addons/lines/Line2.js +56 -0
- package/Resources/WebLibraries/three/addons/lines/LineGeometry.js +157 -0
- package/Resources/WebLibraries/three/addons/lines/LineMaterial.js +742 -0
- package/Resources/WebLibraries/three/addons/lines/LineSegments2.js +434 -0
- package/Resources/WebLibraries/three/addons/lines/LineSegmentsGeometry.js +298 -0
- package/Resources/WebLibraries/three/addons/lines/Wireframe.js +108 -0
- package/Resources/WebLibraries/three/addons/lines/WireframeGeometry2.js +49 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/Line2.js +46 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/LineSegments2.js +419 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/Wireframe.js +86 -0
- package/Resources/WebLibraries/three/addons/loaders/EXRLoader.js +3411 -0
- package/Resources/WebLibraries/three/addons/loaders/FBXLoader.js +4660 -0
- package/Resources/WebLibraries/three/addons/loaders/FontLoader.js +262 -0
- package/Resources/WebLibraries/three/addons/loaders/GLTFLoader.js +5006 -0
- package/Resources/WebLibraries/three/addons/loaders/HDRLoader.js +463 -0
- package/Resources/WebLibraries/three/addons/loaders/MTLLoader.js +601 -0
- package/Resources/WebLibraries/three/addons/loaders/OBJLoader.js +961 -0
- package/Resources/WebLibraries/three/addons/loaders/PLYLoader.js +992 -0
- package/Resources/WebLibraries/three/addons/loaders/RGBELoader.js +18 -0
- package/Resources/WebLibraries/three/addons/loaders/STLLoader.js +423 -0
- package/Resources/WebLibraries/three/addons/loaders/SVGLoader.js +3297 -0
- package/Resources/WebLibraries/three/addons/loaders/TGALoader.js +539 -0
- package/Resources/WebLibraries/three/addons/loaders/UltraHDRLoader.js +757 -0
- package/Resources/WebLibraries/three/addons/math/Capsule.js +159 -0
- package/Resources/WebLibraries/three/addons/math/ColorConverter.js +62 -0
- package/Resources/WebLibraries/three/addons/math/ColorSpaces.js +147 -0
- package/Resources/WebLibraries/three/addons/math/ConvexHull.js +1695 -0
- package/Resources/WebLibraries/three/addons/math/ImprovedNoise.js +88 -0
- package/Resources/WebLibraries/three/addons/math/Lut.js +317 -0
- package/Resources/WebLibraries/three/addons/math/MeshSurfaceSampler.js +315 -0
- package/Resources/WebLibraries/three/addons/math/OBB.js +535 -0
- package/Resources/WebLibraries/three/addons/math/Octree.js +825 -0
- package/Resources/WebLibraries/three/addons/math/SimplexNoise.js +470 -0
- package/Resources/WebLibraries/three/addons/misc/ConvexObjectBreaker.js +539 -0
- package/Resources/WebLibraries/three/addons/misc/GPUComputationRenderer.js +508 -0
- package/Resources/WebLibraries/three/addons/misc/Gyroscope.js +78 -0
- package/Resources/WebLibraries/three/addons/misc/MorphAnimMesh.js +119 -0
- package/Resources/WebLibraries/three/addons/misc/MorphBlendMesh.js +425 -0
- package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMap.js +370 -0
- package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMapGPU.js +322 -0
- package/Resources/WebLibraries/three/addons/misc/RollerCoaster.js +661 -0
- package/Resources/WebLibraries/three/addons/misc/Sculptor.js +1679 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorMesh.js +1504 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorTools.js +1180 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorUtils.js +345 -0
- package/Resources/WebLibraries/three/addons/misc/TileCreasedNormalsPlugin.js +270 -0
- package/Resources/WebLibraries/three/addons/misc/TubePainter.js +611 -0
- package/Resources/WebLibraries/three/addons/misc/Volume.js +520 -0
- package/Resources/WebLibraries/three/addons/misc/VolumeSlice.js +275 -0
- package/Resources/WebLibraries/three/addons/modifiers/CurveModifier.js +374 -0
- package/Resources/WebLibraries/three/addons/modifiers/CurveModifierGPU.js +256 -0
- package/Resources/WebLibraries/three/addons/modifiers/EdgeSplitModifier.js +299 -0
- package/Resources/WebLibraries/three/addons/modifiers/TessellateModifier.js +340 -0
- package/Resources/WebLibraries/three/addons/objects/GroundedSkybox.js +69 -0
- package/Resources/WebLibraries/three/addons/objects/Lensflare.js +489 -0
- package/Resources/WebLibraries/three/addons/objects/LensflareMesh.js +376 -0
- package/Resources/WebLibraries/three/addons/objects/MarchingCubes.js +1261 -0
- package/Resources/WebLibraries/three/addons/objects/Reflector.js +390 -0
- package/Resources/WebLibraries/three/addons/objects/ReflectorForSSRPass.js +393 -0
- package/Resources/WebLibraries/three/addons/objects/Refractor.js +389 -0
- package/Resources/WebLibraries/three/addons/objects/ShadowMesh.js +130 -0
- package/Resources/WebLibraries/three/addons/objects/Sky.js +342 -0
- package/Resources/WebLibraries/three/addons/objects/SkyMesh.js +403 -0
- package/Resources/WebLibraries/three/addons/objects/Water.js +374 -0
- package/Resources/WebLibraries/three/addons/objects/Water2.js +403 -0
- package/Resources/WebLibraries/three/addons/objects/Water2Mesh.js +199 -0
- package/Resources/WebLibraries/three/addons/objects/WaterMesh.js +194 -0
- package/Resources/WebLibraries/three/addons/postprocessing/AfterimagePass.js +187 -0
- package/Resources/WebLibraries/three/addons/postprocessing/BloomPass.js +274 -0
- package/Resources/WebLibraries/three/addons/postprocessing/BokehPass.js +218 -0
- package/Resources/WebLibraries/three/addons/postprocessing/ClearPass.js +97 -0
- package/Resources/WebLibraries/three/addons/postprocessing/CubeTexturePass.js +146 -0
- package/Resources/WebLibraries/three/addons/postprocessing/DotScreenPass.js +114 -0
- package/Resources/WebLibraries/three/addons/postprocessing/EffectComposer.js +365 -0
- package/Resources/WebLibraries/three/addons/postprocessing/FXAAPass.js +40 -0
- package/Resources/WebLibraries/three/addons/postprocessing/FilmPass.js +113 -0
- package/Resources/WebLibraries/three/addons/postprocessing/GTAOPass.js +735 -0
- package/Resources/WebLibraries/three/addons/postprocessing/GlitchPass.js +177 -0
- package/Resources/WebLibraries/three/addons/postprocessing/HalftonePass.js +134 -0
- package/Resources/WebLibraries/three/addons/postprocessing/LUTPass.js +138 -0
- package/Resources/WebLibraries/three/addons/postprocessing/MaskPass.js +195 -0
- package/Resources/WebLibraries/three/addons/postprocessing/OutlinePass.js +776 -0
- package/Resources/WebLibraries/three/addons/postprocessing/OutputPass.js +148 -0
- package/Resources/WebLibraries/three/addons/postprocessing/Pass.js +191 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderPass.js +193 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderPixelatedPass.js +314 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderTransitionPass.js +267 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SAOPass.js +407 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SMAAPass.js +230 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSAARenderPass.js +313 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSAOPass.js +527 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSRPass.js +858 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SavePass.js +132 -0
- package/Resources/WebLibraries/three/addons/postprocessing/ShaderPass.js +135 -0
- package/Resources/WebLibraries/three/addons/postprocessing/TAARenderPass.js +243 -0
- package/Resources/WebLibraries/three/addons/postprocessing/TexturePass.js +131 -0
- package/Resources/WebLibraries/three/addons/postprocessing/UnrealBloomPass.js +541 -0
- package/Resources/WebLibraries/three/addons/shaders/ACESFilmicToneMappingShader.js +96 -0
- package/Resources/WebLibraries/three/addons/shaders/AfterimageShader.js +63 -0
- package/Resources/WebLibraries/three/addons/shaders/BasicShader.js +36 -0
- package/Resources/WebLibraries/three/addons/shaders/BleachBypassShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/BlendShader.js +56 -0
- package/Resources/WebLibraries/three/addons/shaders/BokehShader.js +151 -0
- package/Resources/WebLibraries/three/addons/shaders/BokehShader2.js +404 -0
- package/Resources/WebLibraries/three/addons/shaders/BrightnessContrastShader.js +62 -0
- package/Resources/WebLibraries/three/addons/shaders/ColorCorrectionShader.js +59 -0
- package/Resources/WebLibraries/three/addons/shaders/ColorifyShader.js +57 -0
- package/Resources/WebLibraries/three/addons/shaders/ConvolutionShader.js +74 -0
- package/Resources/WebLibraries/three/addons/shaders/CopyShader.js +52 -0
- package/Resources/WebLibraries/three/addons/shaders/DOFMipMapShader.js +63 -0
- package/Resources/WebLibraries/three/addons/shaders/DepthLimitedBlurShader.js +183 -0
- package/Resources/WebLibraries/three/addons/shaders/DigitalGlitch.js +104 -0
- package/Resources/WebLibraries/three/addons/shaders/DotScreenShader.js +75 -0
- package/Resources/WebLibraries/three/addons/shaders/ExposureShader.js +51 -0
- package/Resources/WebLibraries/three/addons/shaders/FXAAShader.js +298 -0
- package/Resources/WebLibraries/three/addons/shaders/FilmShader.js +73 -0
- package/Resources/WebLibraries/three/addons/shaders/FocusShader.js +94 -0
- package/Resources/WebLibraries/three/addons/shaders/FreiChenShader.js +103 -0
- package/Resources/WebLibraries/three/addons/shaders/GTAOShader.js +437 -0
- package/Resources/WebLibraries/three/addons/shaders/GammaCorrectionShader.js +52 -0
- package/Resources/WebLibraries/three/addons/shaders/HalftoneShader.js +332 -0
- package/Resources/WebLibraries/three/addons/shaders/HorizontalBlurShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/HorizontalTiltShiftShader.js +70 -0
- package/Resources/WebLibraries/three/addons/shaders/HueSaturationShader.js +74 -0
- package/Resources/WebLibraries/three/addons/shaders/KaleidoShader.js +65 -0
- package/Resources/WebLibraries/three/addons/shaders/LuminosityHighPassShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/LuminosityShader.js +54 -0
- package/Resources/WebLibraries/three/addons/shaders/MirrorShader.js +62 -0
- package/Resources/WebLibraries/three/addons/shaders/NormalMapShader.js +60 -0
- package/Resources/WebLibraries/three/addons/shaders/OutputShader.js +103 -0
- package/Resources/WebLibraries/three/addons/shaders/PoissonDenoiseShader.js +230 -0
- package/Resources/WebLibraries/three/addons/shaders/RGBShiftShader.js +61 -0
- package/Resources/WebLibraries/three/addons/shaders/SAOShader.js +201 -0
- package/Resources/WebLibraries/three/addons/shaders/SMAAShader.js +489 -0
- package/Resources/WebLibraries/three/addons/shaders/SSAOShader.js +331 -0
- package/Resources/WebLibraries/three/addons/shaders/SSRShader.js +396 -0
- package/Resources/WebLibraries/three/addons/shaders/SepiaShader.js +57 -0
- package/Resources/WebLibraries/three/addons/shaders/SobelOperatorShader.js +98 -0
- package/Resources/WebLibraries/three/addons/shaders/SubsurfaceScatteringShader.js +95 -0
- package/Resources/WebLibraries/three/addons/shaders/TechnicolorShader.js +51 -0
- package/Resources/WebLibraries/three/addons/shaders/ToonShader.js +349 -0
- package/Resources/WebLibraries/three/addons/shaders/TriangleBlurShader.js +79 -0
- package/Resources/WebLibraries/three/addons/shaders/UnpackDepthRGBAShader.js +60 -0
- package/Resources/WebLibraries/three/addons/shaders/VelocityShader.js +137 -0
- package/Resources/WebLibraries/three/addons/shaders/VerticalBlurShader.js +66 -0
- package/Resources/WebLibraries/three/addons/shaders/VerticalTiltShiftShader.js +70 -0
- package/Resources/WebLibraries/three/addons/shaders/VignetteShader.js +56 -0
- package/Resources/WebLibraries/three/addons/shaders/VolumeShader.js +285 -0
- package/Resources/WebLibraries/three/addons/shaders/WaterRefractionShader.js +106 -0
- package/Resources/WebLibraries/three/addons/textures/FlakesTexture.js +54 -0
- package/Resources/WebLibraries/three/addons/tsl/WebGLNodesHandler.js +607 -0
- package/Resources/WebLibraries/three/addons/tsl/display/AfterImageNode.js +256 -0
- package/Resources/WebLibraries/three/addons/tsl/display/AnaglyphPassNode.js +550 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BilateralBlurNode.js +377 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BleachBypass.js +33 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BloomNode.js +599 -0
- package/Resources/WebLibraries/three/addons/tsl/display/CRT.js +150 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ChromaticAberrationNode.js +163 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DenoiseNode.js +354 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DepthOfFieldNode.js +572 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DotScreenNode.js +104 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FSR1Node.js +481 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FXAANode.js +357 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FilmNode.js +101 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GTAONode.js +727 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GaussianBlurNode.js +412 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GodraysNode.js +604 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ImportanceSampledEnvironment.js +564 -0
- package/Resources/WebLibraries/three/addons/tsl/display/LensflareNode.js +282 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Lut3DNode.js +109 -0
- package/Resources/WebLibraries/three/addons/tsl/display/MotionBlur.js +33 -0
- package/Resources/WebLibraries/three/addons/tsl/display/OITPassNode.js +341 -0
- package/Resources/WebLibraries/three/addons/tsl/display/OutlineNode.js +916 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ParallaxBarrierPassNode.js +90 -0
- package/Resources/WebLibraries/three/addons/tsl/display/PixelationPassNode.js +227 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RGBShiftNode.js +96 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RecurrentDenoiseNode.js +812 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RetroPassNode.js +263 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SMAANode.js +729 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSAAPassNode.js +344 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSAONode.js +422 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSGINode.js +698 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSRNode.js +1430 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSSNode.js +479 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Sepia.js +24 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Shape.js +29 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SharpenNode.js +284 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SobelOperatorNode.js +168 -0
- package/Resources/WebLibraries/three/addons/tsl/display/StereoCompositePassNode.js +190 -0
- package/Resources/WebLibraries/three/addons/tsl/display/StereoPassNode.js +117 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TAAUNode.js +700 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TRAANode.js +609 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TemporalReprojectNode.js +1024 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TransitionNode.js +141 -0
- package/Resources/WebLibraries/three/addons/tsl/display/boxBlur.js +65 -0
- package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlend.js +80 -0
- package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlur.js +63 -0
- package/Resources/WebLibraries/three/addons/tsl/display/hashBlur.js +55 -0
- package/Resources/WebLibraries/three/addons/tsl/display/lensDirt.js +30 -0
- package/Resources/WebLibraries/three/addons/tsl/display/radialBlur.js +68 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/ClusteredLightsNode.js +994 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/DynamicLightsNode.js +201 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/LightProbeGridNode.js +183 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/AmbientLightDataNode.js +67 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/DirectionalLightDataNode.js +117 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/HemisphereLightDataNode.js +105 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/PointLightDataNode.js +140 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/SpotLightDataNode.js +167 -0
- package/Resources/WebLibraries/three/addons/tsl/math/Bayer.js +84 -0
- package/Resources/WebLibraries/three/addons/tsl/math/curlNoise.js +107 -0
- package/Resources/WebLibraries/three/addons/tsl/math/voronoiNoise.js +112 -0
- package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNode.js +542 -0
- package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/GroundedSkybox.js +62 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/RNoise.js +51 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/Raymarching.js +70 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/SoftParticles.js +53 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/SpecularHelpers.js +302 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/TAAUtils.js +184 -0
- package/Resources/WebLibraries/three/addons/utils/BufferGeometryUtils.js +1523 -0
- package/Resources/WebLibraries/three/addons/utils/CameraUtils.js +82 -0
- package/Resources/WebLibraries/three/addons/utils/ColorUtils.js +76 -0
- package/Resources/WebLibraries/three/addons/utils/GaussianSplatUtils.js +229 -0
- package/Resources/WebLibraries/three/addons/utils/GeometryCompressionUtils.js +547 -0
- package/Resources/WebLibraries/three/addons/utils/GeometryUtils.js +226 -0
- package/Resources/WebLibraries/three/addons/utils/LDrawUtils.js +211 -0
- package/Resources/WebLibraries/three/addons/utils/SceneOptimizer.js +459 -0
- package/Resources/WebLibraries/three/addons/utils/SceneUtils.js +363 -0
- package/Resources/WebLibraries/three/addons/utils/ShadowMapViewer.js +244 -0
- package/Resources/WebLibraries/three/addons/utils/ShadowMapViewerGPU.js +233 -0
- package/Resources/WebLibraries/three/addons/utils/SkeletonUtils.js +496 -0
- package/Resources/WebLibraries/three/addons/utils/SortUtils.js +175 -0
- package/Resources/WebLibraries/three/addons/utils/UVsDebug.js +173 -0
- package/Resources/WebLibraries/three/addons/utils/WebGLTextureUtils.js +115 -0
- package/Resources/WebLibraries/three/addons/utils/WebGPUTextureUtils.js +81 -0
- package/Resources/WebLibraries/three/addons/utils/WorkerPool.js +167 -0
- package/Resources/WebLibraries/three/addons/utils/unwrapUVs.js +865 -0
- package/Resources/WebLibraries/three/three.core.js +61162 -0
- package/Resources/WebLibraries/three/three.module.js +19537 -0
- package/Resources/WebLibraries/three/three.tsl.js +41903 -0
- package/Resources/WebLibraries/three/three.webgpu.js +53714 -0
- package/Resources/skills/2d-game/SKILL.md +305 -0
- package/Resources/skills/3d-game/SKILL.md +274 -0
- package/Resources/skills/accounts/SKILL.md +41 -0
- package/Resources/skills/android-design/SKILL.md +159 -0
- package/Resources/skills/app-ai/SKILL.md +154 -0
- package/Resources/skills/app-intents/SKILL.md +31 -0
- package/Resources/skills/app-kinds/SKILL.md +122 -0
- package/Resources/skills/apple-watch/SKILL.md +43 -0
- package/Resources/skills/assets/SKILL.md +183 -0
- package/Resources/skills/building-blocks/SKILL.md +97 -0
- package/Resources/skills/device-control/SKILL.md +56 -0
- package/Resources/skills/device-integrations/SKILL.md +278 -0
- package/Resources/skills/finder-files/SKILL.md +19 -0
- package/Resources/skills/game/SKILL.md +414 -0
- package/Resources/skills/game-3d/SKILL.md +12 -0
- package/Resources/skills/game-art/SKILL.md +11 -0
- package/Resources/skills/game-feel/SKILL.md +13 -0
- package/Resources/skills/game-levels/SKILL.md +12 -0
- package/Resources/skills/game-live/SKILL.md +12 -0
- package/Resources/skills/game-physics/SKILL.md +13 -0
- package/Resources/skills/game-playtest/SKILL.md +26 -0
- package/Resources/skills/game-ui/SKILL.md +278 -0
- package/Resources/skills/github-projects/SKILL.md +59 -0
- package/Resources/skills/icloud-sync/SKILL.md +30 -0
- package/Resources/skills/iphone-hardware/SKILL.md +57 -0
- package/Resources/skills/iphone-widgets/SKILL.md +53 -0
- package/Resources/skills/lg-developer-mode/SKILL.md +152 -0
- package/Resources/skills/mac-widgets/SKILL.md +60 -0
- package/Resources/skills/maps/SKILL.md +8 -0
- package/Resources/skills/menu-bar/SKILL.md +36 -0
- package/Resources/skills/more-apps/SKILL.md +53 -0
- package/Resources/skills/phone-controllers/SKILL.md +79 -0
- package/Resources/skills/phone-pages/SKILL.md +173 -0
- package/Resources/skills/roku-developer-mode/SKILL.md +106 -0
- package/Resources/skills/scene-3d/SKILL.md +27 -0
- package/Resources/skills/scripting/SKILL.md +17 -0
- package/Resources/skills/share-extension/SKILL.md +22 -0
- package/Resources/skills/tv-design/SKILL.md +72 -0
- package/Resources/skills/web-app/SKILL.md +136 -0
- package/Resources/skills/web-game/SKILL.md +95 -0
- package/Resources/skills/web-or-native/SKILL.md +103 -0
- package/Resources/skills/wish-links/SKILL.md +156 -0
- package/THIRD_PARTY_NOTICES.md +170 -0
- package/cli/android.mjs +941 -0
- package/cli/browser.mjs +268 -0
- package/cli/calls.mjs +390 -0
- package/cli/dev.mjs +773 -0
- package/cli/devices.mjs +984 -0
- package/cli/lamp.mjs +1016 -0
- package/cli/lampapp.mjs +332 -0
- package/cli/lamps/android-host/LampPageGateway.kt +345 -0
- package/cli/lamps/android-host/app/build.gradle.kts +40 -0
- package/cli/lamps/android-host/build.gradle.kts +4 -0
- package/cli/lamps/android-host/game/AndroidManifest.xml +33 -0
- package/cli/lamps/android-host/game/MainActivity.kt +173 -0
- package/cli/lamps/android-host/gradle/libs.versions.toml +39 -0
- package/cli/lamps/android-host/gradle.properties +8 -0
- package/cli/lamps/android-host/page/AndroidManifest.xml +35 -0
- package/cli/lamps/android-host/page/MainActivity.kt +193 -0
- package/cli/lamps/android-host/settings.gradle.kts +30 -0
- package/cli/lamps/android-host/tools.json +43 -0
- package/cli/lamps/lamp-controllers.js +2 -0
- package/cli/lamps/lamp-for-games.js +6863 -0
- package/cli/lamps/lamp.js +7023 -0
- package/cli/lamps/mac-starter/.lamp/meta.json +1 -0
- package/cli/lamps/mac-starter/APP.md +12 -0
- package/cli/lamps/mac-starter/Package.swift +8 -0
- package/cli/lamps/mac-starter/Sources/App.swift +11 -0
- package/cli/lamps/mac-starter/Sources/ContentView.swift +17 -0
- package/cli/lamps/mac-starter/Sources/LampSupport.swift +18097 -0
- package/cli/lamps/mac-starter/build.sh +336 -0
- package/cli/lamps/mac-starter/gitignore +3 -0
- package/cli/lamps/mac-starter/lamp-starter.json +6 -0
- package/cli/lamps/web-starter/APP.md +8 -0
- package/cli/lamps/web-starter/app.js +1 -0
- package/cli/lamps/web-starter/index.html +17 -0
- package/cli/lamps/web-starter/lamp-starter.json +5 -0
- package/cli/lamps/web-starter/lamp.js +7023 -0
- package/cli/lamps/web-starter/style.css +25 -0
- package/cli/link.mjs +138 -0
- package/cli/mac.mjs +621 -0
- package/cli/mdns.mjs +205 -0
- package/cli/msix.mjs +413 -0
- package/cli/network.mjs +209 -0
- package/cli/outside.mjs +140 -0
- package/cli/page.js +165 -0
- package/cli/place.mjs +298 -0
- package/cli/png.mjs +184 -0
- package/cli/share.mjs +202 -0
- package/cli/skill/SKILL.md +255 -0
- package/cli/skills.mjs +71 -0
- package/cli/state.mjs +173 -0
- package/cli/update.mjs +57 -0
- package/package.json +20 -4
- package/site/lib/quota.js +59 -0
- package/site/lib/shared-wishes.js +996 -0
|
@@ -0,0 +1,1531 @@
|
|
|
1
|
+
#if defined(SOKOL_IMPL) && !defined(SOKOL_SHAPE_IMPL)
|
|
2
|
+
#define SOKOL_SHAPE_IMPL
|
|
3
|
+
#endif
|
|
4
|
+
#ifndef SOKOL_SHAPE_INCLUDED
|
|
5
|
+
/*
|
|
6
|
+
sokol_shape.h -- create simple primitive shapes for sokol_gfx.h
|
|
7
|
+
|
|
8
|
+
Project URL: https://github.com/floooh/sokol
|
|
9
|
+
|
|
10
|
+
Do this:
|
|
11
|
+
#define SOKOL_IMPL or
|
|
12
|
+
#define SOKOL_SHAPE_IMPL
|
|
13
|
+
before you include this file in *one* C or C++ file to create the
|
|
14
|
+
implementation.
|
|
15
|
+
|
|
16
|
+
Include the following headers before including sokol_shape.h:
|
|
17
|
+
|
|
18
|
+
sokol_gfx.h
|
|
19
|
+
|
|
20
|
+
...optionally provide the following macros to override defaults:
|
|
21
|
+
|
|
22
|
+
SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
|
|
23
|
+
SOKOL_SHAPE_API_DECL- public function declaration prefix (default: extern)
|
|
24
|
+
SOKOL_API_DECL - same as SOKOL_SHAPE_API_DECL
|
|
25
|
+
SOKOL_API_IMPL - public function implementation prefix (default: -)
|
|
26
|
+
|
|
27
|
+
If sokol_shape.h is compiled as a DLL, define the following before
|
|
28
|
+
including the declaration or implementation:
|
|
29
|
+
|
|
30
|
+
SOKOL_DLL
|
|
31
|
+
|
|
32
|
+
On Windows, SOKOL_DLL will define SOKOL_SHAPE_API_DECL as __declspec(dllexport)
|
|
33
|
+
or __declspec(dllimport) as needed.
|
|
34
|
+
|
|
35
|
+
FEATURE OVERVIEW
|
|
36
|
+
================
|
|
37
|
+
sokol_shape.h creates vertices and indices for simple shapes and
|
|
38
|
+
builds structs which can be plugged into sokol-gfx resource
|
|
39
|
+
creation functions:
|
|
40
|
+
|
|
41
|
+
The following shape types are supported:
|
|
42
|
+
|
|
43
|
+
- plane
|
|
44
|
+
- cube
|
|
45
|
+
- sphere (with poles, not geodesic)
|
|
46
|
+
- cylinder
|
|
47
|
+
- torus (donut)
|
|
48
|
+
|
|
49
|
+
Generated vertex components have the following format (all components
|
|
50
|
+
except position are optional):
|
|
51
|
+
|
|
52
|
+
- position: SG_VERTEXFORMAT_FLOAT3
|
|
53
|
+
- normal: SG_VERTEXFORMAT_BYTE4N
|
|
54
|
+
- texcoord: SG_VERTEXFORMAT_USHORT2N
|
|
55
|
+
- color: SG_VERTEXFORMAT_UBYTE4N
|
|
56
|
+
|
|
57
|
+
Indices are generally 16-bits wide (SG_INDEXTYPE_UINT16) and the indices
|
|
58
|
+
are written as triangle-lists (SG_PRIMITIVETYPE_TRIANGLES).
|
|
59
|
+
|
|
60
|
+
EXAMPLES:
|
|
61
|
+
=========
|
|
62
|
+
|
|
63
|
+
Create multiple shapes into the same vertex- and index-buffer and
|
|
64
|
+
render with separate draw calls:
|
|
65
|
+
|
|
66
|
+
https://github.com/floooh/sokol-samples/blob/master/sapp/shapes-sapp.c
|
|
67
|
+
|
|
68
|
+
Same as the above, but pre-transform shapes and merge them into a single
|
|
69
|
+
shape that's rendered with a single draw call.
|
|
70
|
+
|
|
71
|
+
https://github.com/floooh/sokol-samples/blob/master/sapp/shapes-transform-sapp.c
|
|
72
|
+
|
|
73
|
+
STEP-BY-STEP:
|
|
74
|
+
=============
|
|
75
|
+
|
|
76
|
+
Setup an sshape_state_t struct with pointers to memory buffers where
|
|
77
|
+
generated vertices and indices will be written to:
|
|
78
|
+
|
|
79
|
+
```c
|
|
80
|
+
uint8_t vertices[512 * SSHAPE_MAX_VERTEX_SIZE];
|
|
81
|
+
uint16_t indices[4096];
|
|
82
|
+
|
|
83
|
+
sshape_state_t state = {
|
|
84
|
+
.vertices = { .buffer = SSHAPE_RANGE(vertices) },
|
|
85
|
+
.indices = { .buffer = SSHAPE_RANGE(indices) }
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
This generates all vertex components. Optionally you can disable
|
|
89
|
+
vertex components to be generates:
|
|
90
|
+
|
|
91
|
+
```c
|
|
92
|
+
sshape_state_t state = {
|
|
93
|
+
.disable {
|
|
94
|
+
.normals = false,
|
|
95
|
+
.texcoords = false,
|
|
96
|
+
.colors = false,
|
|
97
|
+
},
|
|
98
|
+
.vertices = { .buffer = SSHAPE_RANGE(vertices) },
|
|
99
|
+
.indices = { .buffer = SSHAPE_RANGE(indices) }
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Compute the per-vertex size in bytes via (note that the arguments
|
|
104
|
+
have inverted meaning from `sshape_state_t.disabled`, here you define
|
|
105
|
+
what components are enabled:
|
|
106
|
+
|
|
107
|
+
```c
|
|
108
|
+
size_t vertex_size = sshape_vertex_size(&(sshape_optional_components_t){
|
|
109
|
+
.normals = true,
|
|
110
|
+
.texcoords = true,
|
|
111
|
+
.colors = true,
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
This returns a value between SSHAPE_MIN_VERTEX_SIZE (12) and
|
|
115
|
+
SSHAPE_MAX_VERTEX_SIZE (24).
|
|
116
|
+
|
|
117
|
+
To find out how big the vertex and index memory buffers must be (in case you want
|
|
118
|
+
to allocate dynamically) call the following functions. For `vertex_size`
|
|
119
|
+
pass in the result of the `sshape_vertex_size` function:
|
|
120
|
+
```c
|
|
121
|
+
sshape_sizes_t sshape_plane_sizes(uint32_t tiles, size_t vertex_size);
|
|
122
|
+
sshape_sizes_t sshape_box_sizes(uint32_t tiles, size_t vertex_size);
|
|
123
|
+
sshape_sizes_t sshape_sphere_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size);
|
|
124
|
+
sshape_sizes_t sshape_cylinder_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size);
|
|
125
|
+
sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t rings, size_t vertex_size);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The returned sshape_sizes_t struct contains vertex- and index-counts
|
|
129
|
+
as well as the equivalent buffer sizes in bytes. For instance:
|
|
130
|
+
|
|
131
|
+
```c
|
|
132
|
+
const vtx_size = sshape_vertex_size(&(sshape_optional_components){0});
|
|
133
|
+
sshape_sizes_t sizes = sshape_sphere_sizes(36, 12, vtx_size);
|
|
134
|
+
uint32_t num_vertices = sizes.vertices.num;
|
|
135
|
+
uint32_t num_indices = sizes.indices.num;
|
|
136
|
+
uint32_t vertex_buffer_size = sizes.vertices.size;
|
|
137
|
+
uint32_t index_buffer_size = sizes.indices.size;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
With the sshape_state_t struct that was setup earlier, call any
|
|
141
|
+
of the shape-builder functions:
|
|
142
|
+
|
|
143
|
+
```c
|
|
144
|
+
void sshape_build_plane(sshape_state_t* state, const sshape_plane_t* params);
|
|
145
|
+
void sshape_build_box(sshape_state_t* state, const sshape_box_t* params);
|
|
146
|
+
void sshape_build_sphere(sshape_state_t* state, const sshape_sphere_t* params);
|
|
147
|
+
void sshape_build_cylinder(sshape_state_t* state, const sshape_cylinder_t* params);
|
|
148
|
+
void sshape_build_torus(sshape_state_t* state, const sshape_torus_t* params);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Note that the `state` arg is a non-const pointer, this indicates
|
|
152
|
+
that the `sshape_state_t` struct will be mutated.
|
|
153
|
+
|
|
154
|
+
The second argument is a struct which holds creation parameters.
|
|
155
|
+
|
|
156
|
+
For instance to build a sphere with radius 2, 36 "cake slices" and 12 stacks:
|
|
157
|
+
|
|
158
|
+
```c
|
|
159
|
+
sshape_state_t state = ...;
|
|
160
|
+
sshape_build_sphere(&state, &(sshape_sphere_t){
|
|
161
|
+
.radius = 2.0f,
|
|
162
|
+
.slices = 36,
|
|
163
|
+
.stacks = 12,
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
If the provided buffers are big enough to hold all generated vertices and
|
|
168
|
+
indices, the "valid" field in the result will be true:
|
|
169
|
+
|
|
170
|
+
```c
|
|
171
|
+
assert(state.valid);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The shape creation parameters have "useful defaults", refer to the
|
|
175
|
+
actual C struct declarations below to look up those defaults.
|
|
176
|
+
|
|
177
|
+
You can also provide additional creation parameters, like a common vertex
|
|
178
|
+
color, a debug-helper to randomize colors, tell the shape builder function
|
|
179
|
+
to merge the new shape with the previous shape into the same draw-element-range,
|
|
180
|
+
or a 4x4 transform matrix to move, rotate and scale the generated vertices:
|
|
181
|
+
|
|
182
|
+
```c
|
|
183
|
+
sshape_state_t state = ...;
|
|
184
|
+
sshape_build_sphere(&state, &(sshape_sphere_t){
|
|
185
|
+
.radius = 2.0f,
|
|
186
|
+
.slices = 36,
|
|
187
|
+
.stacks = 12,
|
|
188
|
+
// merge with previous shape into a single element-range
|
|
189
|
+
.merge = true,
|
|
190
|
+
// set vertex color to red+opaque
|
|
191
|
+
.color = sshape_color_4f(1.0f, 0.0f, 0.0f, 1.0f),
|
|
192
|
+
// set position to y = 2.0
|
|
193
|
+
.transform = {
|
|
194
|
+
.m = {
|
|
195
|
+
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
|
196
|
+
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
|
197
|
+
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
|
198
|
+
{ 0.0f, 2.0f, 0.0f, 1.0f },
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
assert(state.valid);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The following helper functions can be used to build a packed
|
|
206
|
+
color value or to convert from external matrix types:
|
|
207
|
+
|
|
208
|
+
```c
|
|
209
|
+
uint32_t sshape_color_4f(float r, float g, float b, float a);
|
|
210
|
+
uint32_t sshape_color_3f(float r, float g, float b);
|
|
211
|
+
uint32_t sshape_color_4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
|
212
|
+
uint32_t sshape_color_3b(uint8_t r, uint8_t g, uint8_t b);
|
|
213
|
+
sshape_mat4_t sshape_mat4(const float m[16]);
|
|
214
|
+
sshape_mat4_t sshape_mat4_transpose(const float m[16]);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
After the shape builder function has been called, the following functions
|
|
218
|
+
are used to extract the build result for plugging into sokol_gfx.h:
|
|
219
|
+
|
|
220
|
+
```c
|
|
221
|
+
sshape_element_range_t sshape_element_range(const sshape_state_t* state);
|
|
222
|
+
sg_buffer_desc sshape_vertex_buffer_desc(const sshape_state_t* state);
|
|
223
|
+
sg_buffer_desc sshape_index_buffer_desc(const sshape_state_t* state);
|
|
224
|
+
sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(const sshape_state_t* state);
|
|
225
|
+
sg_vertex_attr_state sshape_position_vertex_attr_state(const sshape_state_t* state);
|
|
226
|
+
sg_vertex_attr_state sshape_normal_vertex_attr_state(consts sshape_state_t* state);
|
|
227
|
+
sg_vertex_attr_state sshape_texcoord_vertex_attr_state(const sshape_state_t* state);
|
|
228
|
+
sg_vertex_attr_state sshape_color_vertex_attr_state(const sshape_state_t* state);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The sshape_element_range_t struct contains the base-index and number of
|
|
232
|
+
indices which can be plugged into the sg_draw() call:
|
|
233
|
+
|
|
234
|
+
```c
|
|
235
|
+
sshape_element_range_t elms = sshape_element_range(&state);
|
|
236
|
+
...
|
|
237
|
+
sg_draw(elms.base_element, elms.num_elements, 1);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
To create sokol-gfx vertex- and index-buffers from the generated
|
|
241
|
+
shape data:
|
|
242
|
+
|
|
243
|
+
```c
|
|
244
|
+
// create sokol-gfx vertex buffer
|
|
245
|
+
sg_buffer_desc vbuf_desc = sshape_vertex_buffer_desc(&state);
|
|
246
|
+
sg_buffer vbuf = sg_make_buffer(&vbuf_desc);
|
|
247
|
+
|
|
248
|
+
// create sokol-gfx index buffer
|
|
249
|
+
sg_buffer_desc ibuf_desc = sshape_index_buffer_desc(&state);
|
|
250
|
+
sg_buffer ibuf = sg_make_buffer(&ibuf_desc);
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The remaining functions are used to populate the vertex-layout item
|
|
254
|
+
in sg_pipeline_desc:
|
|
255
|
+
|
|
256
|
+
```c
|
|
257
|
+
sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){
|
|
258
|
+
.layout = {
|
|
259
|
+
.buffers[0] = sshape_vertex_buffer_layout_state(&state),
|
|
260
|
+
.attrs = {
|
|
261
|
+
[0] = sshape_position_vertex_attr_state(&state),
|
|
262
|
+
[1] = sshape_normal_vertex_attr_state(&state),
|
|
263
|
+
[2] = sshape_texcoord_vertex_attr_state(&state),
|
|
264
|
+
[3] = sshape_color_vertex_attr_state(&state)
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
...
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
Note that you don't have to use all generated vertex attributes in the
|
|
271
|
+
pipeline's vertex layout, the sg_vertex_buffer_layout_state struct returned
|
|
272
|
+
by sshape_vertex_buffer_layout_state() contains the correct vertex stride
|
|
273
|
+
to skip vertex components.
|
|
274
|
+
|
|
275
|
+
WRITING MULTIPLE SHAPES INTO THE SAME BUFFER
|
|
276
|
+
============================================
|
|
277
|
+
You can merge multiple shapes into the same vertex- and
|
|
278
|
+
index-buffers and either render them as a single shape, or
|
|
279
|
+
in separate draw calls.
|
|
280
|
+
|
|
281
|
+
To build a single shape made of two cubes which can be rendered
|
|
282
|
+
in a single draw-call:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
uint8_t vertices[128 * SSHAPE_MAX_VERTEX_SIZE];
|
|
286
|
+
uint16_t indices[16];
|
|
287
|
+
|
|
288
|
+
sshape_state_t state = {
|
|
289
|
+
.vertices.buffer = SSHAPE_RANGE(vertices),
|
|
290
|
+
.indices.buffer = SSHAPE_RANGE(indices)
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// first cube at pos x=-2.0 (with default size of 1x1x1)
|
|
294
|
+
sshape_build_cube(&state, &(sshape_box_t){
|
|
295
|
+
.transform = {
|
|
296
|
+
.m = {
|
|
297
|
+
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
|
298
|
+
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
|
299
|
+
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
|
300
|
+
{-2.0f, 0.0f, 0.0f, 1.0f },
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
// ...and append another cube at pos pos=+1.0
|
|
305
|
+
// NOTE the .merge = true, this tells the shape builder
|
|
306
|
+
// function to not advance the current shape start offset
|
|
307
|
+
sshape_build_cube(&state, &(sshape_box_t){
|
|
308
|
+
.merge = true,
|
|
309
|
+
.transform = {
|
|
310
|
+
.m = {
|
|
311
|
+
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
|
312
|
+
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
|
313
|
+
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
|
314
|
+
{-2.0f, 0.0f, 0.0f, 1.0f },
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
assert(state.valid);
|
|
319
|
+
|
|
320
|
+
// skipping buffer- and pipeline-creation...
|
|
321
|
+
|
|
322
|
+
sshape_element_range_t elms = sshape_element_range(&state);
|
|
323
|
+
sg_draw(elms.base_element, elms.num_elements, 1);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
To render the two cubes in separate draw-calls, the element-ranges used
|
|
327
|
+
in the sg_draw() calls must be captured right after calling the
|
|
328
|
+
builder-functions:
|
|
329
|
+
|
|
330
|
+
```c
|
|
331
|
+
uint8_t vertices[128 * SSHAPE_MAX_VERTEX_SIZE];
|
|
332
|
+
uint16_t indices[16];
|
|
333
|
+
sshape_state_t state = {
|
|
334
|
+
.vertices.buffer = SSHAPE_RANGE(vertices),
|
|
335
|
+
.indices.buffer = SSHAPE_RANGE(indices)
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// build a red cube...
|
|
339
|
+
sshape_build_cube(&state, &(sshape_box_t){
|
|
340
|
+
.color = sshape_color_3b(255, 0, 0)
|
|
341
|
+
});
|
|
342
|
+
sshape_element_range_t red_cube = sshape_element_range(&state);
|
|
343
|
+
|
|
344
|
+
// append a green cube to the same vertex-/index-buffer:
|
|
345
|
+
sshape_build_cube(&state, &sshape_box_t){
|
|
346
|
+
.color = sshape_color_3b(0, 255, 0);
|
|
347
|
+
});
|
|
348
|
+
sshape_element_range_t green_cube = sshape_element_range(&state);
|
|
349
|
+
|
|
350
|
+
// skipping buffer- and pipeline-creation...
|
|
351
|
+
|
|
352
|
+
sg_draw(red_cube.base_element, red_cube.num_elements, 1);
|
|
353
|
+
sg_draw(green_cube.base_element, green_cube.num_elements, 1);
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
...that's about all :)
|
|
357
|
+
|
|
358
|
+
LICENSE
|
|
359
|
+
=======
|
|
360
|
+
zlib/libpng license
|
|
361
|
+
|
|
362
|
+
Copyright (c) 2020 Andre Weissflog
|
|
363
|
+
|
|
364
|
+
This software is provided 'as-is', without any express or implied warranty.
|
|
365
|
+
In no event will the authors be held liable for any damages arising from the
|
|
366
|
+
use of this software.
|
|
367
|
+
|
|
368
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
369
|
+
including commercial applications, and to alter it and redistribute it
|
|
370
|
+
freely, subject to the following restrictions:
|
|
371
|
+
|
|
372
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
373
|
+
claim that you wrote the original software. If you use this software in a
|
|
374
|
+
product, an acknowledgment in the product documentation would be
|
|
375
|
+
appreciated but is not required.
|
|
376
|
+
|
|
377
|
+
2. Altered source versions must be plainly marked as such, and must not
|
|
378
|
+
be misrepresented as being the original software.
|
|
379
|
+
|
|
380
|
+
3. This notice may not be removed or altered from any source
|
|
381
|
+
distribution.
|
|
382
|
+
*/
|
|
383
|
+
#define SOKOL_SHAPE_INCLUDED
|
|
384
|
+
#include <stddef.h> // size_t, offsetof
|
|
385
|
+
#include <stdint.h>
|
|
386
|
+
#include <stdbool.h>
|
|
387
|
+
|
|
388
|
+
#if !defined(SOKOL_GFX_INCLUDED)
|
|
389
|
+
#error "Please include sokol_gfx.h before sokol_shape.h"
|
|
390
|
+
#endif
|
|
391
|
+
|
|
392
|
+
#if defined(SOKOL_API_DECL) && !defined(SOKOL_SHAPE_API_DECL)
|
|
393
|
+
#define SOKOL_SHAPE_API_DECL SOKOL_API_DECL
|
|
394
|
+
#endif
|
|
395
|
+
#ifndef SOKOL_SHAPE_API_DECL
|
|
396
|
+
#if defined(_WIN32) && defined(SOKOL_DLL) && defined(SOKOL_SHAPE_IMPL)
|
|
397
|
+
#define SOKOL_SHAPE_API_DECL __declspec(dllexport)
|
|
398
|
+
#elif defined(_WIN32) && defined(SOKOL_DLL)
|
|
399
|
+
#define SOKOL_SHAPE_API_DECL __declspec(dllimport)
|
|
400
|
+
#else
|
|
401
|
+
#define SOKOL_SHAPE_API_DECL extern
|
|
402
|
+
#endif
|
|
403
|
+
#endif
|
|
404
|
+
|
|
405
|
+
#ifdef __cplusplus
|
|
406
|
+
extern "C" {
|
|
407
|
+
#endif
|
|
408
|
+
|
|
409
|
+
/*
|
|
410
|
+
sshape_range_t is a pointer-size-pair struct used to pass memory
|
|
411
|
+
blobs into sokol-shape. When initialized from a value type
|
|
412
|
+
(array or struct), use the SSHAPE_RANGE() macro to build
|
|
413
|
+
an sshape_range struct.
|
|
414
|
+
*/
|
|
415
|
+
typedef struct sshape_range_t {
|
|
416
|
+
const void* ptr;
|
|
417
|
+
size_t size;
|
|
418
|
+
} sshape_range_t;
|
|
419
|
+
|
|
420
|
+
// disabling this for every includer isn't great, but the warning is also quite pointless
|
|
421
|
+
#if defined(_MSC_VER)
|
|
422
|
+
#pragma warning(disable:4221) /* /W4 only: nonstandard extension used: 'x': cannot be initialized using address of automatic variable 'y' */
|
|
423
|
+
#endif
|
|
424
|
+
#if defined(__cplusplus)
|
|
425
|
+
#define SSHAPE_RANGE(x) sshape_range_t{ &x, sizeof(x) }
|
|
426
|
+
#else
|
|
427
|
+
#define SSHAPE_RANGE(x) (sshape_range_t){ &x, sizeof(x) }
|
|
428
|
+
#endif
|
|
429
|
+
|
|
430
|
+
enum {
|
|
431
|
+
// the minumum vertex size in bytes (when no optional components are used)
|
|
432
|
+
SSHAPE_MIN_VERTEX_SIZE = 12,
|
|
433
|
+
// the maximum vertex size in bytes (when all optional components are used)
|
|
434
|
+
SSHAPE_MAX_VERTEX_SIZE = 24,
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// a 4x4 matrix wrapper struct
|
|
438
|
+
typedef struct sshape_mat4_t { float m[4][4]; } sshape_mat4_t;
|
|
439
|
+
|
|
440
|
+
// a struct for configuring optional vertex components
|
|
441
|
+
typedef struct sshape_optional_components_t {
|
|
442
|
+
bool normals;
|
|
443
|
+
bool texcoords;
|
|
444
|
+
bool colors;
|
|
445
|
+
} sshape_optional_components_t;
|
|
446
|
+
|
|
447
|
+
// a range of draw-elements (sg_draw(int base_element, int num_element, ...))
|
|
448
|
+
typedef struct sshape_element_range_t {
|
|
449
|
+
int base_element;
|
|
450
|
+
int num_elements;
|
|
451
|
+
} sshape_element_range_t;
|
|
452
|
+
|
|
453
|
+
// number of elements and byte size of build actions
|
|
454
|
+
typedef struct sshape_sizes_item_t {
|
|
455
|
+
uint32_t num; // number of elements
|
|
456
|
+
uint32_t size; // the same as size in bytes
|
|
457
|
+
} sshape_sizes_item_t;
|
|
458
|
+
|
|
459
|
+
typedef struct sshape_sizes_t {
|
|
460
|
+
sshape_sizes_item_t vertices;
|
|
461
|
+
sshape_sizes_item_t indices;
|
|
462
|
+
} sshape_sizes_t;
|
|
463
|
+
|
|
464
|
+
// in/out struct to keep track of mesh-build state
|
|
465
|
+
typedef struct sshape_buffer_state_t {
|
|
466
|
+
sshape_range_t buffer; // pointer/size pair of output buffer
|
|
467
|
+
size_t data_size; // size in bytes of valid data in buffer
|
|
468
|
+
size_t shape_offset; // data offset of the most recent shape
|
|
469
|
+
} sshape_buffer_state_t;
|
|
470
|
+
|
|
471
|
+
typedef struct sshape_state_t {
|
|
472
|
+
bool valid;
|
|
473
|
+
sshape_optional_components_t disable;
|
|
474
|
+
sshape_buffer_state_t vertices; // memory buffer for vertex data
|
|
475
|
+
sshape_buffer_state_t indices; // memory buffer for index data
|
|
476
|
+
} sshape_state_t;
|
|
477
|
+
|
|
478
|
+
// creation parameters for the different shape types
|
|
479
|
+
typedef struct sshape_plane_t {
|
|
480
|
+
float width, depth; // default: 1.0
|
|
481
|
+
uint16_t tiles; // default: 1
|
|
482
|
+
uint32_t color; // default: white
|
|
483
|
+
bool random_colors; // default: false
|
|
484
|
+
bool merge; // if true merge with previous shape (default: false)
|
|
485
|
+
sshape_mat4_t transform; // default: identity matrix
|
|
486
|
+
} sshape_plane_t;
|
|
487
|
+
|
|
488
|
+
typedef struct sshape_box_t {
|
|
489
|
+
float width, height, depth; // default: 1.0
|
|
490
|
+
uint16_t tiles; // default: 1
|
|
491
|
+
uint32_t color; // default: white
|
|
492
|
+
bool random_colors; // default: false
|
|
493
|
+
bool merge; // if true merge with previous shape (default: false)
|
|
494
|
+
sshape_mat4_t transform; // default: identity matrix
|
|
495
|
+
} sshape_box_t;
|
|
496
|
+
|
|
497
|
+
typedef struct sshape_sphere_t {
|
|
498
|
+
float radius; // default: 0.5
|
|
499
|
+
uint16_t slices; // default: 5
|
|
500
|
+
uint16_t stacks; // default: 4
|
|
501
|
+
uint32_t color; // default: white
|
|
502
|
+
bool random_colors; // default: false
|
|
503
|
+
bool merge; // if true merge with previous shape (default: false)
|
|
504
|
+
sshape_mat4_t transform; // default: identity matrix
|
|
505
|
+
} sshape_sphere_t;
|
|
506
|
+
|
|
507
|
+
typedef struct sshape_cylinder_t {
|
|
508
|
+
float radius; // default: 0.5
|
|
509
|
+
float height; // default: 1.0
|
|
510
|
+
uint16_t slices; // default: 5
|
|
511
|
+
uint16_t stacks; // default: 1
|
|
512
|
+
uint32_t color; // default: white
|
|
513
|
+
bool random_colors; // default: false
|
|
514
|
+
bool merge; // if true merge with previous shape (default: false)
|
|
515
|
+
sshape_mat4_t transform; // default: identity matrix
|
|
516
|
+
} sshape_cylinder_t;
|
|
517
|
+
|
|
518
|
+
typedef struct sshape_torus_t {
|
|
519
|
+
float radius; // default: 0.5f
|
|
520
|
+
float ring_radius; // default: 0.2f
|
|
521
|
+
uint16_t sides; // default: 5
|
|
522
|
+
uint16_t rings; // default: 5
|
|
523
|
+
uint32_t color; // default: white
|
|
524
|
+
bool random_colors; // default: false
|
|
525
|
+
bool merge; // if true merge with previous shape (default: false)
|
|
526
|
+
sshape_mat4_t transform; // default: identity matrix
|
|
527
|
+
} sshape_torus_t;
|
|
528
|
+
|
|
529
|
+
// shape builder functions
|
|
530
|
+
SOKOL_SHAPE_API_DECL void sshape_build_plane(sshape_state_t* state, const sshape_plane_t* params);
|
|
531
|
+
SOKOL_SHAPE_API_DECL void sshape_build_box(sshape_state_t* state, const sshape_box_t* params);
|
|
532
|
+
SOKOL_SHAPE_API_DECL void sshape_build_sphere(sshape_state_t* state, const sshape_sphere_t* params);
|
|
533
|
+
SOKOL_SHAPE_API_DECL void sshape_build_cylinder(sshape_state_t* state, const sshape_cylinder_t* params);
|
|
534
|
+
SOKOL_SHAPE_API_DECL void sshape_build_torus(sshape_state_t* state, const sshape_torus_t* params);
|
|
535
|
+
|
|
536
|
+
// compute size of vertex given optional components
|
|
537
|
+
SOKOL_SHAPE_API_DECL size_t sshape_vertex_size(const sshape_optional_components_t* components);
|
|
538
|
+
|
|
539
|
+
// query required vertex- and index-buffer sizes in bytes
|
|
540
|
+
SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_plane_sizes(uint32_t tiles, size_t vertex_size);
|
|
541
|
+
SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_box_sizes(uint32_t tiles, size_t vertex_size);
|
|
542
|
+
SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_sphere_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size);
|
|
543
|
+
SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_cylinder_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size);
|
|
544
|
+
SOKOL_SHAPE_API_DECL sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t rings, size_t vertex_size);
|
|
545
|
+
|
|
546
|
+
// extract sokol-gfx desc structs and primitive ranges from build state
|
|
547
|
+
SOKOL_SHAPE_API_DECL sshape_element_range_t sshape_element_range(const sshape_state_t* state);
|
|
548
|
+
SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_state_t* state);
|
|
549
|
+
SOKOL_SHAPE_API_DECL sg_buffer_desc sshape_index_buffer_desc(const sshape_state_t* state);
|
|
550
|
+
SOKOL_SHAPE_API_DECL sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(const sshape_state_t* state);
|
|
551
|
+
SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_position_vertex_attr_state(const sshape_state_t* state);
|
|
552
|
+
SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_normal_vertex_attr_state(const sshape_state_t* state);
|
|
553
|
+
SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_texcoord_vertex_attr_state(const sshape_state_t* state);
|
|
554
|
+
SOKOL_SHAPE_API_DECL sg_vertex_attr_state sshape_color_vertex_attr_state(const sshape_state_t* state);
|
|
555
|
+
|
|
556
|
+
// helper functions to build packed color value from floats or bytes
|
|
557
|
+
SOKOL_SHAPE_API_DECL uint32_t sshape_color_4f(float r, float g, float b, float a);
|
|
558
|
+
SOKOL_SHAPE_API_DECL uint32_t sshape_color_3f(float r, float g, float b);
|
|
559
|
+
SOKOL_SHAPE_API_DECL uint32_t sshape_color_4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
|
560
|
+
SOKOL_SHAPE_API_DECL uint32_t sshape_color_3b(uint8_t r, uint8_t g, uint8_t b);
|
|
561
|
+
|
|
562
|
+
// adapter function for filling matrix struct from generic float[16] array
|
|
563
|
+
SOKOL_SHAPE_API_DECL sshape_mat4_t sshape_mat4(const float m[16]);
|
|
564
|
+
SOKOL_SHAPE_API_DECL sshape_mat4_t sshape_mat4_transpose(const float m[16]);
|
|
565
|
+
|
|
566
|
+
#ifdef __cplusplus
|
|
567
|
+
} // extern "C"
|
|
568
|
+
|
|
569
|
+
// FIXME: C++ helper functions
|
|
570
|
+
|
|
571
|
+
#endif
|
|
572
|
+
#endif // SOKOL_SHAPE_INCLUDED
|
|
573
|
+
|
|
574
|
+
/*-- IMPLEMENTATION ----------------------------------------------------------*/
|
|
575
|
+
#ifdef SOKOL_SHAPE_IMPL
|
|
576
|
+
#define SOKOL_SHAPE_IMPL_INCLUDED (1)
|
|
577
|
+
|
|
578
|
+
#include <string.h> // memcpy
|
|
579
|
+
#include <math.h> // sinf, cosf
|
|
580
|
+
|
|
581
|
+
#ifdef __clang__
|
|
582
|
+
#pragma clang diagnostic push
|
|
583
|
+
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
|
584
|
+
#endif
|
|
585
|
+
|
|
586
|
+
#ifndef SOKOL_API_IMPL
|
|
587
|
+
#define SOKOL_API_IMPL
|
|
588
|
+
#endif
|
|
589
|
+
#ifndef SOKOL_ASSERT
|
|
590
|
+
#include <assert.h>
|
|
591
|
+
#define SOKOL_ASSERT(c) assert(c)
|
|
592
|
+
#endif
|
|
593
|
+
|
|
594
|
+
#define _sshape_def(val, def) (((val) == 0) ? (def) : (val))
|
|
595
|
+
#define _sshape_def_flt(val, def) (((val) == 0.0f) ? (def) : (val))
|
|
596
|
+
#define _sshape_white (0xFFFFFFFF)
|
|
597
|
+
|
|
598
|
+
typedef struct { float x, y, z, w; } _sshape_vec4_t;
|
|
599
|
+
typedef struct { float x, y; } _sshape_vec2_t;
|
|
600
|
+
|
|
601
|
+
static inline float _sshape_clamp(float v) {
|
|
602
|
+
if (v < 0.0f) return 0.0f;
|
|
603
|
+
else if (v > 1.0f) return 1.0f;
|
|
604
|
+
else return v;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
static inline uint32_t _sshape_pack_ub4_ubyte4n(uint8_t x, uint8_t y, uint8_t z, uint8_t w) {
|
|
608
|
+
return (uint32_t)(((uint32_t)w<<24)|((uint32_t)z<<16)|((uint32_t)y<<8)|x);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
static inline uint32_t _sshape_pack_f4_ubyte4n(float x, float y, float z, float w) {
|
|
612
|
+
uint8_t x8 = (uint8_t) (x * 255.0f);
|
|
613
|
+
uint8_t y8 = (uint8_t) (y * 255.0f);
|
|
614
|
+
uint8_t z8 = (uint8_t) (z * 255.0f);
|
|
615
|
+
uint8_t w8 = (uint8_t) (w * 255.0f);
|
|
616
|
+
return _sshape_pack_ub4_ubyte4n(x8, y8, z8, w8);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
static inline uint32_t _sshape_pack_f4_byte4n(float x, float y, float z, float w) {
|
|
620
|
+
int8_t x8 = (int8_t) (x * 127.0f);
|
|
621
|
+
int8_t y8 = (int8_t) (y * 127.0f);
|
|
622
|
+
int8_t z8 = (int8_t) (z * 127.0f);
|
|
623
|
+
int8_t w8 = (int8_t) (w * 127.0f);
|
|
624
|
+
return _sshape_pack_ub4_ubyte4n((uint8_t)x8, (uint8_t)y8, (uint8_t)z8, (uint8_t)w8);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
static inline uint16_t _sshape_pack_f_ushortn(float x) {
|
|
628
|
+
return (uint16_t) (x * 65535.0f);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
static inline _sshape_vec4_t _sshape_vec4(float x, float y, float z, float w) {
|
|
632
|
+
_sshape_vec4_t v = { x, y, z, w };
|
|
633
|
+
return v;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
static inline _sshape_vec4_t _sshape_vec4_norm(_sshape_vec4_t v) {
|
|
637
|
+
float l = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
|
|
638
|
+
if (l != 0.0f) {
|
|
639
|
+
return _sshape_vec4(v.x/l, v.y/l, v.z/l, v.w/l);
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
return _sshape_vec4(0.0f, 1.0f, 0.0f, 0.0f);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
static inline _sshape_vec2_t _sshape_vec2(float x, float y) {
|
|
647
|
+
_sshape_vec2_t v = { x, y };
|
|
648
|
+
return v;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
static bool _sshape_mat4_isnull(const sshape_mat4_t* m) {
|
|
652
|
+
for (int y = 0; y < 4; y++) {
|
|
653
|
+
for (int x = 0; x < 4; x++) {
|
|
654
|
+
if (0.0f != m->m[y][x]) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
static sshape_mat4_t _sshape_mat4_identity(void) {
|
|
663
|
+
sshape_mat4_t m = {
|
|
664
|
+
{
|
|
665
|
+
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
|
666
|
+
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
|
667
|
+
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
|
668
|
+
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
return m;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
static _sshape_vec4_t _sshape_mat4_mul(const sshape_mat4_t* m, _sshape_vec4_t v) {
|
|
675
|
+
_sshape_vec4_t res = {
|
|
676
|
+
m->m[0][0]*v.x + m->m[1][0]*v.y + m->m[2][0]*v.z + m->m[3][0]*v.w,
|
|
677
|
+
m->m[0][1]*v.x + m->m[1][1]*v.y + m->m[2][1]*v.z + m->m[3][1]*v.w,
|
|
678
|
+
m->m[0][2]*v.x + m->m[1][2]*v.y + m->m[2][2]*v.z + m->m[3][2]*v.w,
|
|
679
|
+
m->m[0][3]*v.x + m->m[1][3]*v.y + m->m[2][3]*v.z + m->m[3][3]*v.w
|
|
680
|
+
};
|
|
681
|
+
return res;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
static uint32_t _sshape_plane_num_vertices(uint32_t tiles) {
|
|
685
|
+
return (tiles + 1) * (tiles + 1);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
static uint32_t _sshape_plane_num_indices(uint32_t tiles) {
|
|
689
|
+
return tiles * tiles * 2 * 3;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
static uint32_t _sshape_box_num_vertices(uint32_t tiles) {
|
|
693
|
+
return (tiles + 1) * (tiles + 1) * 6;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
static uint32_t _sshape_box_num_indices(uint32_t tiles) {
|
|
697
|
+
return tiles * tiles * 2 * 6 * 3;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
static uint32_t _sshape_sphere_num_vertices(uint32_t slices, uint32_t stacks) {
|
|
701
|
+
return (slices + 1) * (stacks + 1);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
static uint32_t _sshape_sphere_num_indices(uint32_t slices, uint32_t stacks) {
|
|
705
|
+
return ((2 * slices * stacks) - (2 * slices)) * 3;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
static uint32_t _sshape_cylinder_num_vertices(uint32_t slices, uint32_t stacks) {
|
|
709
|
+
return (slices + 1) * (stacks + 5);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
static uint32_t _sshape_cylinder_num_indices(uint32_t slices, uint32_t stacks) {
|
|
713
|
+
return ((2 * slices * stacks) + (2 * slices)) * 3;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
static uint32_t _sshape_torus_num_vertices(uint32_t sides, uint32_t rings) {
|
|
717
|
+
return (sides + 1) * (rings + 1);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
static uint32_t _sshape_torus_num_indices(uint32_t sides, uint32_t rings) {
|
|
721
|
+
return sides * rings * 2 * 3;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
static bool _sshape_validate_buffer_state(const sshape_buffer_state_t* state, uint32_t build_size) {
|
|
725
|
+
if (0 == state->buffer.ptr) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
if (0 == state->buffer.size) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
if ((state->data_size + build_size) > state->buffer.size) {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
if (state->shape_offset > state->data_size) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
static uint32_t _sshape_vertex_size(bool has_normals, bool has_texcoords, bool has_colors) {
|
|
741
|
+
uint32_t s = 3 * (uint32_t)sizeof(float);
|
|
742
|
+
if (has_normals) {
|
|
743
|
+
s += (uint32_t)sizeof(uint32_t);
|
|
744
|
+
}
|
|
745
|
+
if (has_texcoords) {
|
|
746
|
+
s += 2 * (uint32_t)sizeof(uint16_t);
|
|
747
|
+
}
|
|
748
|
+
if (has_colors) {
|
|
749
|
+
s += (uint32_t)sizeof(uint32_t);
|
|
750
|
+
}
|
|
751
|
+
return s;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
static int _sshape_vertex_position_offset(const sshape_state_t* state) {
|
|
755
|
+
(void)state;
|
|
756
|
+
return 0;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
static int _sshape_vertex_normal_offset(const sshape_state_t* state) {
|
|
760
|
+
SOKOL_ASSERT(!state->disable.normals); (void)state;
|
|
761
|
+
return (int)(3 * sizeof(float));
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
static int _sshape_vertex_texcoord_offset(const sshape_state_t* state) {
|
|
765
|
+
SOKOL_ASSERT(!state->disable.texcoords);
|
|
766
|
+
int offset = 3 * sizeof(float);
|
|
767
|
+
if (!state->disable.normals) {
|
|
768
|
+
offset += (int)sizeof(uint32_t);
|
|
769
|
+
}
|
|
770
|
+
return offset;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
static int _sshape_vertex_color_offset(const sshape_state_t* state) {
|
|
774
|
+
SOKOL_ASSERT(!state->disable.colors);
|
|
775
|
+
int offset = 3 * sizeof(float);
|
|
776
|
+
if (!state->disable.normals) {
|
|
777
|
+
offset += (int)sizeof(uint32_t);
|
|
778
|
+
}
|
|
779
|
+
if (!state->disable.texcoords) {
|
|
780
|
+
offset += (int)(2 * sizeof(uint16_t));
|
|
781
|
+
}
|
|
782
|
+
return offset;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
static uint32_t _sshape_vertex_size_from_state(const sshape_state_t* state) {
|
|
786
|
+
const bool has_normals = !state->disable.normals;
|
|
787
|
+
const bool has_texcoords = !state->disable.texcoords;
|
|
788
|
+
const bool has_colors = !state->disable.colors;
|
|
789
|
+
return _sshape_vertex_size(has_normals, has_texcoords, has_colors);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
static bool _sshape_validate_state(const sshape_state_t* state, uint32_t num_vertices, uint32_t num_indices) {
|
|
793
|
+
const uint32_t vertex_size = (uint32_t)_sshape_vertex_size_from_state(state);
|
|
794
|
+
if (!_sshape_validate_buffer_state(&state->vertices, num_vertices * vertex_size)) {
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
if (!_sshape_validate_buffer_state(&state->indices, num_indices * sizeof(uint16_t))) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
static void _sshape_advance_offset(sshape_buffer_state_t* state) {
|
|
804
|
+
state->shape_offset = state->data_size;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
static uint16_t _sshape_base_index(const sshape_state_t* state) {
|
|
808
|
+
const size_t vertex_size = _sshape_vertex_size_from_state(state);
|
|
809
|
+
const size_t base_index = state->vertices.data_size / vertex_size;
|
|
810
|
+
SOKOL_ASSERT(base_index <= 0xFFFF);
|
|
811
|
+
return (uint16_t)base_index;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
static sshape_plane_t _sshape_plane_defaults(const sshape_plane_t* params) {
|
|
815
|
+
sshape_plane_t res = *params;
|
|
816
|
+
res.width = _sshape_def_flt(res.width, 1.0f);
|
|
817
|
+
res.depth = _sshape_def_flt(res.depth, 1.0f);
|
|
818
|
+
res.tiles = _sshape_def(res.tiles, 1);
|
|
819
|
+
res.color = _sshape_def(res.color, _sshape_white);
|
|
820
|
+
res.transform = _sshape_mat4_isnull(&res.transform) ? _sshape_mat4_identity() : res.transform;
|
|
821
|
+
return res;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
static sshape_box_t _sshape_box_defaults(const sshape_box_t* params) {
|
|
825
|
+
sshape_box_t res = *params;
|
|
826
|
+
res.width = _sshape_def_flt(res.width, 1.0f);
|
|
827
|
+
res.height = _sshape_def_flt(res.height, 1.0f);
|
|
828
|
+
res.depth = _sshape_def_flt(res.depth, 1.0f);
|
|
829
|
+
res.tiles = _sshape_def(res.tiles, 1);
|
|
830
|
+
res.color = _sshape_def(res.color, _sshape_white);
|
|
831
|
+
res.transform = _sshape_mat4_isnull(&res.transform) ? _sshape_mat4_identity() : res.transform;
|
|
832
|
+
return res;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
static sshape_sphere_t _sshape_sphere_defaults(const sshape_sphere_t* params) {
|
|
836
|
+
sshape_sphere_t res = *params;
|
|
837
|
+
res.radius = _sshape_def_flt(res.radius, 0.5f);
|
|
838
|
+
res.slices = _sshape_def(res.slices, 5);
|
|
839
|
+
res.stacks = _sshape_def(res.stacks, 4);
|
|
840
|
+
res.color = _sshape_def(res.color, _sshape_white);
|
|
841
|
+
res.transform = _sshape_mat4_isnull(&res.transform) ? _sshape_mat4_identity() : res.transform;
|
|
842
|
+
return res;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
static sshape_cylinder_t _sshape_cylinder_defaults(const sshape_cylinder_t* params) {
|
|
846
|
+
sshape_cylinder_t res = *params;
|
|
847
|
+
res.radius = _sshape_def_flt(res.radius, 0.5f);
|
|
848
|
+
res.height = _sshape_def_flt(res.height, 1.0f);
|
|
849
|
+
res.slices = _sshape_def(res.slices, 5);
|
|
850
|
+
res.stacks = _sshape_def(res.stacks, 1);
|
|
851
|
+
res.color = _sshape_def(res.color, _sshape_white);
|
|
852
|
+
res.transform = _sshape_mat4_isnull(&res.transform) ? _sshape_mat4_identity() : res.transform;
|
|
853
|
+
return res;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
static sshape_torus_t _sshape_torus_defaults(const sshape_torus_t* params) {
|
|
857
|
+
sshape_torus_t res = *params;
|
|
858
|
+
res.radius = _sshape_def_flt(res.radius, 0.5f);
|
|
859
|
+
res.ring_radius = _sshape_def_flt(res.ring_radius, 0.2f);
|
|
860
|
+
res.sides = _sshape_def(res.sides, 5);
|
|
861
|
+
res.rings = _sshape_def(res.rings, 5);
|
|
862
|
+
res.color = _sshape_def(res.color, _sshape_white);
|
|
863
|
+
res.transform = _sshape_mat4_isnull(&res.transform) ? _sshape_mat4_identity() : res.transform;
|
|
864
|
+
return res;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
static void _sshape_add_vertex(sshape_state_t* state, _sshape_vec4_t pos, _sshape_vec4_t norm, _sshape_vec2_t uv, uint32_t color) {
|
|
868
|
+
size_t offset = state->vertices.data_size;
|
|
869
|
+
const size_t vertex_size = _sshape_vertex_size_from_state(state);
|
|
870
|
+
SOKOL_ASSERT((offset + vertex_size) <= state->vertices.buffer.size);
|
|
871
|
+
state->vertices.data_size += vertex_size;
|
|
872
|
+
uint8_t* dst_ptr = (uint8_t*)state->vertices.buffer.ptr + offset;
|
|
873
|
+
*(float*)dst_ptr = pos.x; dst_ptr += sizeof(float);
|
|
874
|
+
*(float*)dst_ptr = pos.y; dst_ptr += sizeof(float);
|
|
875
|
+
*(float*)dst_ptr = pos.z; dst_ptr += sizeof(float);
|
|
876
|
+
if (!state->disable.normals) {
|
|
877
|
+
*(uint32_t*)dst_ptr = _sshape_pack_f4_byte4n(norm.x, norm.y, norm.z, norm.w); dst_ptr += sizeof(uint32_t);
|
|
878
|
+
}
|
|
879
|
+
if (!state->disable.texcoords) {
|
|
880
|
+
*(uint16_t*)dst_ptr = _sshape_pack_f_ushortn(uv.x); dst_ptr += sizeof(uint16_t);
|
|
881
|
+
*(uint16_t*)dst_ptr = _sshape_pack_f_ushortn(uv.y); dst_ptr += sizeof(uint16_t);
|
|
882
|
+
}
|
|
883
|
+
if (!state->disable.colors) {
|
|
884
|
+
*(uint32_t*)dst_ptr = color; dst_ptr += sizeof(uint32_t);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
static void _sshape_add_triangle(sshape_state_t* state, uint16_t i0, uint16_t i1, uint16_t i2) {
|
|
889
|
+
size_t offset = state->indices.data_size;
|
|
890
|
+
SOKOL_ASSERT((offset + 3*sizeof(uint16_t)) <= state->indices.buffer.size);
|
|
891
|
+
state->indices.data_size += 3*sizeof(uint16_t);
|
|
892
|
+
uint16_t* i_ptr = (uint16_t*) ((uint8_t*)state->indices.buffer.ptr + offset);
|
|
893
|
+
i_ptr[0] = i0;
|
|
894
|
+
i_ptr[1] = i1;
|
|
895
|
+
i_ptr[2] = i2;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
static uint32_t _sshape_rand_color(uint32_t* xorshift_state) {
|
|
899
|
+
// xorshift32
|
|
900
|
+
uint32_t x = *xorshift_state;
|
|
901
|
+
x ^= x<<13;
|
|
902
|
+
x ^= x>>17;
|
|
903
|
+
x ^= x<<5;
|
|
904
|
+
*xorshift_state = x;
|
|
905
|
+
|
|
906
|
+
// rand => bright color with alpha 1.0
|
|
907
|
+
x |= 0xFF000000;
|
|
908
|
+
return x;
|
|
909
|
+
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/*=== PUBLIC API FUNCTIONS ===================================================*/
|
|
913
|
+
SOKOL_API_IMPL uint32_t sshape_color_4f(float r, float g, float b, float a) {
|
|
914
|
+
return _sshape_pack_f4_ubyte4n(_sshape_clamp(r), _sshape_clamp(g), _sshape_clamp(b), _sshape_clamp(a));
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
SOKOL_API_IMPL uint32_t sshape_color_3f(float r, float g, float b) {
|
|
918
|
+
return _sshape_pack_f4_ubyte4n(_sshape_clamp(r), _sshape_clamp(g), _sshape_clamp(b), 1.0f);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
SOKOL_API_IMPL uint32_t sshape_color_4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
|
922
|
+
return _sshape_pack_ub4_ubyte4n(r, g, b, a);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
SOKOL_API_IMPL uint32_t sshape_color_3b(uint8_t r, uint8_t g, uint8_t b) {
|
|
926
|
+
return _sshape_pack_ub4_ubyte4n(r, g, b, 255);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
SOKOL_API_IMPL sshape_mat4_t sshape_mat4(const float m[16]) {
|
|
930
|
+
sshape_mat4_t res;
|
|
931
|
+
memcpy(&res.m[0][0], &m[0], 64);
|
|
932
|
+
return res;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
SOKOL_API_IMPL sshape_mat4_t sshape_mat4_transpose(const float m[16]) {
|
|
936
|
+
sshape_mat4_t res;
|
|
937
|
+
for (int c = 0; c < 4; c++) {
|
|
938
|
+
for (int r = 0; r < 4; r++) {
|
|
939
|
+
res.m[r][c] = m[c*4 + r];
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return res;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
SOKOL_API_IMPL size_t sshape_vertex_size(const sshape_optional_components_t* comps) {
|
|
946
|
+
SOKOL_ASSERT(comps);
|
|
947
|
+
return _sshape_vertex_size(comps->normals, comps->texcoords, comps->colors);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
SOKOL_API_IMPL sshape_sizes_t sshape_plane_sizes(uint32_t tiles, size_t vertex_size) {
|
|
951
|
+
SOKOL_ASSERT(tiles >= 1);
|
|
952
|
+
SOKOL_ASSERT((vertex_size >= SSHAPE_MIN_VERTEX_SIZE) && (vertex_size <= SSHAPE_MAX_VERTEX_SIZE));
|
|
953
|
+
sshape_sizes_t res = { {0} };
|
|
954
|
+
res.vertices.num = _sshape_plane_num_vertices(tiles);
|
|
955
|
+
res.indices.num = _sshape_plane_num_indices(tiles);
|
|
956
|
+
res.vertices.size = res.vertices.num * (uint32_t)vertex_size;
|
|
957
|
+
res.indices.size = res.indices.num * sizeof(uint16_t);
|
|
958
|
+
return res;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
SOKOL_API_IMPL sshape_sizes_t sshape_box_sizes(uint32_t tiles, size_t vertex_size) {
|
|
962
|
+
SOKOL_ASSERT(tiles >= 1);
|
|
963
|
+
SOKOL_ASSERT((vertex_size >= SSHAPE_MIN_VERTEX_SIZE) && (vertex_size <= SSHAPE_MAX_VERTEX_SIZE));
|
|
964
|
+
sshape_sizes_t res = { {0} };
|
|
965
|
+
res.vertices.num = _sshape_box_num_vertices(tiles);
|
|
966
|
+
res.indices.num = _sshape_box_num_indices(tiles);
|
|
967
|
+
res.vertices.size = res.vertices.num * (uint32_t)vertex_size;
|
|
968
|
+
res.indices.size = res.indices.num * sizeof(uint16_t);
|
|
969
|
+
return res;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
SOKOL_API_IMPL sshape_sizes_t sshape_sphere_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size) {
|
|
973
|
+
SOKOL_ASSERT((slices >= 3) && (stacks >= 2));
|
|
974
|
+
SOKOL_ASSERT((vertex_size >= SSHAPE_MIN_VERTEX_SIZE) && (vertex_size <= SSHAPE_MAX_VERTEX_SIZE));
|
|
975
|
+
sshape_sizes_t res = { {0} };
|
|
976
|
+
res.vertices.num = _sshape_sphere_num_vertices(slices, stacks);
|
|
977
|
+
res.indices.num = _sshape_sphere_num_indices(slices, stacks);
|
|
978
|
+
res.vertices.size = res.vertices.num * (uint32_t)vertex_size;
|
|
979
|
+
res.indices.size = res.indices.num * sizeof(uint16_t);
|
|
980
|
+
return res;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
SOKOL_API_IMPL sshape_sizes_t sshape_cylinder_sizes(uint32_t slices, uint32_t stacks, size_t vertex_size) {
|
|
984
|
+
SOKOL_ASSERT((slices >= 3) && (stacks >= 1));
|
|
985
|
+
SOKOL_ASSERT((vertex_size >= SSHAPE_MIN_VERTEX_SIZE) && (vertex_size <= SSHAPE_MAX_VERTEX_SIZE));
|
|
986
|
+
sshape_sizes_t res = { {0} };
|
|
987
|
+
res.vertices.num = _sshape_cylinder_num_vertices(slices, stacks);
|
|
988
|
+
res.indices.num = _sshape_cylinder_num_indices(slices, stacks);
|
|
989
|
+
res.vertices.size = res.vertices.num * (uint32_t)vertex_size;
|
|
990
|
+
res.indices.size = res.indices.num * sizeof(uint16_t);
|
|
991
|
+
return res;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
SOKOL_API_IMPL sshape_sizes_t sshape_torus_sizes(uint32_t sides, uint32_t rings, size_t vertex_size) {
|
|
995
|
+
SOKOL_ASSERT((sides >= 3) && (rings >= 3));
|
|
996
|
+
SOKOL_ASSERT((vertex_size >= SSHAPE_MIN_VERTEX_SIZE) && (vertex_size <= SSHAPE_MAX_VERTEX_SIZE));
|
|
997
|
+
sshape_sizes_t res = { {0} };
|
|
998
|
+
res.vertices.num = _sshape_torus_num_vertices(sides, rings);
|
|
999
|
+
res.indices.num = _sshape_torus_num_indices(sides, rings);
|
|
1000
|
+
res.vertices.size = res.vertices.num * (uint32_t)vertex_size;
|
|
1001
|
+
res.indices.size = res.indices.num * sizeof(uint16_t);
|
|
1002
|
+
return res;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/*
|
|
1006
|
+
Geometry layout for plane (4 tiles):
|
|
1007
|
+
+--+--+--+--+
|
|
1008
|
+
|\ |\ |\ |\ |
|
|
1009
|
+
| \| \| \| \|
|
|
1010
|
+
+--+--+--+--+ 25 vertices (tiles + 1) * (tiles + 1)
|
|
1011
|
+
|\ |\ |\ |\ | 32 triangles (tiles + 1) * (tiles + 1) * 2
|
|
1012
|
+
| \| \| \| \|
|
|
1013
|
+
+--+--+--+--+
|
|
1014
|
+
|\ |\ |\ |\ |
|
|
1015
|
+
| \| \| \| \|
|
|
1016
|
+
+--+--+--+--+
|
|
1017
|
+
|\ |\ |\ |\ |
|
|
1018
|
+
| \| \| \| \|
|
|
1019
|
+
+--+--+--+--+
|
|
1020
|
+
*/
|
|
1021
|
+
SOKOL_API_IMPL void sshape_build_plane(sshape_state_t* state, const sshape_plane_t* in_params) {
|
|
1022
|
+
SOKOL_ASSERT(state && in_params);
|
|
1023
|
+
const sshape_plane_t params = _sshape_plane_defaults(in_params);
|
|
1024
|
+
const uint32_t num_vertices = _sshape_plane_num_vertices(params.tiles);
|
|
1025
|
+
const uint32_t num_indices = _sshape_plane_num_indices(params.tiles);
|
|
1026
|
+
if (!_sshape_validate_state(state, num_vertices, num_indices)) {
|
|
1027
|
+
state->valid = false;
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
state->valid = true;
|
|
1031
|
+
const uint16_t start_index = _sshape_base_index(state);
|
|
1032
|
+
if (!params.merge) {
|
|
1033
|
+
_sshape_advance_offset(&state->vertices);
|
|
1034
|
+
_sshape_advance_offset(&state->indices);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// write vertices
|
|
1038
|
+
uint32_t rand_seed = 0x12345678;
|
|
1039
|
+
const float x0 = -params.width * 0.5f;
|
|
1040
|
+
const float z0 = params.depth * 0.5f;
|
|
1041
|
+
const float dx = params.width / params.tiles;
|
|
1042
|
+
const float dz = -params.depth / params.tiles;
|
|
1043
|
+
const float duv = 1.0f / params.tiles;
|
|
1044
|
+
_sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, _sshape_vec4(0.0f, 1.0f, 0.0f, 0.0f)));
|
|
1045
|
+
for (uint32_t ix = 0; ix <= params.tiles; ix++) {
|
|
1046
|
+
for (uint32_t iz = 0; iz <= params.tiles; iz++) {
|
|
1047
|
+
const _sshape_vec4_t pos = _sshape_vec4(x0 + dx*ix, 0.0f, z0 + dz*iz, 1.0f);
|
|
1048
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1049
|
+
const _sshape_vec2_t uv = _sshape_vec2(duv*ix, duv*iz);
|
|
1050
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1051
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// write indices
|
|
1056
|
+
for (uint16_t j = 0; j < params.tiles; j++) {
|
|
1057
|
+
for (uint16_t i = 0; i < params.tiles; i++) {
|
|
1058
|
+
const uint16_t i0 = start_index + (j * (params.tiles + 1)) + i;
|
|
1059
|
+
const uint16_t i1 = i0 + 1;
|
|
1060
|
+
const uint16_t i2 = i0 + params.tiles + 1;
|
|
1061
|
+
const uint16_t i3 = i2 + 1;
|
|
1062
|
+
_sshape_add_triangle(state, i0, i1, i3);
|
|
1063
|
+
_sshape_add_triangle(state, i0, i3, i2);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
SOKOL_API_IMPL void sshape_build_box(sshape_state_t* state, const sshape_box_t* in_params) {
|
|
1069
|
+
SOKOL_ASSERT(state && in_params);
|
|
1070
|
+
const sshape_box_t params = _sshape_box_defaults(in_params);
|
|
1071
|
+
const uint32_t num_vertices = _sshape_box_num_vertices(params.tiles);
|
|
1072
|
+
const uint32_t num_indices = _sshape_box_num_indices(params.tiles);
|
|
1073
|
+
if (!_sshape_validate_state(state, num_vertices, num_indices)) {
|
|
1074
|
+
state->valid = false;
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
state->valid = true;
|
|
1078
|
+
const uint16_t start_index = _sshape_base_index(state);
|
|
1079
|
+
if (!params.merge) {
|
|
1080
|
+
_sshape_advance_offset(&state->vertices);
|
|
1081
|
+
_sshape_advance_offset(&state->indices);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// build vertices
|
|
1085
|
+
uint32_t rand_seed = 0x12345678;
|
|
1086
|
+
const float x0 = -params.width * 0.5f;
|
|
1087
|
+
const float x1 = params.width * 0.5f;
|
|
1088
|
+
const float y0 = -params.height * 0.5f;
|
|
1089
|
+
const float y1 = params.height * 0.5f;
|
|
1090
|
+
const float z0 = -params.depth * 0.5f;
|
|
1091
|
+
const float z1 = params.depth * 0.5f;
|
|
1092
|
+
const float dx = params.width / params.tiles;
|
|
1093
|
+
const float dy = params.height / params.tiles;
|
|
1094
|
+
const float dz = params.depth / params.tiles;
|
|
1095
|
+
const float duv = 1.0f / params.tiles;
|
|
1096
|
+
|
|
1097
|
+
// bottom/top vertices
|
|
1098
|
+
for (uint32_t top_bottom = 0; top_bottom < 2; top_bottom++) {
|
|
1099
|
+
_sshape_vec4_t pos = _sshape_vec4(0.0f, (0==top_bottom) ? y0:y1, 0.0f, 1.0f);
|
|
1100
|
+
const _sshape_vec4_t norm = _sshape_vec4(0.0f, (0==top_bottom) ? -1.0f:1.0f, 0.0f, 0.0f);
|
|
1101
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1102
|
+
for (uint32_t ix = 0; ix <= params.tiles; ix++) {
|
|
1103
|
+
pos.x = (0==top_bottom) ? (x0 + dx * ix) : (x1 - dx * ix);
|
|
1104
|
+
for (uint32_t iz = 0; iz <= params.tiles; iz++) {
|
|
1105
|
+
pos.z = z0 + dz * iz;
|
|
1106
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1107
|
+
const _sshape_vec2_t uv = _sshape_vec2(ix * duv, iz * duv);
|
|
1108
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1109
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// left/right vertices
|
|
1115
|
+
for (uint32_t left_right = 0; left_right < 2; left_right++) {
|
|
1116
|
+
_sshape_vec4_t pos = _sshape_vec4((0==left_right) ? x0:x1, 0.0f, 0.0f, 1.0f);
|
|
1117
|
+
const _sshape_vec4_t norm = _sshape_vec4((0==left_right) ? -1.0f:1.0f, 0.0f, 0.0f, 0.0f);
|
|
1118
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1119
|
+
for (uint32_t iy = 0; iy <= params.tiles; iy++) {
|
|
1120
|
+
pos.y = (0==left_right) ? (y1 - dy * iy) : (y0 + dy * iy);
|
|
1121
|
+
for (uint32_t iz = 0; iz <= params.tiles; iz++) {
|
|
1122
|
+
pos.z = z0 + dz * iz;
|
|
1123
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1124
|
+
const _sshape_vec2_t uv = _sshape_vec2(iy * duv, iz * duv);
|
|
1125
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1126
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// front/back vertices
|
|
1132
|
+
for (uint32_t front_back = 0; front_back < 2; front_back++) {
|
|
1133
|
+
_sshape_vec4_t pos = _sshape_vec4(0.0f, 0.0f, (0==front_back) ? z0:z1, 1.0f);
|
|
1134
|
+
const _sshape_vec4_t norm = _sshape_vec4(0.0f, 0.0f, (0==front_back) ? -1.0f:1.0f, 0.0f);
|
|
1135
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1136
|
+
for (uint32_t ix = 0; ix <= params.tiles; ix++) {
|
|
1137
|
+
pos.x = (0==front_back) ? (x1 - dx * ix) : (x0 + dx * ix);
|
|
1138
|
+
for (uint32_t iy = 0; iy <= params.tiles; iy++) {
|
|
1139
|
+
pos.y = y0 + dy * iy;
|
|
1140
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1141
|
+
const _sshape_vec2_t uv = _sshape_vec2(ix * duv, iy * duv);
|
|
1142
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1143
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
// build indices
|
|
1149
|
+
const uint16_t verts_per_face = (params.tiles + 1) * (params.tiles + 1);
|
|
1150
|
+
for (uint16_t face = 0; face < 6; face++) {
|
|
1151
|
+
uint16_t face_start_index = start_index + face * verts_per_face;
|
|
1152
|
+
for (uint16_t j = 0; j < params.tiles; j++) {
|
|
1153
|
+
for (uint16_t i = 0; i < params.tiles; i++) {
|
|
1154
|
+
const uint16_t i0 = face_start_index + (j * (params.tiles + 1)) + i;
|
|
1155
|
+
const uint16_t i1 = i0 + 1;
|
|
1156
|
+
const uint16_t i2 = i0 + params.tiles + 1;
|
|
1157
|
+
const uint16_t i3 = i2 + 1;
|
|
1158
|
+
_sshape_add_triangle(state, i0, i1, i3);
|
|
1159
|
+
_sshape_add_triangle(state, i0, i3, i2);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/*
|
|
1166
|
+
Geometry layout for spheres is as follows (for 5 slices, 4 stacks):
|
|
1167
|
+
|
|
1168
|
+
+ + + + + + north pole
|
|
1169
|
+
|\ |\ |\ |\ |\
|
|
1170
|
+
| \| \| \| \| \
|
|
1171
|
+
+--+--+--+--+--+ 30 vertices (slices + 1) * (stacks + 1)
|
|
1172
|
+
|\ |\ |\ |\ |\ | 30 triangles (2 * slices * stacks) - (2 * slices)
|
|
1173
|
+
| \| \| \| \| \| 2 orphaned vertices
|
|
1174
|
+
+--+--+--+--+--+
|
|
1175
|
+
|\ |\ |\ |\ |\ |
|
|
1176
|
+
| \| \| \| \| \|
|
|
1177
|
+
+--+--+--+--+--+
|
|
1178
|
+
\ |\ |\ |\ |\ |
|
|
1179
|
+
\| \| \| \| \|
|
|
1180
|
+
+ + + + + + south pole
|
|
1181
|
+
*/
|
|
1182
|
+
SOKOL_API_IMPL void sshape_build_sphere(sshape_state_t* state, const sshape_sphere_t* in_params) {
|
|
1183
|
+
SOKOL_ASSERT(state && in_params);
|
|
1184
|
+
const sshape_sphere_t params = _sshape_sphere_defaults(in_params);
|
|
1185
|
+
const uint32_t num_vertices = _sshape_sphere_num_vertices(params.slices, params.stacks);
|
|
1186
|
+
const uint32_t num_indices = _sshape_sphere_num_indices(params.slices, params.stacks);
|
|
1187
|
+
if (!_sshape_validate_state(state, num_vertices, num_indices)) {
|
|
1188
|
+
state->valid = false;
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
state->valid = true;
|
|
1192
|
+
const uint16_t start_index = _sshape_base_index(state);
|
|
1193
|
+
if (!params.merge) {
|
|
1194
|
+
_sshape_advance_offset(&state->vertices);
|
|
1195
|
+
_sshape_advance_offset(&state->indices);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
uint32_t rand_seed = 0x12345678;
|
|
1199
|
+
const float pi = 3.14159265358979323846f;
|
|
1200
|
+
const float two_pi = 2.0f * pi;
|
|
1201
|
+
const float du = 1.0f / params.slices;
|
|
1202
|
+
const float dv = 1.0f / params.stacks;
|
|
1203
|
+
|
|
1204
|
+
// generate vertices
|
|
1205
|
+
for (uint32_t stack = 0; stack <= params.stacks; stack++) {
|
|
1206
|
+
const float stack_angle = (pi * stack) / params.stacks;
|
|
1207
|
+
const float sin_stack = sinf(stack_angle);
|
|
1208
|
+
const float cos_stack = cosf(stack_angle);
|
|
1209
|
+
for (uint32_t slice = 0; slice <= params.slices; slice++) {
|
|
1210
|
+
const float slice_angle = (two_pi * slice) / params.slices;
|
|
1211
|
+
const float sin_slice = sinf(slice_angle);
|
|
1212
|
+
const float cos_slice = cosf(slice_angle);
|
|
1213
|
+
const _sshape_vec4_t norm = _sshape_vec4(-sin_slice * sin_stack, cos_stack, cos_slice * sin_stack, 0.0f);
|
|
1214
|
+
const _sshape_vec4_t pos = _sshape_vec4(norm.x * params.radius, norm.y * params.radius, norm.z * params.radius, 1.0f);
|
|
1215
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1216
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1217
|
+
const _sshape_vec2_t uv = _sshape_vec2(1.0f - slice * du, 1.0f - stack * dv);
|
|
1218
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1219
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// generate indices
|
|
1224
|
+
{
|
|
1225
|
+
// north-pole triangles
|
|
1226
|
+
const uint16_t row_a = start_index;
|
|
1227
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1228
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1229
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice, row_b + slice + 1);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
// stack triangles
|
|
1233
|
+
for (uint16_t stack = 1; stack < params.stacks - 1; stack++) {
|
|
1234
|
+
const uint16_t row_a = start_index + stack * (params.slices + 1);
|
|
1235
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1236
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1237
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice + 1, row_a + slice + 1);
|
|
1238
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice, row_b + slice + 1);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
{
|
|
1242
|
+
// south-pole triangles
|
|
1243
|
+
const uint16_t row_a = start_index + (params.stacks - 1) * (params.slices + 1);
|
|
1244
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1245
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1246
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice + 1, row_a + slice + 1);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
/*
|
|
1252
|
+
Geometry for cylinders is as follows (2 stacks, 5 slices):
|
|
1253
|
+
|
|
1254
|
+
+ + + + + +
|
|
1255
|
+
|\ |\ |\ |\ |\
|
|
1256
|
+
| \| \| \| \| \
|
|
1257
|
+
+--+--+--+--+--+
|
|
1258
|
+
+--+--+--+--+--+ 42 vertices (2 wasted) (slices + 1) * (stacks + 5)
|
|
1259
|
+
|\ |\ |\ |\ |\ | 30 triangles (2 * slices * stacks) + (2 * slices)
|
|
1260
|
+
| \| \| \| \| \|
|
|
1261
|
+
+--+--+--+--+--+
|
|
1262
|
+
|\ |\ |\ |\ |\ |
|
|
1263
|
+
| \| \| \| \| \|
|
|
1264
|
+
+--+--+--+--+--+
|
|
1265
|
+
+--+--+--+--+--+
|
|
1266
|
+
\ |\ |\ |\ |\ |
|
|
1267
|
+
\| \| \| \| \|
|
|
1268
|
+
+ + + + + +
|
|
1269
|
+
*/
|
|
1270
|
+
static void _sshape_build_cylinder_cap_pole(sshape_state_t* state, const sshape_cylinder_t* params, float pos_y, float norm_y, float du, float v, uint32_t* rand_seed) {
|
|
1271
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms->transform, _sshape_vec4(0.0f, norm_y, 0.0f, 0.0f)));
|
|
1272
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms->transform, _sshape_vec4(0.0f, pos_y, 0.0f, 1.0f));
|
|
1273
|
+
for (uint32_t slice = 0; slice <= params->slices; slice++) {
|
|
1274
|
+
const _sshape_vec2_t uv = _sshape_vec2(slice * du, 1.0f - v);
|
|
1275
|
+
const uint32_t color = params->random_colors ? _sshape_rand_color(rand_seed) : params->color;
|
|
1276
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
static void _sshape_build_cylinder_cap_ring(sshape_state_t* state, const sshape_cylinder_t* params, float pos_y, float norm_y, float du, float v, uint32_t* rand_seed) {
|
|
1281
|
+
const float two_pi = 2.0f * 3.14159265358979323846f;
|
|
1282
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms->transform, _sshape_vec4(0.0f, norm_y, 0.0f, 0.0f)));
|
|
1283
|
+
for (uint32_t slice = 0; slice <= params->slices; slice++) {
|
|
1284
|
+
const float slice_angle = (two_pi * slice) / params->slices;
|
|
1285
|
+
const float sin_slice = sinf(slice_angle);
|
|
1286
|
+
const float cos_slice = cosf(slice_angle);
|
|
1287
|
+
const _sshape_vec4_t pos = _sshape_vec4(sin_slice * params->radius, pos_y, cos_slice * params->radius, 1.0f);
|
|
1288
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms->transform, pos);
|
|
1289
|
+
const _sshape_vec2_t uv = _sshape_vec2(slice * du, 1.0f - v);
|
|
1290
|
+
const uint32_t color = params->random_colors ? _sshape_rand_color(rand_seed) : params->color;
|
|
1291
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
SOKOL_API_IMPL void sshape_build_cylinder(sshape_state_t* state, const sshape_cylinder_t* in_params) {
|
|
1296
|
+
SOKOL_ASSERT(state && in_params);
|
|
1297
|
+
const sshape_cylinder_t params = _sshape_cylinder_defaults(in_params);
|
|
1298
|
+
const uint32_t num_vertices = _sshape_cylinder_num_vertices(params.slices, params.stacks);
|
|
1299
|
+
const uint32_t num_indices = _sshape_cylinder_num_indices(params.slices, params.stacks);
|
|
1300
|
+
if (!_sshape_validate_state(state, num_vertices, num_indices)) {
|
|
1301
|
+
state->valid = false;
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
state->valid = true;
|
|
1305
|
+
const uint16_t start_index = _sshape_base_index(state);
|
|
1306
|
+
if (!params.merge) {
|
|
1307
|
+
_sshape_advance_offset(&state->vertices);
|
|
1308
|
+
_sshape_advance_offset(&state->indices);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
uint32_t rand_seed = 0x12345678;
|
|
1312
|
+
const float two_pi = 2.0f * 3.14159265358979323846f;
|
|
1313
|
+
const float du = 1.0f / params.slices;
|
|
1314
|
+
const float dv = 1.0f / (params.stacks + 2);
|
|
1315
|
+
const float y0 = params.height * 0.5f;
|
|
1316
|
+
const float y1 = -params.height * 0.5f;
|
|
1317
|
+
const float dy = params.height / params.stacks;
|
|
1318
|
+
|
|
1319
|
+
// generate vertices
|
|
1320
|
+
_sshape_build_cylinder_cap_pole(state, ¶ms, y0, 1.0f, du, 0.0f, &rand_seed);
|
|
1321
|
+
_sshape_build_cylinder_cap_ring(state, ¶ms, y0, 1.0f, du, dv, &rand_seed);
|
|
1322
|
+
for (uint32_t stack = 0; stack <= params.stacks; stack++) {
|
|
1323
|
+
const float y = y0 - dy * stack;
|
|
1324
|
+
const float v = dv * stack + dv;
|
|
1325
|
+
for (uint32_t slice = 0; slice <= params.slices; slice++) {
|
|
1326
|
+
const float slice_angle = (two_pi * slice) / params.slices;
|
|
1327
|
+
const float sin_slice = sinf(slice_angle);
|
|
1328
|
+
const float cos_slice = cosf(slice_angle);
|
|
1329
|
+
const _sshape_vec4_t pos = _sshape_vec4(sin_slice * params.radius, y, cos_slice * params.radius, 1.0f);
|
|
1330
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1331
|
+
const _sshape_vec4_t norm = _sshape_vec4(sin_slice, 0.0f, cos_slice, 0.0f);
|
|
1332
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1333
|
+
const _sshape_vec2_t uv = _sshape_vec2(slice * du, 1.0f - v);
|
|
1334
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1335
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
_sshape_build_cylinder_cap_ring(state, ¶ms, y1, -1.0f, du, 1.0f - dv, &rand_seed);
|
|
1339
|
+
_sshape_build_cylinder_cap_pole(state, ¶ms, y1, -1.0f, du, 1.0f, &rand_seed);
|
|
1340
|
+
|
|
1341
|
+
// generate indices
|
|
1342
|
+
{
|
|
1343
|
+
// top-cap indices
|
|
1344
|
+
const uint16_t row_a = start_index;
|
|
1345
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1346
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1347
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice + 1, row_b + slice);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
// shaft triangles
|
|
1351
|
+
for (uint16_t stack = 0; stack < params.stacks; stack++) {
|
|
1352
|
+
const uint16_t row_a = start_index + (stack + 2) * (params.slices + 1);
|
|
1353
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1354
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1355
|
+
_sshape_add_triangle(state, row_a + slice, row_a + slice + 1, row_b + slice + 1);
|
|
1356
|
+
_sshape_add_triangle(state, row_a + slice, row_b + slice + 1, row_b + slice);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
{
|
|
1360
|
+
// bottom-cap indices
|
|
1361
|
+
const uint16_t row_a = start_index + (params.stacks + 3) * (params.slices + 1);
|
|
1362
|
+
const uint16_t row_b = row_a + params.slices + 1;
|
|
1363
|
+
for (uint16_t slice = 0; slice < params.slices; slice++) {
|
|
1364
|
+
_sshape_add_triangle(state, row_a + slice, row_a + slice + 1, row_b + slice + 1);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/*
|
|
1370
|
+
Geometry layout for torus (sides = 4, rings = 5):
|
|
1371
|
+
|
|
1372
|
+
+--+--+--+--+--+
|
|
1373
|
+
|\ |\ |\ |\ |\ |
|
|
1374
|
+
| \| \| \| \| \|
|
|
1375
|
+
+--+--+--+--+--+ 30 vertices (sides + 1) * (rings + 1)
|
|
1376
|
+
|\ |\ |\ |\ |\ | 40 triangles (2 * sides * rings)
|
|
1377
|
+
| \| \| \| \| \|
|
|
1378
|
+
+--+--+--+--+--+
|
|
1379
|
+
|\ |\ |\ |\ |\ |
|
|
1380
|
+
| \| \| \| \| \|
|
|
1381
|
+
+--+--+--+--+--+
|
|
1382
|
+
|\ |\ |\ |\ |\ |
|
|
1383
|
+
| \| \| \| \| \|
|
|
1384
|
+
+--+--+--+--+--+
|
|
1385
|
+
*/
|
|
1386
|
+
SOKOL_API_IMPL void sshape_build_torus(sshape_state_t* state, const sshape_torus_t* in_params) {
|
|
1387
|
+
SOKOL_ASSERT(state && in_params);
|
|
1388
|
+
const sshape_torus_t params = _sshape_torus_defaults(in_params);
|
|
1389
|
+
const uint32_t num_vertices = _sshape_torus_num_vertices(params.sides, params.rings);
|
|
1390
|
+
const uint32_t num_indices = _sshape_torus_num_indices(params.sides, params.rings);
|
|
1391
|
+
if (!_sshape_validate_state(state, num_vertices, num_indices)) {
|
|
1392
|
+
state->valid = false;
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
state->valid = true;
|
|
1396
|
+
const uint16_t start_index = _sshape_base_index(state);
|
|
1397
|
+
if (!params.merge) {
|
|
1398
|
+
_sshape_advance_offset(&state->vertices);
|
|
1399
|
+
_sshape_advance_offset(&state->indices);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
uint32_t rand_seed = 0x12345678;
|
|
1403
|
+
const float two_pi = 2.0f * 3.14159265358979323846f;
|
|
1404
|
+
const float dv = 1.0f / params.sides;
|
|
1405
|
+
const float du = 1.0f / params.rings;
|
|
1406
|
+
|
|
1407
|
+
// generate vertices
|
|
1408
|
+
for (uint32_t side = 0; side <= params.sides; side++) {
|
|
1409
|
+
const float phi = (side * two_pi) / params.sides;
|
|
1410
|
+
const float sin_phi = sinf(phi);
|
|
1411
|
+
const float cos_phi = cosf(phi);
|
|
1412
|
+
for (uint32_t ring = 0; ring <= params.rings; ring++) {
|
|
1413
|
+
const float theta = (ring * two_pi) / params.rings;
|
|
1414
|
+
const float sin_theta = sinf(theta);
|
|
1415
|
+
const float cos_theta = cosf(theta);
|
|
1416
|
+
|
|
1417
|
+
// torus surface position
|
|
1418
|
+
const float spx = sin_theta * (params.radius - (params.ring_radius * cos_phi));
|
|
1419
|
+
const float spy = sin_phi * params.ring_radius;
|
|
1420
|
+
const float spz = cos_theta * (params.radius - (params.ring_radius * cos_phi));
|
|
1421
|
+
|
|
1422
|
+
// torus position with ring-radius zero (for normal computation)
|
|
1423
|
+
const float ipx = sin_theta * params.radius;
|
|
1424
|
+
const float ipy = 0.0f;
|
|
1425
|
+
const float ipz = cos_theta * params.radius;
|
|
1426
|
+
|
|
1427
|
+
const _sshape_vec4_t pos = _sshape_vec4(spx, spy, spz, 1.0f);
|
|
1428
|
+
const _sshape_vec4_t norm = _sshape_vec4(spx - ipx, spy - ipy, spz - ipz, 0.0f);
|
|
1429
|
+
const _sshape_vec4_t tpos = _sshape_mat4_mul(¶ms.transform, pos);
|
|
1430
|
+
const _sshape_vec4_t tnorm = _sshape_vec4_norm(_sshape_mat4_mul(¶ms.transform, norm));
|
|
1431
|
+
const _sshape_vec2_t uv = _sshape_vec2(ring * du, 1.0f - side * dv);
|
|
1432
|
+
const uint32_t color = params.random_colors ? _sshape_rand_color(&rand_seed) : params.color;
|
|
1433
|
+
_sshape_add_vertex(state, tpos, tnorm, uv, color);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// generate indices
|
|
1438
|
+
for (uint16_t side = 0; side < params.sides; side++) {
|
|
1439
|
+
const uint16_t row_a = start_index + side * (params.rings + 1);
|
|
1440
|
+
const uint16_t row_b = row_a + params.rings + 1;
|
|
1441
|
+
for (uint16_t ring = 0; ring < params.rings; ring++) {
|
|
1442
|
+
_sshape_add_triangle(state, row_a + ring, row_a + ring + 1, row_b + ring + 1);
|
|
1443
|
+
_sshape_add_triangle(state, row_a + ring, row_b + ring + 1, row_b + ring);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
SOKOL_API_IMPL sg_buffer_desc sshape_vertex_buffer_desc(const sshape_state_t* state) {
|
|
1449
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1450
|
+
sg_buffer_desc desc = { 0 };
|
|
1451
|
+
if (state->valid) {
|
|
1452
|
+
desc.usage.vertex_buffer = true;
|
|
1453
|
+
desc.data.ptr = state->vertices.buffer.ptr;
|
|
1454
|
+
desc.data.size = state->vertices.data_size;
|
|
1455
|
+
}
|
|
1456
|
+
return desc;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
SOKOL_API_IMPL sg_buffer_desc sshape_index_buffer_desc(const sshape_state_t* state) {
|
|
1460
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1461
|
+
sg_buffer_desc desc = { 0 };
|
|
1462
|
+
if (state->valid) {
|
|
1463
|
+
desc.usage.index_buffer = true;
|
|
1464
|
+
desc.data.ptr = state->indices.buffer.ptr;
|
|
1465
|
+
desc.data.size = state->indices.data_size;
|
|
1466
|
+
}
|
|
1467
|
+
return desc;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
SOKOL_API_IMPL sshape_element_range_t sshape_element_range(const sshape_state_t* state) {
|
|
1471
|
+
SOKOL_ASSERT(state);
|
|
1472
|
+
sshape_element_range_t range = { 0 };
|
|
1473
|
+
if (state->valid) {
|
|
1474
|
+
SOKOL_ASSERT(state->indices.shape_offset < state->indices.data_size);
|
|
1475
|
+
SOKOL_ASSERT(0 == (state->indices.shape_offset & (sizeof(uint16_t) - 1)));
|
|
1476
|
+
SOKOL_ASSERT(0 == (state->indices.data_size & (sizeof(uint16_t) - 1)));
|
|
1477
|
+
range.base_element = (int) (state->indices.shape_offset / sizeof(uint16_t));
|
|
1478
|
+
range.num_elements = (int) ((state->indices.data_size - state->indices.shape_offset) / sizeof(uint16_t));
|
|
1479
|
+
}
|
|
1480
|
+
return range;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
SOKOL_API_IMPL sg_vertex_buffer_layout_state sshape_vertex_buffer_layout_state(const sshape_state_t* state) {
|
|
1484
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1485
|
+
sg_vertex_buffer_layout_state layout_state = { 0 };
|
|
1486
|
+
layout_state.stride = (int)_sshape_vertex_size_from_state(state);
|
|
1487
|
+
return layout_state;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
SOKOL_API_IMPL sg_vertex_attr_state sshape_position_vertex_attr_state(const sshape_state_t* state) {
|
|
1491
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1492
|
+
sg_vertex_attr_state attr_state = { 0 };
|
|
1493
|
+
attr_state.offset = _sshape_vertex_position_offset(state);
|
|
1494
|
+
attr_state.format = SG_VERTEXFORMAT_FLOAT3;
|
|
1495
|
+
return attr_state;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
SOKOL_API_IMPL sg_vertex_attr_state sshape_normal_vertex_attr_state(const sshape_state_t* state) {
|
|
1499
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1500
|
+
sg_vertex_attr_state attr_state = { 0 };
|
|
1501
|
+
if (!state->disable.normals) {
|
|
1502
|
+
attr_state.offset = _sshape_vertex_normal_offset(state);
|
|
1503
|
+
attr_state.format = SG_VERTEXFORMAT_BYTE4N;
|
|
1504
|
+
}
|
|
1505
|
+
return attr_state;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
SOKOL_API_IMPL sg_vertex_attr_state sshape_texcoord_vertex_attr_state(const sshape_state_t* state) {
|
|
1509
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1510
|
+
sg_vertex_attr_state attr_state = { 0 };
|
|
1511
|
+
if (!state->disable.texcoords) {
|
|
1512
|
+
attr_state.offset = _sshape_vertex_texcoord_offset(state);
|
|
1513
|
+
attr_state.format = SG_VERTEXFORMAT_USHORT2N;
|
|
1514
|
+
}
|
|
1515
|
+
return attr_state;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
SOKOL_API_IMPL sg_vertex_attr_state sshape_color_vertex_attr_state(const sshape_state_t* state) {
|
|
1519
|
+
SOKOL_ASSERT(state && state->valid);
|
|
1520
|
+
sg_vertex_attr_state attr_state = { 0 };
|
|
1521
|
+
if (!state->disable.colors) {
|
|
1522
|
+
attr_state.offset = _sshape_vertex_color_offset(state);
|
|
1523
|
+
attr_state.format = SG_VERTEXFORMAT_UBYTE4N;
|
|
1524
|
+
}
|
|
1525
|
+
return attr_state;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
#ifdef __clang__
|
|
1529
|
+
#pragma clang diagnostic pop
|
|
1530
|
+
#endif
|
|
1531
|
+
#endif // SOKOL_SHAPE_IMPL
|