├── .github └── workflows │ ├── main.yml │ └── sync_wiki.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── all.hxml ├── h2d ├── Anim.hx ├── Bitmap.hx ├── BlendMode.hx ├── Camera.hx ├── CdbLevel.hx ├── CheckBox.hx ├── Console.hx ├── Drawable.hx ├── Dropdown.hx ├── Flow.hx ├── Font.hx ├── Graphics.hx ├── HtmlText.hx ├── Interactive.hx ├── KeyFrames.hx ├── Layers.hx ├── LoadingScene.hx ├── Mask.hx ├── Object.hx ├── ObjectFollower.hx ├── Particles.hx ├── RenderContext.hx ├── ScaleGrid.hx ├── Scene.hx ├── Slider.hx ├── Sprite.hx ├── SpriteBatch.hx ├── Text.hx ├── TextInput.hx ├── Tile.hx ├── TileGroup.hx ├── Video.hx ├── ZGroup.hx ├── col │ ├── Bounds.hx │ ├── Circle.hx │ ├── Collider.hx │ ├── Delaunay.hx │ ├── IBounds.hx │ ├── IPoint.hx │ ├── IPolygon.hx │ ├── IPolygons.hx │ ├── Line.hx │ ├── Matrix.hx │ ├── PixelsCollider.hx │ ├── Point.hx │ ├── Polygon.hx │ ├── PolygonCollider.hx │ ├── Polygons.hx │ ├── Polynomial.hx │ ├── Ray.hx │ ├── RoundRect.hx │ ├── Segment.hx │ ├── Segments.hx │ ├── Triangle.hx │ └── Voronoi.hx ├── domkit │ ├── BaseComponents.hx │ ├── InitComponents.hx │ ├── Object.hx │ └── Style.hx ├── filter │ ├── AbstractMask.hx │ ├── Ambient.hx │ ├── Bloom.hx │ ├── Blur.hx │ ├── ColorMatrix.hx │ ├── Displacement.hx │ ├── DropShadow.hx │ ├── Filter.hx │ ├── Glow.hx │ ├── Group.hx │ ├── InnerGlow.hx │ ├── Mask.hx │ ├── Nothing.hx │ ├── Outline.hx │ ├── Shader.hx │ └── ToneMapping.hx └── impl │ ├── BatchDrawState.hx │ └── PointApi.hx ├── h3d ├── Buffer.hx ├── Camera.hx ├── Engine.hx ├── GPUCounter.hx ├── IDrawable.hx ├── Indexes.hx ├── Matrix.hx ├── Quat.hx ├── Vector.hx ├── Vector4.hx ├── anim │ ├── Animation.hx │ ├── BlendSpace2D.hx │ ├── BufferAnimation.hx │ ├── LinearAnimation.hx │ ├── SimpleBlend.hx │ ├── Skin.hx │ ├── SmoothTarget.hx │ ├── SmoothTransition.hx │ └── Transition.hx ├── col │ ├── Bounds.hx │ ├── Capsule.hx │ ├── Collider.hx │ ├── FPoint.hx │ ├── Frustum.hx │ ├── HeightMap.hx │ ├── IPoint.hx │ ├── ObjectCollider.hx │ ├── OrientedBounds.hx │ ├── Plane.hx │ ├── Point.hx │ ├── Polygon.hx │ ├── PolygonBuffer.hx │ ├── Ray.hx │ ├── Seg.hx │ ├── SkinCollider.hx │ ├── Sphere.hx │ └── TransformCollider.hx ├── impl │ ├── Benchmark.hx │ ├── DX12Driver.hx │ ├── DirectXDriver.hx │ ├── Driver.hx │ ├── GlDriver.hx │ ├── InstanceBuffer.hx │ ├── MacroHelper.hx │ ├── MemoryManager.hx │ ├── NullDriver.hx │ ├── PipelineCache.hx │ ├── RenderContext.hx │ ├── RendererFX.hx │ ├── SceneProf.hx │ ├── ShaderCache.hx │ ├── TextureCache.hx │ ├── VarBinding.hx │ └── VulkanDriver.hx ├── mat │ ├── BaseMaterial.hx │ ├── BigTexture.hx │ ├── BlendMode.hx │ ├── Data.hx │ ├── Defaults.hx │ ├── Material.hx │ ├── MaterialDatabase.hx │ ├── MaterialSetup.hx │ ├── Pass.hx │ ├── PbrMaterial.hx │ ├── PbrMaterialSetup.hx │ ├── Stencil.hx │ ├── Texture.hx │ ├── Texture3D.hx │ ├── TextureArray.hx │ ├── TextureChannels.hx │ └── noise │ │ └── WorleyNoise.hx ├── parts │ ├── Collider.hx │ ├── Data.hx │ ├── Emitter.hx │ ├── GpuParticles.hx │ ├── Particle.hx │ ├── Particles.hx │ ├── default.png │ └── defaultAlpha.png ├── pass │ ├── Blur.hx │ ├── Border.hx │ ├── CapsuleShadowMap.hx │ ├── CascadeShadowMap.hx │ ├── ColorMatrix.hx │ ├── Copy.hx │ ├── CubeCopy.hx │ ├── CubeShadowMap.hx │ ├── DefaultShadowMap.hx │ ├── DirShadowMap.hx │ ├── FXAA.hx │ ├── Outline.hx │ ├── Output.hx │ ├── OutputShader.hx │ ├── PassList.hx │ ├── PassObject.hx │ ├── PointShadowMap.hx │ ├── ScalableAO.hx │ ├── ScreenFx.hx │ ├── Shadows.hx │ ├── SortByMaterial.hx │ └── SpotShadowMap.hx ├── prim │ ├── BigPrimitive.hx │ ├── Blendshape.hx │ ├── Capsule.hx │ ├── Collider.hx │ ├── Cube.hx │ ├── Cylinder.hx │ ├── Disc.hx │ ├── DynamicPrimitive.hx │ ├── GeoSphere.hx │ ├── Grid.hx │ ├── HMDModel.hx │ ├── Instanced.hx │ ├── MeshPrimitive.hx │ ├── ModelCache.hx │ ├── ModelDatabase.hx │ ├── Plane2D.hx │ ├── Polygon.hx │ ├── Primitive.hx │ ├── Quads.hx │ ├── RawPrimitive.hx │ ├── Sphere.hx │ └── UV.hx ├── scene │ ├── AnimMeshBatcher.hx │ ├── Box.hx │ ├── CameraController.hx │ ├── Capsule.hx │ ├── GPUMeshBatch.hx │ ├── Graphics.hx │ ├── HierarchicalWorld.hx │ ├── Interactive.hx │ ├── Light.hx │ ├── LightSystem.hx │ ├── Mesh.hx │ ├── MeshBatch.hx │ ├── MultiMaterial.hx │ ├── Object.hx │ ├── RenderContext.hx │ ├── Renderer.hx │ ├── Scene.hx │ ├── Skin.hx │ ├── Sphere.hx │ ├── Trail.hx │ ├── World.hx │ ├── fwd │ │ ├── DirLight.hx │ │ ├── Light.hx │ │ ├── LightSystem.hx │ │ ├── PointLight.hx │ │ └── Renderer.hx │ └── pbr │ │ ├── CapsuleLight.hx │ │ ├── Decal.hx │ │ ├── DirLight.hx │ │ ├── Environment.hx │ │ ├── Light.hx │ │ ├── LightBuffer.hx │ │ ├── LightSystem.hx │ │ ├── PointLight.hx │ │ ├── Renderer.hx │ │ ├── SpotLight.hx │ │ ├── envDefault.dds │ │ ├── envDefault.envd.dds │ │ ├── envDefault.envs.dds │ │ └── lighting_performance_gradient.png └── shader │ ├── AlphaChannel.hx │ ├── AlphaMSDF.hx │ ├── AlphaMap.hx │ ├── AlphaMult.hx │ ├── AmbientLight.hx │ ├── AnimatedTexture.hx │ ├── Base2d.hx │ ├── BaseMesh.hx │ ├── Bloom.hx │ ├── Blur.hx │ ├── Buffers.hx │ ├── CascadeShadow.hx │ ├── Checker.hx │ ├── CheckerboardDepth.hx │ ├── ColorAdd.hx │ ├── ColorKey.hx │ ├── ColorMatrix.hx │ ├── ColorMult.hx │ ├── ColorSpaces.hx │ ├── CubeMap.hx │ ├── DepthAwareUpsampling.hx │ ├── DirLight.hx │ ├── DirShadow.hx │ ├── Displacement.hx │ ├── DisplacementDisplay.hx │ ├── DistanceFade.hx │ ├── FixedColor.hx │ ├── FlipBackFaceNormal.hx │ ├── GenTexture.hx │ ├── GpuParticle.hx │ ├── InstanceIndirect.hx │ ├── KillAlpha.hx │ ├── LineShader.hx │ ├── MinMaxShader.hx │ ├── NoiseLib.hx │ ├── NormalMap.hx │ ├── Outline.hx │ ├── Outline2D.hx │ ├── Parallax.hx │ ├── ParticleShader.hx │ ├── PointLight.hx │ ├── PointShadow.hx │ ├── SAO.hx │ ├── ScreenShader.hx │ ├── Shadow.hx │ ├── SignedDistanceField.hx │ ├── SinusDeform.hx │ ├── Skin.hx │ ├── SkinBase.hx │ ├── SkinTangent.hx │ ├── SpecularTexture.hx │ ├── SpotShadow.hx │ ├── Texture.hx │ ├── Texture2.hx │ ├── UVAnim.hx │ ├── UVDelta.hx │ ├── UVScroll.hx │ ├── VertexColor.hx │ ├── VertexColorAlpha.hx │ ├── VolumeDecal.hx │ ├── WhiteAlpha.hx │ ├── ZCut.hx │ └── pbr │ ├── AlphaMultiply.hx │ ├── BDRF.hx │ ├── CubeLod.hx │ ├── DefaultForward.hx │ ├── Distortion.hx │ ├── GammaCorrect.hx │ ├── Light.hx │ ├── Lighting.hx │ ├── PerformanceViewer.hx │ ├── PropsDefinition.hx │ ├── PropsImport.hx │ ├── PropsTexture.hx │ ├── PropsValues.hx │ ├── Slides.hx │ ├── StrengthValues.hx │ ├── ToneMapping.hx │ └── VolumeDecal.hx ├── haxelib.json ├── hxd ├── App.hx ├── BitmapData.hx ├── BufferFormat.hx ├── ByteConversions.hx ├── BytesBuffer.hx ├── Charset.hx ├── Cursor.hx ├── Direction.hx ├── DropFileEvent.hx ├── Event.hx ├── File.hx ├── FloatBuffer.hx ├── FloatBufferLoader.hx ├── IndexBuffer.hx ├── Key.hx ├── Math.hx ├── Pad.hx ├── Perlin.hx ├── PixelFormat.hx ├── Pixels.hx ├── Rand.hx ├── Res.hx ├── Save.hx ├── SceneEvents.hx ├── Stage.hx ├── System.hl.hx ├── System.hx ├── System.js.hx ├── Timer.hx ├── WaitEvent.hx ├── Window.hl.hx ├── Window.hx ├── Window.js.hx ├── clipper │ ├── ClipType.hx │ ├── Clipper.hx │ ├── EndType.hx │ ├── JoinType.hx │ ├── PolyFillType.hx │ ├── PolyType.hx │ └── Rect.hx ├── earcut │ └── Earcut.hx ├── fmt │ ├── bfnt │ │ ├── FontParser.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ ├── blend │ │ └── Data.hx │ ├── fbx │ │ ├── BaseLibrary.hx │ │ ├── Data.hx │ │ ├── Filter.hx │ │ ├── Geometry.hx │ │ ├── HMDOut.hx │ │ ├── Parser.hx │ │ └── Writer.hx │ ├── grd │ │ ├── Data.hx │ │ └── Reader.hx │ ├── hbson │ │ ├── Reader.hx │ │ └── Writer.hx │ ├── hdr │ │ └── Reader.hx │ ├── hmd │ │ ├── Data.hx │ │ ├── Dump.hx │ │ ├── Library.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ ├── kframes │ │ └── Data.hx │ ├── pak │ │ ├── Build.hx │ │ ├── Data.hx │ │ ├── FileSystem.hx │ │ ├── Loader.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ ├── spine │ │ ├── Data.hx │ │ ├── JsonData.hx │ │ └── Library.hx │ └── tiff │ │ ├── Data.hx │ │ ├── Reader.hx │ │ └── Writer.hx ├── fs │ ├── BytesFileSystem.hx │ ├── Convert.hx │ ├── EmbedFileSystem.hx │ ├── FileConverter.hx │ ├── FileEntry.hx │ ├── FileInput.hx │ ├── FileSystem.hx │ ├── LoadedBitmap.hx │ ├── LocalFileSystem.hx │ ├── MultiFileSystem.hx │ ├── NotFound.hx │ └── SourceLoader.hx ├── impl │ ├── AllocPos.hx │ ├── Allocator.hx │ ├── AnyProps.hx │ ├── AppContext.hx │ ├── ArrayIterator.hx │ ├── AsyncLoader.hx │ ├── BitSet.hx │ ├── BitsBuilder.hx │ ├── CacheAllocator.hx │ ├── FIFOBufferAllocator.hx │ ├── Float32.hx │ ├── MouseMode.hx │ ├── Properties.hx │ ├── TypedArray.hx │ ├── UInt16.hx │ └── UncheckedBytes.hx ├── ja-simplified.txt ├── net │ ├── BinaryLoader.hx │ ├── Socket.hx │ └── SocketHost.hx ├── poly2tri │ ├── AdvancingFront.hx │ ├── Basin.hx │ ├── Constants.hx │ ├── Edge.hx │ ├── EdgeEvent.hx │ ├── Node.hx │ ├── Orientation.hx │ ├── Point.hx │ ├── Sweep.hx │ ├── SweepContext.hx │ ├── Triangle.hx │ ├── Utils.hx │ └── VisiblePolygon.hx ├── res │ ├── AnimGraph.hx │ ├── Any.hx │ ├── Atlas.hx │ ├── BDFFont.hx │ ├── BitmapFont.hx │ ├── Config.hx │ ├── DefaultFont.hx │ ├── DynamicText.hx │ ├── Embed.hx │ ├── EmbedOptions.hx │ ├── FileTree.hx │ ├── Font.hx │ ├── FontBuilder.hx │ ├── Gradients.hx │ ├── Image.hx │ ├── Loader.hx │ ├── Model.hx │ ├── NanoJpeg.hx │ ├── NotFound.hx │ ├── Prefab.hx │ ├── Resource.hx │ ├── Sound.hx │ ├── TiledMap.hx │ ├── defaultFont.fnt │ └── defaultFont.png ├── snd │ ├── Channel.hx │ ├── ChannelBase.hx │ ├── ChannelGroup.hx │ ├── Data.hx │ ├── Driver.hx │ ├── Effect.hx │ ├── Listener.hx │ ├── LoadingData.hx │ ├── Manager.hx │ ├── Mp3Data.hx │ ├── NativeChannel.hx │ ├── OggData.hx │ ├── SoundGroup.hx │ ├── WavData.hx │ ├── effect │ │ ├── LowPass.hx │ │ ├── Pitch.hx │ │ ├── Reverb.hx │ │ ├── ReverbPreset.hx │ │ └── Spatialization.hx │ ├── openal │ │ ├── AudioTypes.hx │ │ ├── Driver.hx │ │ ├── Emulator.hx │ │ ├── LowPassDriver.hx │ │ ├── PitchDriver.hx │ │ ├── ReverbDriver.hx │ │ └── SpatializationDriver.hx │ └── webaudio │ │ ├── AudioTypes.hx │ │ ├── Context.hx │ │ ├── Driver.hx │ │ ├── LowPassDriver.hx │ │ ├── PitchDriver.hx │ │ └── SpatializationDriver.hx ├── tools │ ├── MeshOptimizer.hx │ ├── Mikktspace.hx │ └── VHACD.hx └── zh-simplified.txt ├── hxsl ├── Ast.hx ├── BatchShader.hx ├── Cache.hx ├── CacheFile.hx ├── CacheFileBuilder.hx ├── Channel.hx ├── ChannelTexture.hx ├── Checker.hx ├── Clone.hx ├── Dce.hx ├── Debug.hx ├── DynamicShader.hx ├── Eval.hx ├── Flatten.hx ├── Globals.hx ├── GlslOut.hx ├── HlslOut.hx ├── Linker.hx ├── MacroParser.hx ├── Macros.hx ├── NXGlslOut.hx ├── Output.hx ├── Printer.hx ├── RuntimeShader.hx ├── Serializer.hx ├── Shader.hx ├── ShaderList.hx ├── SharedShader.hx ├── Splitter.hx └── Types.hx ├── samples ├── AdjustColor.hx ├── Base2D.hx ├── Base3D.hx ├── Blur.hx ├── Bounds.hx ├── Camera2D.hx ├── CollideCheck.hx ├── CubeTexture.hx ├── Cursor.hx ├── Domkit.hx ├── DrawingTiles.hx ├── ExtraTests.hx ├── Filters.hx ├── Flows.hx ├── Fullscreen.hx ├── FxView.hx ├── Generator.hx ├── GpuParticles.hx ├── GraphicsDraw.hx ├── Helpers.hx ├── HtmlText.hx ├── Input.hx ├── Interactive.hx ├── Interactive2D.hx ├── Lights.hx ├── Mask.hx ├── MeshBatch.hx ├── MouseApi.hx ├── Network.hx ├── Pad.hx ├── Particles2d.hx ├── Pbr.hx ├── PointLights.hx ├── Polygons.hx ├── Quaternion.hx ├── SampleApp.hx ├── Sao.hx ├── ScaleMode2D.hx ├── ShaderAdvanced.hx ├── Shadows.hx ├── Skin.hx ├── Sound.hx ├── Stencil.hx ├── Text.hx ├── Tiled.hx ├── Video.hx ├── World.hx ├── all.hxml ├── domkit_res │ └── style.css ├── fxView_res │ ├── hideEffect.fx │ └── ray.jpg ├── gen.hxml ├── particles2d_res │ └── arrow.png ├── pbr_res │ ├── back.jpg │ ├── bottom.jpg │ ├── front.jpg │ ├── left.jpg │ ├── right.jpg │ └── top.jpg ├── res │ ├── customFont.fnt │ ├── customFont.png │ ├── hxlogo.png │ └── normalmap.png ├── skin_res │ ├── Model.FBX │ ├── Skeleton01.png │ └── Sword01.png ├── sound_res │ ├── music_loop.mp3 │ ├── music_loop.ogg │ └── sound_fx.wav ├── templates │ ├── .vscode │ │ ├── launch.json │ │ └── tasks.json │ ├── __name_hl.hxml │ ├── __name_js.hxml │ └── index.html ├── text_res │ ├── bmfont_binary.fnt │ ├── bmfont_binary_0.png │ ├── bmfont_text.fnt │ ├── bmfont_xml.fnt │ ├── gravityFont.fnt │ ├── gravityFont.png │ ├── littera.png │ ├── littera_text.fnt │ ├── littera_xml.fnt │ ├── sdf_font.fnt │ ├── sdf_font.png │ └── trueTypeFont.ttf ├── tiled_res │ ├── tileMap.tmx │ └── tiles.png └── world_res │ ├── rock.hmd │ ├── rockTexture.jpg │ ├── tree.hmd │ └── treeTexture.png └── tools ├── hxsl ├── Main.hx ├── hxsl.hxml ├── hxsl.hxproj └── index.html ├── meshTools ├── Makefile ├── MeshTools.hx ├── build_msvc.bat └── meshtools.hxml └── xtra └── xtraExporter.ms /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build-samples: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: krdlab/setup-haxe@v1 14 | with: 15 | haxe-version: 4.3.6 16 | - name: Print Haxe version 17 | run: | 18 | haxe --version 19 | - name: Install haxelib deps 20 | run: | 21 | haxelib git format https://github.com/HaxeFoundation/format 22 | haxelib git hxbit https://github.com/ncannasse/hxbit 23 | haxelib git hscript https://github.com/HaxeFoundation/hscript 24 | haxelib git domkit https://github.com/HeapsIO/domkit 25 | haxelib git hide https://github.com/HeapsIO/hide 26 | haxelib git hlsdl https://github.com/HaxeFoundation/hashlink master libs/sdl 27 | haxelib dev heaps . 28 | - name: Build samples 29 | run: | 30 | cd samples 31 | haxe all.hxml 32 | cd .. 33 | -------------------------------------------------------------------------------- /.github/workflows/sync_wiki.yml: -------------------------------------------------------------------------------- 1 | name: Synchronize Wiki 2 | 3 | on: 4 | schedule: 5 | # daily, midnight UTC 6 | - cron: "0 0 * * *" 7 | workflow_dispatch: 8 | 9 | jobs: 10 | synchronize: 11 | if: github.repository_owner == 'HeapsIO' 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: write 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | repository: ${{ github.repository }}.wiki 19 | fetch-depth: 0 20 | - name: Set git credentials 21 | run: | 22 | git config user.name "github-actions[bot]" 23 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 24 | - name: Fetch 25 | run: | 26 | git remote add upstream ${{ github.server_url }}/${{ github.repository_owner }}/heaps-doc 27 | git fetch upstream master 28 | - name: Merge 29 | run: | 30 | git merge upstream/master --no-edit 31 | - name: Push 32 | run: | 33 | git push 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.n 2 | *.swf 3 | *.js 4 | *.js.map 5 | *.obj 6 | bin 7 | .tmp 8 | /hxd/net/inspect.min.css 9 | /hxd/inspect/inspect.min.css 10 | /samples/build 11 | /*.xml 12 | .vscode 13 | /tools/meshtools/out 14 | *.exe 15 | /shaders -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: haxe 2 | 3 | os: linux 4 | dist: trusty 5 | 6 | haxe: 7 | - development 8 | - "4.1.5" 9 | - "4.2.2" 10 | 11 | install: 12 | - yes | haxelib install all 13 | - pushd samples 14 | - yes | haxelib install all 15 | - popd 16 | - haxelib dev heaps . 17 | - haxelib list 18 | 19 | script: 20 | - haxe all.hxml 21 | - haxe --cwd samples all.hxml 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Nicolas Cannasse 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /all.hxml: -------------------------------------------------------------------------------- 1 | -lib heaps 2 | -lib castle 3 | -lib hxbit 4 | --macro include('h3d') 5 | --macro include('h2d',true,['h2d.domkit']) 6 | --macro include('hxsl',true,['hxsl.Macros','hxsl.CacheFileBuilder','hxsl.Checker']) 7 | --macro include('hxd',true,['hxd.res.FileTree','hxd.Res','hxd.impl.BitsBuilder','hxd.fmt.pak.Build','hxd.snd.openal','hxd.res.Config']) 8 | --no-output 9 | -D apicheck 10 | --each 11 | 12 | -js heaps.js 13 | -xml heaps_js.xml 14 | 15 | --next 16 | 17 | -hl heaps.hl 18 | -lib hlsdl 19 | -lib hlopenal 20 | -xml heaps_hl.xml 21 | hxsl.CacheFileBuilder 22 | -D hl-ver=1.15.0 23 | 24 | --next 25 | 26 | -hl heaps.hl 27 | -lib hldx 28 | -lib hlopenal 29 | -xml heaps_hldx.xml 30 | -D hl-ver=1.15.0 31 | 32 | --next 33 | 34 | -hl heaps.hl 35 | -lib hldx 36 | -lib hlopenal 37 | -D dx12 38 | -xml heaps_hldx12.xml 39 | -D hl-ver=1.15.0 40 | -------------------------------------------------------------------------------- /h2d/BlendMode.hx: -------------------------------------------------------------------------------- 1 | package h2d; 2 | 3 | /** 4 | The blending rules when rendering a Tile/Material. 5 | **/ 6 | enum BlendMode { 7 | /** 8 | `Out = 1 * Src + 0 * Dst` 9 | **/ 10 | None; 11 | /** 12 | `Out = SrcA * Src + (1 - SrcA) * Dst` 13 | **/ 14 | Alpha; 15 | /** 16 | `Out = SrcA * Src + 1 * Dst` 17 | **/ 18 | Add; 19 | /** 20 | `Out = Src + (1 - SrcA) * Dst` 21 | **/ 22 | AlphaAdd; 23 | /** 24 | `Out = (1 - Dst) * Src + 1 * Dst` 25 | **/ 26 | SoftAdd; 27 | /** 28 | `Out = Dst * Src + 0 * Dst` 29 | **/ 30 | Multiply; 31 | /** 32 | `Out = Dst * Src + (1 - SrcA) * Dst` 33 | **/ 34 | AlphaMultiply; 35 | /** 36 | `Out = 0 * Src + (1 - Srb) * Dst` 37 | **/ 38 | Erase; 39 | /** 40 | `Out = 1 * Src + (1 - Srb) * Dst` 41 | **/ 42 | Screen; 43 | /** 44 | `Out = 1 * Dst - SrcA * Src` 45 | **/ 46 | Sub; 47 | /** 48 | The output color is the max of the source and dest colors. 49 | The blend parameters Src and Dst are ignored for this equation. 50 | `Out = MAX( Src, Dst )` 51 | **/ 52 | Max; 53 | /** 54 | The output color is the min of the source and dest colors. 55 | The blend parameters Src and Dst are ignored for this equation. 56 | `Out = MAX( Src, Dst )` 57 | **/ 58 | Min; 59 | } 60 | -------------------------------------------------------------------------------- /h2d/LoadingScene.hx: -------------------------------------------------------------------------------- 1 | package h2d; 2 | 3 | class LoadingScene extends h2d.Scene { 4 | var renderTarget : h3d.mat.Texture; 5 | var presentCooldown : Float; 6 | public function new(presentCooldown : Float) { 7 | super(); 8 | this.presentCooldown = presentCooldown; 9 | renderTarget = new h3d.mat.Texture(width, height, [Target]); 10 | } 11 | 12 | var lastPresentTime : Float = 0.0; 13 | public override function render( engine : h3d.Engine ) { 14 | var time = haxe.Timer.stamp(); 15 | if ( time - lastPresentTime < presentCooldown) 16 | return; 17 | lastPresentTime = time; 18 | 19 | #if usesys 20 | haxe.System.emitEvents(@:privateAccess hxd.Window.inst.event); 21 | #elseif hldx 22 | dx.Loop.processEvents(@:privateAccess hxd.Window.inst.onEvent); 23 | #elseif hlsdl 24 | sdl.Sdl.processEvents(@:privateAccess hxd.Window.inst.onEvent); 25 | #end 26 | 27 | if ( renderTarget.width != engine.width || renderTarget.height != engine.height) { 28 | renderTarget.dispose(); 29 | renderTarget = new h3d.mat.Texture(engine.width, engine.height, [Target]); 30 | } 31 | 32 | engine.pushTarget(renderTarget); 33 | super.render(engine); 34 | engine.popTarget(); 35 | h3d.pass.Copy.run(renderTarget, null); 36 | engine.driver.present(); 37 | } 38 | 39 | override function onRemove() { 40 | super.onRemove(); 41 | if ( renderTarget != null ) 42 | renderTarget.dispose(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /h2d/Sprite.hx: -------------------------------------------------------------------------------- 1 | package h2d; 2 | 3 | #if !heaps_sprite 4 | @:deprecated("h2d.Sprite is now h2d.Object, rename or use -D heaps-sprite") 5 | @:noCompletion 6 | @:dox(hide) 7 | #end 8 | typedef Sprite = Object; -------------------------------------------------------------------------------- /h2d/col/Collider.hx: -------------------------------------------------------------------------------- 1 | package h2d.col; 2 | 3 | /** 4 | A common interface for 2D Shapes to hit-test again the mouse or a specific point in space. 5 | **/ 6 | abstract class Collider { 7 | 8 | /** 9 | Tests if Point `p` is inside the Collider. 10 | **/ 11 | public abstract function contains( p : Point ) : Bool; 12 | public abstract function collideCircle( c : Circle ) : Bool; 13 | public abstract function collideBounds( b : Bounds ) : Bool; 14 | 15 | } -------------------------------------------------------------------------------- /h2d/col/PolygonCollider.hx: -------------------------------------------------------------------------------- 1 | package h2d.col; 2 | 3 | /** 4 | A `Collider` wrapper around `Polygons` to enable using those for hit-testing testing. 5 | **/ 6 | class PolygonCollider extends Collider { 7 | /** 8 | The Polygons instance used for collision checks. 9 | **/ 10 | public var polygons : Polygons; 11 | /** 12 | Whether Polygons is convex or concave. 13 | Convex polygons are cheaper to test against. 14 | **/ 15 | public var isConvex : Bool; 16 | 17 | /** 18 | Create new PolygonCollider with specified Polygons and flag to check as convex or concave. 19 | **/ 20 | public function new( polygons:Polygons, isConvex : Bool = false ) { 21 | this.polygons = polygons; 22 | this.isConvex = isConvex; 23 | } 24 | 25 | /** 26 | Test is Point `p` is inside `polygons`. 27 | **/ 28 | public function contains( p : Point ) { 29 | if (polygons == null) return false; 30 | return polygons.contains(p, isConvex); 31 | } 32 | 33 | public function collideCircle( c : Circle ) : Bool { 34 | throw "Not implemented"; 35 | } 36 | 37 | public function collideBounds( b : Bounds ) : Bool { 38 | throw "Not implemented"; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /h2d/domkit/InitComponents.hx: -------------------------------------------------------------------------------- 1 | package h2d.domkit; 2 | import h2d.domkit.BaseComponents.CustomParser; 3 | 4 | class InitComponents { 5 | 6 | public static function init() { 7 | domkit.Macros.registerComponentsPath("h2d.domkit.BaseComponents.$Comp"); 8 | domkit.Macros.registerComponentsPath("$Comp"); 9 | if( domkit.Macros.defaultParserPath == null ) 10 | domkit.Macros.setDefaultParser("h2d.domkit.BaseComponents.CustomParser"); 11 | // force base components to be built before custom components 12 | @:privateAccess domkit.Macros.preload = [ 13 | for( o in ["Object", "Drawable", "Video", "Bitmap", "Text", "HtmlText", "Flow", "Mask", "ScaleGrid", "Input"] ) 14 | 'h2d.domkit.BaseComponents.${o}Comp' 15 | ]; 16 | return null; 17 | } 18 | 19 | public static function build() { 20 | return domkit.Macros.buildObject(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /h2d/domkit/Object.hx: -------------------------------------------------------------------------------- 1 | package h2d.domkit; 2 | import h2d.domkit.BaseComponents; 3 | 4 | @:build(h2d.domkit.InitComponents.init()) 5 | @:autoBuild(h2d.domkit.InitComponents.build()) 6 | interface Object { 7 | } -------------------------------------------------------------------------------- /h2d/filter/Ambient.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | A ColorMatrix filer that applies color correction depending on the masked area. 5 | 6 | Uses masked objects `red*alpha` channels to determine the transition from original color and transformed color. 7 | 8 | _Hacking_: Through accessing color matrix shader directly via `@:privateAccess ambient.pass.shader.maskChannel` 9 | it's possible to modify which channels affect the resulting transition value. 10 | 11 | @see `ColorMatrix` 12 | **/ 13 | class Ambient extends AbstractMask { 14 | 15 | /** 16 | The exponent of the mask color values that affects transition speed. 17 | **/ 18 | public var power(get, set) : Float; 19 | 20 | /** 21 | Whether to apply ambient color correction inside masked (when enabled) area or outside of it (when disabled). 22 | **/ 23 | public var invert(get, set) : Bool; 24 | 25 | var pass : h3d.pass.ColorMatrix; 26 | 27 | /** 28 | Create new Ambient filter. 29 | @param mask An `Object` that will be used for masking. See `AbstractMask.mask` for limitations. 30 | @param m The color matrix that is applied to the area dictated by `Ambient.invert`. 31 | **/ 32 | public function new( mask, ?m : h3d.Matrix ) { 33 | pass = new h3d.pass.ColorMatrix(m); 34 | super(mask); 35 | } 36 | 37 | inline function get_power() return pass.maskPower; 38 | inline function set_power(v) return pass.maskPower = v; 39 | inline function get_invert() return pass.shader.maskInvert; 40 | inline function set_invert(v) return pass.shader.maskInvert = v; 41 | 42 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 43 | var out = ctx.textures.allocTileTarget("ambientTmp", t); 44 | pass.apply(t.getTexture(), out, getMaskTexture(ctx, t), maskMatrix); 45 | return h2d.Tile.fromTexture(out); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /h2d/filter/Bloom.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | Applies a bloom effect to the filtered Object. 5 | Produces feathers to light areas in the objects. 6 | **/ 7 | class Bloom extends Blur { 8 | 9 | var bloom : h3d.pass.ScreenFx; 10 | /** 11 | The bloom luminosity multiplier. 12 | **/ 13 | public var amount(get, set) : Float; 14 | /** 15 | The bloom luminosity exponent. 16 | **/ 17 | public var power(get, set) : Float; 18 | 19 | /** 20 | @param power The bloom luminosity exponent. 21 | @param amount The bloom luminosity multiplier. 22 | @param radius The bloom glow distance in pixels. 23 | @param gain The bloom color intensity. 24 | @param quality The sample count on each pixel as a tradeoff of speed/quality. 25 | **/ 26 | public function new( power = 2., amount = 1., radius = 1., gain = 1., quality = 1. ) { 27 | super(radius,gain,quality); 28 | bloom = new h3d.pass.ScreenFx(new h3d.shader.Bloom()); 29 | bloom.shader.power = power; 30 | bloom.shader.amount = amount; 31 | @:privateAccess bloom.pass.blend(One, One); 32 | } 33 | 34 | inline function get_amount() return bloom.shader.amount; 35 | inline function set_amount(v) return bloom.shader.amount = v; 36 | inline function get_power() return bloom.shader.power; 37 | inline function set_power(v) return bloom.shader.power = v; 38 | 39 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 40 | var dst = ctx.textures.allocTileTarget("dest", t); 41 | h3d.pass.Copy.run(t.getTexture(), dst); 42 | var blurred = super.draw(ctx, t); 43 | bloom.shader.texture = blurred.getTexture(); 44 | ctx.engine.pushTarget(dst); 45 | bloom.render(); 46 | ctx.engine.popTarget(); 47 | return h2d.Tile.fromTexture(dst); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /h2d/filter/Blur.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | Utilizes the `h3d.pass.Blur` render pass to perform a blurring operation on the filtered object. 5 | **/ 6 | class Blur extends Filter { 7 | 8 | /** 9 | @see `h3d.pass.Blur.radius` 10 | **/ 11 | public var radius(get, set) : Float; 12 | 13 | /** 14 | @see `h3d.pass.Blur.linear` 15 | **/ 16 | public var linear(get, set) : Float; 17 | 18 | /** 19 | @see `h3d.pass.Blur.gain` 20 | **/ 21 | public var gain(get, set) : Float; 22 | 23 | /** 24 | @see `h3d.pass.Blur.quality` 25 | **/ 26 | public var quality(get, set) : Float; 27 | 28 | var pass : h3d.pass.Blur; 29 | 30 | /** 31 | Create a new Blur filter. 32 | @param radius The blur distance in pixels. 33 | @param gain The color gain when blurring. 34 | @param quality The sample count on each pixel as a tradeoff of speed/quality. 35 | @param linear Linear blur power. Set to 0 for gaussian blur. 36 | **/ 37 | public function new( radius = 1., gain = 1., quality = 1., linear = 0. ) { 38 | super(); 39 | pass = new h3d.pass.Blur(radius, gain, linear, quality); 40 | } 41 | 42 | inline function get_quality() return pass.quality; 43 | inline function set_quality(v) return pass.quality = v; 44 | inline function get_radius() return pass.radius; 45 | inline function set_radius(v) return pass.radius = v; 46 | inline function get_gain() return pass.gain; 47 | inline function set_gain(v) return pass.gain = v; 48 | inline function get_linear() return pass.linear; 49 | inline function set_linear(v) return pass.linear = v; 50 | 51 | override function sync( ctx : RenderContext, s : Object ) { 52 | boundsExtend = Math.ceil(radius) * 2; 53 | } 54 | 55 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 56 | var out = t.getTexture(); 57 | var old = out.filter; 58 | out.filter = Linear; 59 | pass.apply(ctx, out); 60 | out.filter = old; 61 | return t; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /h2d/filter/ColorMatrix.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | Applies a color correction filter based on the provided matrix. 5 | 6 | Matrix values are as following: 7 | ``` 8 | red green blue alpha 9 | [ redMult, redMult, redMult, redMult ] 10 | [ greenMult, greenMult, greenMult, greenMult ] 11 | [ blueMult, blueMult, blueMult, blueMult ] 12 | [ alphaMult, alphaMult, alphaMult, alphaMult ] 13 | ``` 14 | An identity matrix will result in an unmodified colors: 15 | ``` 16 | [1, 0, 0, 0] 17 | [0, 1, 0, 0] 18 | [0, 0, 1, 0] 19 | [0, 0, 0, 1] 20 | ``` 21 | 22 | @see `Ambient` 23 | **/ 24 | class ColorMatrix extends Filter { 25 | 26 | /** 27 | The matrix used to apply color correction. 28 | **/ 29 | public var matrix(get, set) : h3d.Matrix; 30 | 31 | var pass : h3d.pass.ColorMatrix; 32 | 33 | /** 34 | Create a new ColorMatrix filter. 35 | 36 | @param m The matrix used to modify the resulting colors. 37 | **/ 38 | public function new( ?m : h3d.Matrix ) { 39 | super(); 40 | pass = new h3d.pass.ColorMatrix(m); 41 | pass.shader.useAlpha = true; 42 | } 43 | 44 | inline function get_matrix() return pass.matrix; 45 | inline function set_matrix(m) return pass.matrix = m; 46 | 47 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 48 | var tout = ctx.textures.allocTileTarget("colorMatrixOut", t); 49 | pass.apply(t.getTexture(), tout); 50 | return h2d.Tile.fromTexture(tout); 51 | } 52 | 53 | /** 54 | Returns a ColorMatrix filter which results in a grayscale image (0 saturation). 55 | **/ 56 | public static function grayed() { 57 | var m = new h3d.Matrix(); 58 | m.identity(); 59 | m.colorSaturate(-1); 60 | return new ColorMatrix(m); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /h2d/filter/Nothing.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | A filter that renders nothing. 5 | **/ 6 | class Nothing extends Filter { 7 | 8 | /** 9 | Create a new Nothing filter. 10 | **/ 11 | public function new() { 12 | super(); 13 | } 14 | 15 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 16 | return t; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /h2d/filter/ToneMapping.hx: -------------------------------------------------------------------------------- 1 | package h2d.filter; 2 | 3 | /** 4 | Applies a color correction that emulates tonemapping. 5 | **/ 6 | class ToneMapping extends Filter { 7 | 8 | /** 9 | The value used to apply gamma correction. 10 | **/ 11 | public var gamma(get, set) : Float; 12 | 13 | var pass : h3d.pass.ScreenFx; 14 | var shader : h3d.shader.pbr.ToneMapping; 15 | 16 | /** 17 | Create a new ColorMatrix filter. 18 | 19 | @param gamma The value used to modify the resulting colors. 20 | **/ 21 | public function new( ?g : Float ) { 22 | super(); 23 | shader = new h3d.shader.pbr.ToneMapping(); 24 | gamma = g; 25 | pass = new h3d.pass.ScreenFx(shader); 26 | } 27 | 28 | inline function get_gamma() return shader.gamma; 29 | inline function set_gamma(v) return shader.gamma = v; 30 | 31 | override function draw( ctx : RenderContext, t : h2d.Tile ) { 32 | var tout = ctx.textures.allocTileTarget("toneMappingOut", t); 33 | ctx.engine.pushTarget(tout); 34 | shader.hdrTexture = t.getTexture(); 35 | pass.render(); 36 | ctx.engine.popTarget(); 37 | return h2d.Tile.fromTexture(tout); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /h3d/GPUCounter.hx: -------------------------------------------------------------------------------- 1 | package h3d; 2 | 3 | class GPUCounter { 4 | public var buffer(default, null) : h3d.Buffer; 5 | var accessor : haxe.io.Bytes; 6 | 7 | public function new() { 8 | var alloc = hxd.impl.Allocator.get(); 9 | buffer = alloc.allocBuffer(1,hxd.BufferFormat.INDEX32, UniformReadWrite); 10 | accessor = haxe.io.Bytes.alloc(4); 11 | } 12 | 13 | public function dispose(){ 14 | var alloc = hxd.impl.Allocator.get(); 15 | alloc.disposeBuffer(buffer); 16 | } 17 | 18 | public function get() : Int { 19 | buffer.readBytes(accessor, 0, 1); 20 | return accessor.getInt32(0); 21 | } 22 | 23 | public function reset(){ 24 | accessor.setInt32(0, 0); 25 | buffer.uploadBytes(accessor, 0,1); 26 | } 27 | } -------------------------------------------------------------------------------- /h3d/IDrawable.hx: -------------------------------------------------------------------------------- 1 | package h3d; 2 | 3 | interface IDrawable { 4 | public function render( engine : Engine ) : Void; 5 | } -------------------------------------------------------------------------------- /h3d/Indexes.hx: -------------------------------------------------------------------------------- 1 | package h3d; 2 | 3 | @:forward(isDisposed, dispose, uploadBytes) 4 | abstract Indexes(Buffer) to Buffer { 5 | 6 | public var count(get,never) : Int; 7 | 8 | public function new(count:Int,is32=false) { 9 | this = new Buffer(count,is32 ? hxd.BufferFormat.INDEX32 : hxd.BufferFormat.INDEX16, [IndexBuffer]); 10 | } 11 | 12 | public function uploadIndexes( ibuf : hxd.IndexBuffer, bufPos : Int, indices : Int, startIndice = 0 ) { 13 | if( startIndice < 0 || indices < 0 || startIndice + indices > this.vertices ) 14 | throw "Invalid indices count"; 15 | if( @:privateAccess this.format.inputs[0].precision != F16 ) 16 | throw "Can't upload indexes on a 32-bit buffer"; 17 | if( indices == 0 ) 18 | return; 19 | h3d.Engine.getCurrent().driver.uploadIndexData(this, startIndice, indices, ibuf, bufPos); 20 | } 21 | 22 | inline function get_count() return this.vertices; 23 | 24 | public static function alloc( i : hxd.IndexBuffer, startPos = 0, length = -1 ) : Indexes { 25 | if( length < 0 ) length = i.length; 26 | var idx = new Indexes(length); 27 | idx.uploadIndexes(i, 0, length); 28 | return idx; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /h3d/anim/SimpleBlend.hx: -------------------------------------------------------------------------------- 1 | package h3d.anim; 2 | 3 | class SimpleBlend extends Transition { 4 | 5 | public var objectsMap : Map; 6 | 7 | public function new( anim1 : Animation, anim2 : Animation, objects : Map < String, Bool > ) { 8 | super("blend", anim1, anim2); 9 | this.objectsMap = objects; 10 | if( anim1.isInstance && anim2.isInstance ) 11 | setupInstance(); 12 | } 13 | 14 | function setupInstance() { 15 | for( o in anim1.objects.copy() ) 16 | if( objectsMap.get(o.objectName) ) 17 | anim1.unbind(o.objectName); 18 | for( o in anim2.objects.copy() ) 19 | if( !objectsMap.get(o.objectName) ) 20 | anim2.unbind(o.objectName); 21 | isInstance = true; 22 | } 23 | 24 | override function clone(?a : Animation) : Animation { 25 | var a : SimpleBlend = cast a; 26 | if( a == null ) 27 | a = new SimpleBlend(anim1, anim2, objectsMap); 28 | super.clone(a); 29 | a.objectsMap = objectsMap; 30 | return a; 31 | } 32 | 33 | override function createInstance( base ) { 34 | return new SimpleBlend(anim1.createInstance(base), anim2.createInstance(base), objectsMap); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /h3d/col/FPoint.hx: -------------------------------------------------------------------------------- 1 | package h3d.col; 2 | using hxd.Math; 3 | 4 | class FPoint { 5 | 6 | public var x : hxd.impl.Float32; 7 | public var y : hxd.impl.Float32; 8 | public var z : hxd.impl.Float32; 9 | 10 | public inline function new(x=0.,y=0.,z=0.) { 11 | this.x = x; 12 | this.y = y; 13 | this.z = z; 14 | } 15 | 16 | public inline function set(x=0.,y=0.,z=0.) { 17 | this.x = x; 18 | this.y = y; 19 | this.z = z; 20 | } 21 | 22 | public inline function sub( p : FPoint ) { 23 | return new FPoint(x - p.x, y - p.y, z - p.z); 24 | } 25 | 26 | public inline function add( p : FPoint ) { 27 | return new FPoint(x + p.x, y + p.y, z + p.z); 28 | } 29 | 30 | public inline function cross( p : FPoint ) { 31 | return new FPoint(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); 32 | } 33 | 34 | public inline function dot( p : FPoint ) { 35 | return x * p.x + y * p.y + z * p.z; 36 | } 37 | 38 | public inline function distanceSq( v : FPoint ) { 39 | var dx = v.x - x; 40 | var dy = v.y - y; 41 | var dz = v.z - z; 42 | return dx * dx + dy * dy + dz * dz; 43 | } 44 | 45 | public inline function lengthSq() { 46 | return x * x + y * y + z * z; 47 | } 48 | 49 | public inline function normalized() { 50 | var k = lengthSq(); 51 | if ( k < hxd.Math.EPSILON2 ) k = 0 else k = k.invSqrt(); 52 | return new FPoint(x * k, y * k, z * k); 53 | } 54 | 55 | public inline function scaled(v : Float) { 56 | return new FPoint(x * v, y * v, z * v); 57 | } 58 | 59 | public function toString() { 60 | return 'FPoint{${x.fmt()},${y.fmt()},${z.fmt()}}'; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /h3d/col/Point.hx: -------------------------------------------------------------------------------- 1 | package h3d.col; 2 | 3 | typedef Point = h3d.Vector; -------------------------------------------------------------------------------- /h3d/col/Seg.hx: -------------------------------------------------------------------------------- 1 | package h3d.col; 2 | import hxd.Math; 3 | 4 | class Seg { 5 | 6 | public var p1 : Point; 7 | public var p2 : Point; 8 | public var lenSq : Float; 9 | 10 | public inline function new( p1 : Point, p2 : Point ) { 11 | this.p1 = p1; 12 | this.p2 = p2; 13 | lenSq = p1.distanceSq(p2); 14 | } 15 | 16 | public inline function distanceSq( p : Point ) { 17 | var t = p.sub(p1).dot(p2.sub(p1)) / lenSq; 18 | return if( t < 0 ) 19 | p.distanceSq(p1); 20 | else if( t > 1 ) { 21 | p.distanceSq(p2); 22 | } else 23 | p.distanceSq(new Point(p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y), p1.z + t * (p2.z - p1.z))); 24 | } 25 | 26 | public inline function distance( p : Point ) { 27 | return Math.sqrt(distanceSq(p)); 28 | } 29 | 30 | public function toString() { 31 | return 'Seg{$p1,$p2}'; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /h3d/impl/MacroHelper.hx: -------------------------------------------------------------------------------- 1 | package h3d.impl; 2 | import haxe.macro.Context; 3 | import haxe.macro.Expr; 4 | 5 | class MacroHelper { 6 | 7 | #if macro 8 | 9 | static function replaceGLLoop( e : Expr ) { 10 | switch( e.expr ) { 11 | case EConst(CIdent("gl")): 12 | e.expr = EConst(CIdent("GL")); 13 | default: 14 | haxe.macro.ExprTools.iter(e, replaceGLLoop); 15 | } 16 | } 17 | 18 | public static function replaceGL() { 19 | var fields = Context.getBuildFields(); 20 | for( f in fields ) 21 | switch( f.kind ) { 22 | case FFun(f): 23 | if( f.expr != null ) replaceGLLoop(f.expr); 24 | case FVar(_,e): 25 | if( e != null ) replaceGLLoop(e); 26 | default: 27 | } 28 | return fields; 29 | } 30 | 31 | #end 32 | 33 | public static macro function getResourcesPath() { 34 | var dir = haxe.macro.Context.definedValue("resourcesPath"); 35 | if( dir == null ) dir = "res"; 36 | return macro $v{try Context.resolvePath(dir) catch( e : Dynamic ) null}; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /h3d/impl/NullDriver.hx: -------------------------------------------------------------------------------- 1 | package h3d.impl; 2 | import h3d.impl.Driver; 3 | 4 | class NullDriver extends Driver { 5 | 6 | var cur : hxsl.RuntimeShader; 7 | 8 | public function new() { 9 | } 10 | 11 | override function hasFeature( f : Feature ) { 12 | return true; 13 | } 14 | 15 | override function isSupportedFormat( fmt : h3d.mat.Data.TextureFormat ) { 16 | return true; 17 | } 18 | 19 | override function logImpl(str:String) { 20 | #if sys 21 | Sys.println(str); 22 | #else 23 | trace(str); 24 | #end 25 | } 26 | 27 | override function isDisposed() { 28 | return false; 29 | } 30 | 31 | override function getDriverName( details : Bool ) { 32 | return "NullDriver"; 33 | } 34 | 35 | override function init( onCreate : Bool -> Void, forceSoftware = false ) { 36 | onCreate(false); 37 | } 38 | 39 | override function selectShader( shader : hxsl.RuntimeShader ) { 40 | if( cur == shader ) return false; 41 | cur = shader; 42 | return true; 43 | } 44 | 45 | override function allocTexture( t : h3d.mat.Texture ) : Texture { 46 | return cast {}; 47 | } 48 | 49 | override function allocBuffer( b : Buffer ) : GPUBuffer { 50 | return cast {}; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /h3d/impl/RendererFX.hx: -------------------------------------------------------------------------------- 1 | package h3d.impl; 2 | 3 | enum Step { 4 | MainDraw; 5 | Decals; 6 | Shadows; 7 | Lighting; 8 | Forward; 9 | BeforeTonemapping; 10 | AfterTonemapping; 11 | Overlay; 12 | Custom( name : String ); 13 | } 14 | 15 | interface RendererFX { 16 | public var enabled : Bool; 17 | public function start( r : h3d.scene.Renderer ) : Void; 18 | public function begin( r : h3d.scene.Renderer, step : Step ) : Void; 19 | public function end( r : h3d.scene.Renderer, step : Step ) : Void; 20 | public function dispose() : Void; 21 | } 22 | -------------------------------------------------------------------------------- /h3d/mat/BlendMode.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | 3 | typedef BlendMode = h2d.BlendMode; -------------------------------------------------------------------------------- /h3d/mat/Defaults.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | 3 | class Defaults { 4 | 5 | public static var defaultKillAlphaThreshold = 0.5; 6 | public static var loadingTextureColor = 0xFFFF00FF; 7 | 8 | @:isVar public static var shadowShader(get, set) : hxsl.Shader; 9 | 10 | // delay initialization if needed only 11 | static function get_shadowShader() { 12 | var s = shadowShader; 13 | if( s == null ) { 14 | shadowShader = s = new h3d.shader.Shadow(); 15 | shadowShader.setPriority(-1); 16 | } 17 | return s; 18 | } 19 | 20 | static function set_shadowShader(s) { 21 | return shadowShader = s; 22 | } 23 | 24 | public dynamic static function makeVolumeDecal( bounds : h3d.col.Bounds ) : hxsl.Shader { 25 | return new h3d.shader.VolumeDecal(bounds.xSize, bounds.ySize); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /h3d/mat/MaterialSetup.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | 3 | class MaterialSetup { 4 | 5 | public var name(default,null) : String; 6 | public var displayName(default,null) : String; 7 | var database : MaterialDatabase; 8 | var emptyMat : h3d.mat.Material; 9 | 10 | public function new(name) { 11 | if( database == null ) 12 | database = new MaterialDatabase(); 13 | this.name = name; 14 | } 15 | 16 | public function createRenderer() : h3d.scene.Renderer { 17 | return new h3d.scene.fwd.Renderer(); 18 | } 19 | 20 | public function createLightSystem() : h3d.scene.LightSystem { 21 | return new h3d.scene.fwd.LightSystem(); 22 | } 23 | 24 | public function createMaterial() { 25 | return @:privateAccess new h3d.mat.Material(); 26 | } 27 | 28 | public function getDefaults( ?kind : String ) { 29 | if( emptyMat == null ) emptyMat = createMaterial(); 30 | return emptyMat.getDefaultProps(kind); 31 | } 32 | 33 | public function loadMaterialProps( material : h3d.mat.Material ) { 34 | return database.loadMatProps(material, this); 35 | } 36 | 37 | public function saveMaterialProps( material : Material, ?defaultProps : Any ) { 38 | database.saveMatProps(material, this, defaultProps); 39 | } 40 | 41 | /* 42 | Can be used to perform custom mesh initialization such as computing extra buffers 43 | when loading it from HSD or displaying it in tools. 44 | */ 45 | public function customMeshInit( mesh : h3d.scene.Mesh ) { 46 | } 47 | 48 | public static var current = new MaterialSetup("Default"); 49 | 50 | } -------------------------------------------------------------------------------- /h3d/mat/PbrMaterialSetup.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | 3 | class PbrMaterialSetup extends MaterialSetup { 4 | 5 | public function new(?name="PBR") { 6 | super(name); 7 | } 8 | 9 | override function createRenderer() : h3d.scene.Renderer { 10 | #if js 11 | // fallback to default renderer (prevent errors) 12 | if( !h3d.Engine.getCurrent().driver.hasFeature(ShaderModel3) ) { 13 | js.Browser.console.log("Could not initialize PBR Driver: WebGL2 required"); 14 | return super.createRenderer(); 15 | } 16 | #end 17 | return new h3d.scene.pbr.Renderer(h3d.scene.pbr.Environment.getDefault()); 18 | } 19 | 20 | override function createLightSystem() { 21 | return new h3d.scene.pbr.LightSystem(); 22 | } 23 | 24 | override function createMaterial() : Material { 25 | return @:privateAccess new PbrMaterial(); 26 | } 27 | 28 | #if (hide && (sys || nodejs)) 29 | public function createAtlasShader() { 30 | return new hrt.prefab.l3d.modellibrary.AtlasShader(); 31 | } 32 | #end 33 | 34 | public static function set() { 35 | MaterialSetup.current = new PbrMaterialSetup(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /h3d/mat/Texture3D.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | import h3d.mat.Data; 3 | 4 | class Texture3D extends Texture { 5 | 6 | var depth : Int; 7 | 8 | public function new(w, h, d, ?flags : Array, ?format : TextureFormat ) { 9 | this.depth = d; 10 | if( flags == null ) flags = []; 11 | flags.push(Is3D); 12 | super(w,h,flags,format); 13 | } 14 | 15 | override function get_layerCount() { 16 | return depth; 17 | } 18 | 19 | override function clone() { 20 | var old = lastFrame; 21 | preventAutoDispose(); 22 | var t = new Texture3D(width, height, depth, null, format); 23 | h3d.pass.Copy.run(this, t); 24 | lastFrame = old; 25 | return t; 26 | } 27 | 28 | override function toString() { 29 | return super.toString()+"x("+depth+")"; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/mat/TextureArray.hx: -------------------------------------------------------------------------------- 1 | package h3d.mat; 2 | import h3d.mat.Data; 3 | 4 | class TextureArray extends Texture { 5 | 6 | var layers : Int; 7 | 8 | public function new(w, h, layers, ?flags : Array, ?format : TextureFormat ) { 9 | this.layers = layers; 10 | if( flags == null ) flags = []; 11 | flags.push(IsArray); 12 | super(w,h,flags,format); 13 | } 14 | 15 | override function get_layerCount() { 16 | return layers; 17 | } 18 | 19 | override function clone() { 20 | var old = lastFrame; 21 | preventAutoDispose(); 22 | var t = new TextureArray(width, height, layers, null, format); 23 | h3d.pass.Copy.run(this, t); 24 | lastFrame = old; 25 | return t; 26 | } 27 | 28 | override function toString() { 29 | return super.toString()+"["+layers+"]"; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/parts/Collider.hx: -------------------------------------------------------------------------------- 1 | package h3d.parts; 2 | 3 | interface Collider { 4 | 5 | public function collidePart( p : Particle, normal : h3d.Vector ) : Bool; 6 | 7 | } -------------------------------------------------------------------------------- /h3d/parts/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/parts/default.png -------------------------------------------------------------------------------- /h3d/parts/defaultAlpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/parts/defaultAlpha.png -------------------------------------------------------------------------------- /h3d/pass/Border.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | private class BorderShader extends h3d.shader.ScreenShader { 4 | static var SRC = { 5 | 6 | @param var color : Vec4; 7 | 8 | function fragment() { 9 | pixelColor = color; 10 | } 11 | 12 | } 13 | } 14 | 15 | class Border extends ScreenFx { 16 | 17 | var width(default, null) : Int; 18 | var height(default, null) : Int; 19 | var size(default, null) : Int; 20 | 21 | public function new( width : Int, height : Int, size : Int = 1 ) { 22 | super(new BorderShader()); 23 | this.width = width; 24 | this.height = height; 25 | this.size = size; 26 | shader.color.set(1,1,1,1); 27 | } 28 | 29 | function createPrimitive() { 30 | var bbuf = new hxd.FloatBuffer(); 31 | inline function add(x, y) { 32 | bbuf.push((x / width) * 2 - 1); 33 | bbuf.push(1 - (y / height) * 2); 34 | } 35 | add(0, 0); 36 | add(width, 0); 37 | add(0, size); 38 | add(width, size); 39 | 40 | add(0, 0); 41 | add(size, 0); 42 | add(0, height); 43 | add(size, height); 44 | 45 | add(0, height-size); 46 | add(width, height-size); 47 | add(0, height); 48 | add(width, height); 49 | 50 | add(width-size, 0); 51 | add(width, 0); 52 | add(width-size, height); 53 | add(width, height); 54 | 55 | this.primitive = new h3d.prim.RawPrimitive({ vbuf : bbuf, format : hxd.BufferFormat.make([{ name : "position", type : DVec2 }]) }, true); 56 | } 57 | 58 | override function render() { 59 | if (primitive == null) 60 | createPrimitive(); 61 | super.render(); 62 | } 63 | 64 | override function dispose() { 65 | if (primitive != null) 66 | this.primitive.dispose(); 67 | super.dispose(); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /h3d/pass/CubeCopy.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | private class CubeCopyShader extends h3d.shader.ScreenShader { 4 | 5 | static var SRC = { 6 | @param var texture : SamplerCube; 7 | @param var mat : Mat3; 8 | function fragment() { 9 | var uv = calculatedUV * 2.0 - 1.0; 10 | pixelColor = texture.get(normalize(vec3(uv, 1) * mat)); 11 | } 12 | } 13 | } 14 | 15 | class CubeCopy extends ScreenFx { 16 | 17 | var cubeDir = [ h3d.Matrix.L([0,0,-1,0, 0,-1,0,0, 1,0,0,0]), 18 | h3d.Matrix.L([0,0,1,0, 0,-1,0,0, -1,0,0,0]), 19 | h3d.Matrix.L([1,0,0,0, 0,0,1,0, 0,1,0,0]), 20 | h3d.Matrix.L([1,0,0,0, 0,0,-1,0, 0,-1,0,0]), 21 | h3d.Matrix.L([1,0,0,0, 0,-1,0,0, 0,0,1,0]), 22 | h3d.Matrix.L([-1,0,0,0, 0,-1,0,0, 0,0,-1,0]) ]; 23 | 24 | public function new() { 25 | super(new CubeCopyShader()); 26 | } 27 | 28 | public function apply( from, to, ?blend : h3d.mat.BlendMode, mip : Int = 0 ) { 29 | shader.texture = from; 30 | for(i in 0 ... 6){ 31 | if( to != null ) 32 | engine.pushTarget(to, i, mip); 33 | shader.mat = cubeDir[i]; 34 | pass.setBlendMode(blend == null ? None : blend); 35 | render(); 36 | if( to != null ) 37 | engine.popTarget(); 38 | } 39 | shader.texture = null; 40 | } 41 | 42 | public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode, mip : Int = 0 ) { 43 | var engine = h3d.Engine.getCurrent(); 44 | if( to != null && from != null && (blend == null || blend == None) && mip == 0 && engine.driver.copyTexture(from, to) ) 45 | return; 46 | var inst : CubeCopy = @:privateAccess engine.resCache.get(CubeCopy); 47 | if( inst == null ) { 48 | inst = new CubeCopy(); 49 | @:privateAccess engine.resCache.set(CubeCopy, inst); 50 | } 51 | return inst.apply(from, to, blend, mip); 52 | } 53 | } -------------------------------------------------------------------------------- /h3d/pass/DefaultShadowMap.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | class DefaultShadowMap extends DirShadowMap { 4 | 5 | var shadowMapId : Int; 6 | var shadowProjId : Int; 7 | var shadowColorId : Int; 8 | var shadowPowerId : Int; 9 | var shadowBiasId : Int; 10 | 11 | public var color : h3d.Vector; 12 | 13 | public function new(size=1024,?format:hxd.PixelFormat) { 14 | if( format != null ) 15 | this.format = format; 16 | super(null); 17 | this.size = size; 18 | color = new h3d.Vector(); 19 | mode = Dynamic; 20 | shadowMapId = hxsl.Globals.allocID("shadow.map"); 21 | shadowProjId = hxsl.Globals.allocID("shadow.proj"); 22 | shadowColorId = hxsl.Globals.allocID("shadow.color"); 23 | shadowPowerId = hxsl.Globals.allocID("shadow.power"); 24 | shadowBiasId = hxsl.Globals.allocID("shadow.bias"); 25 | } 26 | 27 | override function draw( passes, ?sort ) { 28 | super.draw(passes, sort); 29 | ctx.globals.fastSet(shadowMapId, { texture : dshader.shadowMap, channel : format == h3d.mat.Texture.nativeFormat ? hxsl.Channel.PackedFloat : hxsl.Channel.R }); 30 | ctx.globals.fastSet(shadowProjId, getShadowProj()); 31 | ctx.globals.fastSet(shadowColorId, color); 32 | ctx.globals.fastSet(shadowPowerId, power); 33 | ctx.globals.fastSet(shadowBiasId, bias); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /h3d/pass/Outline.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | @ignore("shader") 4 | class Outline extends ScreenFx { 5 | public var size : Float; 6 | public var color : Int; 7 | public var alpha : Float = 1.; 8 | public var quality : Float; 9 | public var multiplyAlpha : Bool; 10 | 11 | public function new(size = 4.0, color = 0x000000, quality = 0.3, multiplyAlpha = true) { 12 | super(new h3d.shader.Outline2D()); 13 | this.size = size; 14 | this.color = color; 15 | this.quality = quality; 16 | this.multiplyAlpha = multiplyAlpha; 17 | } 18 | 19 | public function apply(ctx : h3d.impl.RenderContext, src : h3d.mat.Texture, ?output : h3d.mat.Texture) { 20 | if (output == null) 21 | output = src; 22 | var tmp = ctx.textures.allocTarget(src.name + "OutlineTmp", src.width, src.height, false, src.format); 23 | shader.color.setColor(color); 24 | shader.color.a = alpha; 25 | shader.size.set(size / src.width, size / src.height); 26 | shader.samples = Std.int(Math.max(quality * 100, 1)); 27 | shader.multiplyAlpha = multiplyAlpha ? 0 : 1; 28 | 29 | shader.texture = src; 30 | engine.pushTarget(tmp); 31 | render(); 32 | engine.popTarget(); 33 | 34 | shader.texture = tmp; 35 | var outDepth = output.depthBuffer; 36 | output.depthBuffer = null; 37 | engine.pushTarget(output); 38 | render(); 39 | engine.popTarget(); 40 | output.depthBuffer = outDepth; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /h3d/pass/OutputShader.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | class OutputShader { 4 | 5 | var shaderCache : hxsl.Cache; 6 | var currentOutput : hxsl.ShaderList; 7 | 8 | public function new(?output:Array) { 9 | shaderCache = hxsl.Cache.get(); 10 | currentOutput = new hxsl.ShaderList(null); 11 | setOutput(output); 12 | } 13 | 14 | public function setOutput( ?output : Array ) { 15 | if( output == null ) output = [Value("output.color")]; 16 | currentOutput.s = shaderCache.getLinkShader(output); 17 | } 18 | 19 | public function compileShaders( globals : hxsl.Globals, shaders : hxsl.ShaderList, mode : hxsl.RuntimeShader.LinkMode = Default ) { 20 | globals.resetChannels(); 21 | for( s in shaders ) s.updateConstants(globals); 22 | currentOutput.next = shaders; 23 | var s = shaderCache.link(currentOutput, mode); 24 | currentOutput.next = null; 25 | return s; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /h3d/pass/PassObject.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | class PassObject { 4 | @:noCompletion public var next : PassObject; 5 | var nextAlloc : PassObject; 6 | public var pass : h3d.mat.Pass; 7 | public var obj : h3d.scene.Object; 8 | public var index : Int; 9 | 10 | // cache 11 | public var shaders : hxsl.ShaderList; 12 | public var shader : hxsl.RuntimeShader; 13 | public var depth : Float; 14 | public var texture : Int = 0; 15 | 16 | function new() { 17 | } 18 | } -------------------------------------------------------------------------------- /h3d/pass/ScalableAO.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | class ScalableAO extends h3d.pass.ScreenFx { 4 | 5 | public function new() { 6 | super(new h3d.shader.SAO()); 7 | } 8 | 9 | public function apply( depthTexture : h3d.mat.Texture, normalTexture : h3d.mat.Texture, camera : h3d.Camera ) { 10 | shader.depthTexture = depthTexture; 11 | shader.normalTexture = normalTexture; 12 | shader.cameraView = camera.mcam; 13 | shader.cameraInverseViewProj = camera.getInverseViewProj(); 14 | shader.screenRatio.set(engine.height / engine.width, 1); 15 | shader.fovTan = 1.0 / (2.0 * Math.tan(camera.fovY * (Math.PI / 180) * 0.5)); 16 | render(); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /h3d/pass/SortByMaterial.hx: -------------------------------------------------------------------------------- 1 | package h3d.pass; 2 | 3 | class SortByMaterial { 4 | 5 | var shaderCount : Int = 1; 6 | var textureCount : Int = 1; 7 | var shaderIdMap : Array; 8 | var textureIdMap : Array; 9 | 10 | public function new() { 11 | shaderIdMap = []; 12 | textureIdMap = []; 13 | } 14 | 15 | public function sort( passes : PassList ) { 16 | var shaderStart = shaderCount, textureStart = textureCount; 17 | for( p in passes ) { 18 | if( shaderIdMap[p.shader.id] < shaderStart #if js || shaderIdMap[p.shader.id] == null #end ) 19 | shaderIdMap[p.shader.id] = shaderCount++; 20 | if( textureIdMap[p.texture] < textureStart #if js || textureIdMap[p.shader.id] == null #end ) 21 | textureIdMap[p.texture] = textureCount++; 22 | } 23 | passes.sort(function(o1, o2) { 24 | if ( o1.pass.layer != o2.pass.layer ) 25 | return o1.pass.layer - o2.pass.layer; 26 | var d = shaderIdMap[o1.shader.id] - shaderIdMap[o2.shader.id]; 27 | if( d != 0 ) return d; 28 | return textureIdMap[o1.texture] - textureIdMap[o2.texture]; 29 | }); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/prim/Disc.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | 3 | import h3d.col.Point; 4 | 5 | class Disc extends Polygon { 6 | 7 | public var radius(default,null) : Float; 8 | public var segments(default,null) : Int; 9 | 10 | public function new( radius = 0.5, segments = 8, thetaStart = 0.0, ?thetaLength : Float ) { 11 | if( segments < 3 ) segments = 3; 12 | if( thetaLength == null ) thetaLength = Math.PI * 2; 13 | this.radius = radius; 14 | this.segments = segments; 15 | var pts = [], idx = new hxd.IndexBuffer(); 16 | for( i in 0...segments ) { 17 | var a = thetaStart + i / segments * thetaLength; 18 | pts.push(new Point( radius * Math.cos(a), radius * Math.sin(a), 0 )); 19 | idx.push(i); 20 | idx.push((i == segments - 1) ? 0 : i + 1); 21 | idx.push(segments); 22 | } 23 | pts.push( new Point() ); 24 | super( pts, idx ); 25 | } 26 | 27 | override function addUVs() { 28 | uvs = []; 29 | for( i in 0...segments ) { 30 | uvs.push( new UV( (points[i].x / radius + 1) / 2, (points[i].y / radius + 1) / 2) ); 31 | } 32 | uvs.push( new UV( 0.5, 0.5 ) ); 33 | } 34 | 35 | /** 36 | * Get a default unit Disc with 37 | * radius = 0.5, segments = 8, thetaStart = 0.0, thetaLength = Math.PI * 2 38 | * and add UVs to it. If it has not be cached, it is cached and subsequent 39 | * calls to this method will return Disc from cache. 40 | */ 41 | public static function defaultUnitDisc() { 42 | var engine = h3d.Engine.getCurrent(); 43 | var d : Disc = @:privateAccess engine.resCache.get(Disc); 44 | if( d != null ) 45 | return d; 46 | d = new h3d.prim.Disc(); 47 | d.addUVs(); 48 | @:privateAccess engine.resCache.set(Disc, d); 49 | return d; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /h3d/prim/GeoSphere.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | import h3d.col.Point; 3 | 4 | class GeoSphere extends Polygon { 5 | 6 | public function new( subdiv = 2 ) { 7 | var a = 1 / Math.sqrt(2); 8 | var p = [new Point(0, 0, 1), new Point(0, 0, -1), new Point(-a, -a, 0), new Point(a, -a, 0), new Point(a, a, 0), new Point( -a, a, 0)]; 9 | var idx = new hxd.IndexBuffer(); 10 | idx.push(0); idx.push(3); idx.push(4); 11 | idx.push(0); idx.push(4); idx.push(5); 12 | idx.push(0); idx.push(5); idx.push(2); 13 | idx.push(0); idx.push(2); idx.push(3); 14 | idx.push(1); idx.push(4); idx.push(3); 15 | idx.push(1); idx.push(5); idx.push(4); 16 | idx.push(1); idx.push(2); idx.push(5); 17 | idx.push(1); idx.push(3); idx.push(2); 18 | for( k in 0...subdiv ) { 19 | var i = 0; 20 | var count = idx.length, np = p.length; 21 | var nidx = new hxd.IndexBuffer(); 22 | while( i < count ) { 23 | var p1 = p[idx[i]], p2 = p[idx[i + 1]], p3 = p[idx[i + 2]]; 24 | var pa = p1.add(p2); 25 | var pb = p2.add(p3); 26 | var pc = p3.add(p1); 27 | pa.normalize(); 28 | pb.normalize(); 29 | pc.normalize(); 30 | 31 | nidx.push(np); 32 | nidx.push(np + 1); 33 | nidx.push(np + 2); 34 | 35 | nidx.push(idx[i]); 36 | nidx.push(np); 37 | nidx.push(np + 2); 38 | 39 | nidx.push(np); 40 | nidx.push(idx[i + 1]); 41 | nidx.push(np + 1); 42 | 43 | nidx.push(np + 1); 44 | nidx.push(idx[i + 2]); 45 | nidx.push(np + 2); 46 | 47 | p[np++] = pa; 48 | p[np++] = pb; 49 | p[np++] = pc; 50 | i += 3; 51 | } 52 | idx = nidx; 53 | } 54 | super(p, idx); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /h3d/prim/Grid.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | 3 | class Grid extends Polygon { 4 | 5 | public var width (default, null) : Int; 6 | public var height (default, null) : Int; 7 | public var cellWidth (default, null) : Float; 8 | public var cellHeight (default, null) : Float; 9 | 10 | public function new( width : Int, height : Int, cellWidth = 1., cellHeight = 1. ) { 11 | this.width = width; 12 | this.height = height; 13 | this.cellWidth = cellWidth; 14 | this.cellHeight = cellHeight; 15 | 16 | var idx = new hxd.IndexBuffer(); 17 | for( y in 0...height ) 18 | for( x in 0...width ) { 19 | var s = x + y * (width + 1); 20 | idx.push(s); 21 | idx.push(s + 1); 22 | idx.push(s + width + 1); 23 | idx.push(s + 1); 24 | idx.push(s + width + 2); 25 | idx.push(s + width + 1); 26 | } 27 | super( 28 | [for( y in 0...height + 1 ) for( x in 0...width + 1 ) new h3d.col.Point(x * cellWidth, y * cellHeight, 0)], 29 | idx 30 | ); 31 | } 32 | 33 | override function addUVs() { 34 | uvs = []; 35 | for(i in 0 ... points.length){ 36 | var y = hxd.Math.floor(i / (width + 1)); 37 | var x = i - y * (width + 1); 38 | uvs.push(new UV(x/width,y/height)); 39 | } 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /h3d/prim/Plane2D.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | 3 | class Plane2D extends Primitive { 4 | 5 | public function new() { 6 | } 7 | 8 | override function triCount() { 9 | return 2; 10 | } 11 | 12 | override function vertexCount() { 13 | return 4; 14 | } 15 | 16 | override function alloc( engine : h3d.Engine ) { 17 | var v = new hxd.FloatBuffer(); 18 | v.push( -1); 19 | v.push( -1); 20 | v.push( 0); 21 | v.push( 1 ); 22 | 23 | v.push( -1); 24 | v.push( 1); 25 | v.push( 0); 26 | v.push( 0); 27 | 28 | v.push( 1); 29 | v.push( -1); 30 | v.push( 1); 31 | v.push( 1); 32 | 33 | v.push( 1); 34 | v.push( 1); 35 | v.push( 1); 36 | v.push( 0); 37 | 38 | buffer = h3d.Buffer.ofFloats(v, hxd.BufferFormat.XY_UV); 39 | } 40 | 41 | override function render(engine:h3d.Engine) { 42 | if( buffer == null || buffer.isDisposed() ) alloc(engine); 43 | engine.renderQuadBuffer(buffer); 44 | } 45 | 46 | public static function get() { 47 | var engine = h3d.Engine.getCurrent(); 48 | var inst = @:privateAccess engine.resCache.get(Plane2D); 49 | if( inst == null ) { 50 | inst = new Plane2D(); 51 | @:privateAccess engine.resCache.set(Plane2D, inst); 52 | } 53 | return inst; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /h3d/prim/RawPrimitive.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | 3 | class RawPrimitive extends Primitive { 4 | 5 | var vcount : Int; 6 | var tcount : Int; 7 | var bounds : h3d.col.Bounds; 8 | public var onContextLost : Void -> { vbuf : hxd.FloatBuffer, format : hxd.BufferFormat, ?ibuf : hxd.IndexBuffer }; 9 | 10 | public function new( inf : { vbuf : hxd.FloatBuffer, format : hxd.BufferFormat, ?ibuf : hxd.IndexBuffer, ?bounds : h3d.col.Bounds }, persist = false ) { 11 | onContextLost = function() return inf; 12 | this.bounds = inf.bounds; 13 | alloc(null); 14 | if( !persist ) onContextLost = null; 15 | } 16 | 17 | override function alloc( engine : h3d.Engine ) { 18 | if( onContextLost == null ) throw "Cannot realloc " + this; 19 | var inf = onContextLost(); 20 | buffer = h3d.Buffer.ofFloats(inf.vbuf, inf.format); 21 | vcount = buffer.vertices; 22 | tcount = inf.ibuf != null ? Std.int(inf.ibuf.length / 3) : Std.int(vcount/3); 23 | if( inf.ibuf != null ) 24 | indexes = h3d.Indexes.alloc(inf.ibuf); 25 | else if( indexes != null ) { 26 | indexes.dispose(); 27 | indexes = null; 28 | } 29 | } 30 | 31 | override public function getBounds() { 32 | if( bounds == null ) throw "Bounds not defined for " + this; 33 | return bounds; 34 | } 35 | 36 | override function triCount() { 37 | return tcount; 38 | } 39 | 40 | override function vertexCount() { 41 | return vcount; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /h3d/prim/UV.hx: -------------------------------------------------------------------------------- 1 | package h3d.prim; 2 | 3 | class UV { 4 | 5 | public var u : Float; 6 | public var v : Float; 7 | 8 | public function new(u,v) { 9 | this.u = u; 10 | this.v = v; 11 | } 12 | 13 | public function clone() { 14 | return new UV(u, v); 15 | } 16 | 17 | function toString() { 18 | return "{" + hxd.Math.fmt(u) + "," + hxd.Math.fmt(v) + "}"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /h3d/scene/Light.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene; 2 | 3 | class Light extends Object { 4 | 5 | var shader : hxsl.Shader; 6 | @:noCompletion public var next : Light; // used internaly (public to allow sorting) 7 | 8 | public var color(get, set) : h3d.Vector; 9 | 10 | function new(shader,?parent) { 11 | super(parent); 12 | this.shader = shader; 13 | } 14 | 15 | // dummy implementation 16 | function get_color() { 17 | return new h3d.Vector(); 18 | } 19 | 20 | function set_color(v:h3d.Vector) { 21 | return v; 22 | } 23 | 24 | override function emit(ctx:RenderContext) { 25 | ctx.emitLight(this); 26 | } 27 | 28 | function getShadowDirection() : h3d.Vector { 29 | return null; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/scene/LightSystem.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene; 2 | 3 | class LightSystem { 4 | 5 | public var drawPasses : Int = 0; 6 | public var shadowLight : h3d.scene.Light; 7 | 8 | var ctx : RenderContext; 9 | 10 | public function new() { 11 | } 12 | 13 | public function initGlobals( globals : hxsl.Globals ) { 14 | } 15 | 16 | public function initLights( ctx : h3d.scene.RenderContext ) @:privateAccess { 17 | this.ctx = ctx; 18 | if( shadowLight == null || !shadowLight.allocated) { 19 | var l = ctx.lights; 20 | while( l != null ) { 21 | var dir = l.getShadowDirection(); 22 | if( dir != null ) { 23 | shadowLight = l; 24 | break; 25 | } 26 | l = l.next; 27 | } 28 | } 29 | } 30 | 31 | public function computeLight( obj : h3d.scene.Object, shaders : hxsl.ShaderList ) : hxsl.ShaderList { 32 | return shaders; 33 | } 34 | 35 | public function dispose(){ 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /h3d/scene/MultiMaterial.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene; 2 | 3 | class MultiMaterial extends Mesh { 4 | 5 | public var materials : Array; 6 | 7 | public function new( prim, ?mats, ?parent ) { 8 | super(prim, mats == null ? null : mats[0], parent); 9 | this.materials = mats == null ? [material] : mats; 10 | } 11 | 12 | override function getMeshMaterials() { 13 | return materials.copy(); 14 | } 15 | 16 | override function clone( ?o : Object ) { 17 | var m = o == null ? new MultiMaterial(null, materials) : cast o; 18 | m.materials = []; 19 | for( mat in materials ) 20 | m.materials.push(if( mat == null ) null else cast mat.clone()); 21 | super.clone(m); 22 | m.material = m.materials[0]; 23 | return m; 24 | } 25 | 26 | override function emit( ctx : RenderContext ) { 27 | calcScreenRatio(ctx); 28 | if ( primitive.screenRatioToLod(curScreenRatio) >= primitive.lodCount() ) 29 | return; 30 | for( i in 0...materials.length ) { 31 | var m = materials[i]; 32 | if( m != null ) 33 | ctx.emit(m, this, i); 34 | } 35 | } 36 | 37 | override function getMaterialByName( name : String ) : h3d.mat.Material { 38 | for( m in materials ) 39 | if( m != null && m.name == name ) 40 | return m; 41 | return super.getMaterialByName(name); 42 | } 43 | 44 | override function getMaterials( ?a : Array, recursive = true ) { 45 | if( a == null ) a = []; 46 | for( m in materials ) 47 | if( m != null && a.indexOf(m) < 0 ) 48 | a.push(m); 49 | if( recursive ) { 50 | for( o in children ) 51 | o.getMaterials(a); 52 | } 53 | return a; 54 | } 55 | 56 | override function draw( ctx : RenderContext ) { 57 | if( materials.length > 1 ) 58 | primitive.selectMaterial(ctx.drawPass.index, primitive.screenRatioToLod(curScreenRatio)); 59 | primitive.render(ctx.engine); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /h3d/scene/Sphere.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene; 2 | 3 | class Sphere extends Graphics { 4 | 5 | public var color : Int; 6 | public var radius(default, set) : Float; 7 | 8 | public function new( ?color = 0xFFFF0000, ?radius : Float=1.0, ?depth = true, ?parent) { 9 | super(parent); 10 | this.color = color; 11 | this.radius = radius; 12 | if( !depth ) material.mainPass.depth(true, Always); 13 | } 14 | 15 | function set_radius(v: Float) { 16 | this.radius = v; 17 | refresh(); 18 | return v; 19 | } 20 | 21 | function refresh() { 22 | clear(); 23 | lineStyle(1, color); 24 | 25 | var nsegments = 32; 26 | 27 | inline function circle(f) { 28 | for(i in 0...nsegments) { 29 | var c = hxd.Math.cos(i / (nsegments - 1) * hxd.Math.PI * 2.0) * radius; 30 | var s = hxd.Math.sin(i / (nsegments - 1) * hxd.Math.PI * 2.0) * radius; 31 | f(i, c, s); 32 | } 33 | } 34 | inline function seg(i, x, y, z) { 35 | if(i == 0) 36 | moveTo(x, y, z); 37 | else 38 | lineTo(x, y, z); 39 | } 40 | 41 | circle(function(i, c, s) return seg(i, c, s, 0)); 42 | circle(function(i, c, s) return seg(i, 0, c, s)); 43 | circle(function(i, c, s) return seg(i, c, 0, s)); 44 | } 45 | 46 | override function getLocalCollider() { 47 | return null; 48 | } 49 | 50 | override function sync(ctx) { 51 | super.sync(ctx); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /h3d/scene/fwd/DirLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.fwd; 2 | 3 | class DirLight extends Light { 4 | 5 | var dshader : h3d.shader.DirLight; 6 | 7 | public function new(?dir: h3d.Vector, ?parent) { 8 | dshader = new h3d.shader.DirLight(); 9 | super(dshader, parent); 10 | priority = 100; 11 | if( dir != null ) setDirection(dir); 12 | } 13 | 14 | override function get_color() { 15 | return dshader.color; 16 | } 17 | 18 | override function set_color(v) { 19 | return dshader.color = v; 20 | } 21 | 22 | override function get_enableSpecular() { 23 | return dshader.enableSpecular; 24 | } 25 | 26 | override function set_enableSpecular(b) { 27 | return dshader.enableSpecular = b; 28 | } 29 | 30 | override function getShadowDirection() : h3d.Vector { 31 | return absPos.front(); 32 | } 33 | 34 | override function emit(ctx) { 35 | dshader.direction.load(absPos.front()); 36 | dshader.direction.normalize(); 37 | super.emit(ctx); 38 | } 39 | } -------------------------------------------------------------------------------- /h3d/scene/fwd/Light.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.fwd; 2 | 3 | class Light extends h3d.scene.Light { 4 | 5 | var objectDistance : Float; // used internaly 6 | var cullingDistance : Float = -1; 7 | public var priority : Int = 0; 8 | public var enableSpecular(get, set) : Bool; 9 | 10 | function get_enableSpecular() { 11 | return false; 12 | } 13 | 14 | function set_enableSpecular(b) { 15 | if( b ) throw "Not implemented for this light"; 16 | return false; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /h3d/scene/fwd/PointLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.fwd; 2 | 3 | class PointLight extends Light { 4 | 5 | var pshader : h3d.shader.PointLight; 6 | public var params(get, set) : h3d.Vector; 7 | 8 | public function new(?parent) { 9 | pshader = new h3d.shader.PointLight(); 10 | super(pshader, parent); 11 | } 12 | 13 | override function get_color() { 14 | return pshader.color; 15 | } 16 | 17 | override function set_color(v) { 18 | return pshader.color = v; 19 | } 20 | 21 | override function get_enableSpecular() { 22 | return pshader.enableSpecular; 23 | } 24 | 25 | override function set_enableSpecular(b) { 26 | return pshader.enableSpecular = b; 27 | } 28 | 29 | inline function get_params() { 30 | return pshader.params; 31 | } 32 | 33 | inline function set_params(p) { 34 | return pshader.params = p; 35 | } 36 | 37 | override function emit(ctx) { 38 | var lum = hxd.Math.max(hxd.Math.max(color.r, color.g), color.b); 39 | var p = params; 40 | // solve lum / (x + y.d + z.d²) < 1/128 41 | if( p.z == 0 ) { 42 | cullingDistance = (lum * 128 - p.x) / p.y; 43 | } else { 44 | var delta = p.y * p.y - 4 * p.z * (p.x - lum * 128); 45 | cullingDistance = (p.y + Math.sqrt(delta)) / (2 * p.z); 46 | } 47 | pshader.lightPosition.set(absPos._41, absPos._42, absPos._43); 48 | super.emit(ctx); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /h3d/scene/pbr/Decal.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.pbr; 2 | 3 | class Decal extends Mesh { 4 | 5 | public function new( primitive, ?material, ?parent ) { 6 | super(primitive, material, parent); 7 | } 8 | 9 | override function emit( ctx : RenderContext ) { 10 | super.emit(ctx); 11 | 12 | if(ctx.visibleFlag) { 13 | var shader = material.mainPass.getShader(h3d.shader.pbr.VolumeDecal.DecalPBR); 14 | if( shader != null ) { 15 | var absPos = getAbsPos(); 16 | shader.normal.set(absPos._31, absPos._32, absPos._33); // up 17 | shader.tangent.set(absPos._21, absPos._22, absPos._23); // right 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /h3d/scene/pbr/DirLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.pbr; 2 | 3 | class DirLight extends Light { 4 | 5 | var pbr : h3d.shader.pbr.Light.DirLight; 6 | 7 | public function new(?dir: h3d.Vector, ?parent, ?cascade) { 8 | pbr = new h3d.shader.pbr.Light.DirLight(); 9 | shadows = cascade ? new h3d.pass.CascadeShadowMap(this) : new h3d.pass.DirShadowMap(this); 10 | super(pbr,parent); 11 | if( dir != null ) setDirection(dir); 12 | } 13 | 14 | public override function clone( ?o : h3d.scene.Object ) : h3d.scene.Object { 15 | var dl = o == null ? new DirLight(null) : cast o; 16 | super.clone(dl); 17 | return dl; 18 | } 19 | 20 | override function getShadowDirection() : h3d.Vector { 21 | return absPos.front(); 22 | } 23 | 24 | override function emit(ctx:RenderContext) { 25 | pbr.lightColor.load(_color); 26 | pbr.lightColor.scale(power * power); 27 | pbr.lightDir.load(absPos.front()); 28 | pbr.lightDir.scale(-1); 29 | pbr.lightDir.normalize(); 30 | pbr.occlusionFactor = occlusionFactor; 31 | super.emit(ctx); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /h3d/scene/pbr/Light.hx: -------------------------------------------------------------------------------- 1 | package h3d.scene.pbr; 2 | 3 | class Light extends h3d.scene.Light { 4 | 5 | var _color : h3d.Vector; 6 | var primitive : h3d.prim.Primitive; 7 | public var power : Float = 1.; 8 | public var shadows : h3d.pass.Shadows; 9 | public var isMainLight = false; 10 | public var occlusionFactor : Float = 0.; 11 | public var enableForward : Bool = true; 12 | 13 | function new(shader,?parent) { 14 | super(shader,parent); 15 | _color = new h3d.Vector(1,1,1); 16 | if( shadows == null ) shadows = new h3d.pass.Shadows(this); 17 | } 18 | 19 | override function onRemove() { 20 | super.onRemove(); 21 | if( shadows != null ) shadows.dispose(); 22 | } 23 | 24 | override function sync(ctx) { 25 | super.sync(ctx); 26 | if(isMainLight){ 27 | ctx.setGlobal("mainLightColor", _color); 28 | ctx.setGlobal("mainLightPower", power); 29 | ctx.setGlobal("mainLightPos",new h3d.Vector(absPos.tx, absPos.ty, absPos.tz)); 30 | ctx.setGlobal("mainLightDir", absPos.front()); 31 | ctx.setGlobal("mainLightShadowMap", shadows.getShadowTex()); 32 | ctx.setGlobal("mainLightViewProj", shadows.getShadowProj()); 33 | } 34 | } 35 | 36 | override function get_color() { 37 | return _color; 38 | } 39 | 40 | override function set_color(v:h3d.Vector) { 41 | return _color = v; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /h3d/scene/pbr/envDefault.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/scene/pbr/envDefault.dds -------------------------------------------------------------------------------- /h3d/scene/pbr/envDefault.envd.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/scene/pbr/envDefault.envd.dds -------------------------------------------------------------------------------- /h3d/scene/pbr/envDefault.envs.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/scene/pbr/envDefault.envs.dds -------------------------------------------------------------------------------- /h3d/scene/pbr/lighting_performance_gradient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/h3d/scene/pbr/lighting_performance_gradient.png -------------------------------------------------------------------------------- /h3d/shader/AlphaChannel.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class AlphaChannel extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | @const var showAlpha : Bool; 8 | function fragment() { 9 | if( showAlpha ) pixelColor.rgb = pixelColor.aaa; 10 | pixelColor.a = 1.; 11 | } 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /h3d/shader/AlphaMSDF.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class AlphaMSDF extends hxsl.Shader { 4 | static var SRC = { 5 | 6 | var calculatedUV : Vec2; 7 | var pixelColor : Vec4; 8 | @input var input : { uv : Vec2 }; 9 | @const @param var useSourceUVs : Bool = true; 10 | 11 | @param var texture : Sampler2D; 12 | @param var blur : Float = 1; 13 | @const var useColor : Bool = false; 14 | @param var color : Vec3; 15 | 16 | function median(r : Float, g : Float, b : Float) : Float { 17 | return max(min(r, g), min(max(r, g), b)); 18 | } 19 | 20 | function screenPxRange( uv : Vec2 ) : Float { 21 | var unitRange = vec2(blur)/vec2(texture.size()); 22 | var screenTexSize = vec2(1.0)/fwidth(uv); 23 | return max(0.5*dot(unitRange, screenTexSize), 1.0); 24 | } 25 | 26 | function fragment() { 27 | var uv = useSourceUVs ? input.uv : calculatedUV; 28 | var sample = texture.get(uv); 29 | var sd = median(sample.r, sample.g, sample.b); 30 | var screenPxDistance = screenPxRange(uv)*(sd - 0.5); 31 | pixelColor.a = clamp(screenPxDistance + 0.5, 0.0, 1.0); 32 | if (useColor) 33 | pixelColor.rgb = color; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /h3d/shader/AlphaMap.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class AlphaMap extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var calculatedUV : Vec2; 7 | var pixelColor : Vec4; 8 | @input var input : { uv : Vec2 }; 9 | 10 | @param var texture : Sampler2D; 11 | @param var uvScale : Vec2; 12 | @param var uvDelta : Vec2; 13 | @const var useAlphaChannel : Bool; 14 | @const @param var useSourceUVs : Bool = false; 15 | function fragment() { 16 | var uv = useSourceUVs ? input.uv : calculatedUV; 17 | uv = uv * uvScale + uvDelta; 18 | if( useAlphaChannel ) 19 | pixelColor.a *= texture.get(uv).a; 20 | else 21 | pixelColor.a *= texture.get(uv).b; 22 | } 23 | } 24 | 25 | public function new(texture, useAlphaChannel=false) { 26 | super(); 27 | uvScale.set(1, 1); 28 | this.useAlphaChannel = useAlphaChannel; 29 | this.texture = texture; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/shader/AlphaMult.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class AlphaMult extends hxsl.Shader { 4 | static var SRC = { 5 | @perInstance @range(0, 1) @param var alpha : Float; 6 | var pixelColor : Vec4; 7 | 8 | function fragment() { 9 | pixelColor.a *= alpha; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /h3d/shader/AmbientLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class AmbientLight extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @global var global : { 8 | var ambientLight : Vec3; 9 | @const var perPixelLighting : Bool; 10 | }; 11 | 12 | var pixelColor : Vec4; 13 | var lightPixelColor : Vec3; 14 | var lightColor : Vec3; 15 | 16 | @const var additive : Bool; 17 | 18 | function __init__() { 19 | lightColor = additive ? global.ambientLight : vec3(0.); 20 | } 21 | 22 | function __init__fragment() { 23 | lightPixelColor = additive ? global.ambientLight : vec3(0.); 24 | } 25 | 26 | function calcLight( lightColor : Vec3 ) : Vec3 { 27 | return additive ? lightColor : (global.ambientLight + (1 - global.ambientLight).max(0.) * lightColor); 28 | } 29 | 30 | function vertex() { 31 | if( !global.perPixelLighting ) pixelColor.rgb *= calcLight(lightColor); 32 | } 33 | 34 | function fragment() { 35 | if( global.perPixelLighting ) pixelColor.rgb *= calcLight(lightPixelColor); 36 | } 37 | 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /h3d/shader/Bloom.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Bloom extends ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @param var texture : Sampler2D; 8 | @param var power : Float; 9 | @param var amount : Float; 10 | 11 | function fragment() { 12 | var c = texture.get(input.uv); 13 | var lum = c.rgb.dot(vec3(0.2126, 0.7152, 0.0722)); 14 | output.color = vec4(c.rgb * lum.pow(power) * amount * c.a, c.a); 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /h3d/shader/Buffers.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | enum abstract BufferKind(Int) { 4 | public var Globals = 0; 5 | public var Params = 1; 6 | public var Textures = 2; 7 | public var Buffers = 3; 8 | } 9 | 10 | typedef ShaderBufferData = hxd.impl.TypedArray.Float32Array; 11 | 12 | class ShaderBuffers { 13 | 14 | public var globals : ShaderBufferData; 15 | public var params : ShaderBufferData; 16 | public var tex : haxe.ds.Vector; 17 | public var buffers : haxe.ds.Vector; 18 | 19 | public function new() { 20 | globals = new ShaderBufferData(0); 21 | params = new ShaderBufferData(0); 22 | tex = new haxe.ds.Vector(0); 23 | } 24 | 25 | public function grow( s : hxsl.RuntimeShader.RuntimeShaderData ) { 26 | var ng = s.globalsSize << 2; 27 | var np = s.paramsSize << 2; 28 | var nt = s.texturesCount; 29 | var nb = s.bufferCount; 30 | if( globals.length < ng ) globals = new ShaderBufferData(ng); 31 | if( params.length < np ) params = new ShaderBufferData(np); 32 | if( tex.length < nt ) tex = new haxe.ds.Vector(nt); 33 | if( nb > 0 && (buffers == null || buffers.length < nb) ) buffers = new haxe.ds.Vector(nb); 34 | } 35 | 36 | } 37 | 38 | class Buffers { 39 | 40 | public var vertex : ShaderBuffers; 41 | public var fragment : ShaderBuffers; 42 | 43 | public function new() { 44 | vertex = new ShaderBuffers(); 45 | fragment = new ShaderBuffers(); 46 | } 47 | 48 | public inline function grow( s : hxsl.RuntimeShader ) { 49 | vertex.grow(s.vertex); 50 | if( s.fragment != null ) fragment.grow(s.fragment); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /h3d/shader/Checker.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Checker extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | 8 | @param var width : Float; 9 | @param var height : Float; 10 | 11 | var calculatedUV : Vec2; 12 | 13 | @input var input : { var uv : Vec2; } 14 | function vertex() { 15 | calculatedUV = input.uv; 16 | } 17 | 18 | function fragment() { 19 | if ( ((calculatedUV.fract().x - 0.5) * (calculatedUV.fract().y - 0.5)) > 0.0 ) { 20 | pixelColor.rgb = vec3(1.0); 21 | } else { 22 | pixelColor.rgb = vec3(0.0); 23 | } 24 | } 25 | 26 | }; 27 | } -------------------------------------------------------------------------------- /h3d/shader/CheckerboardDepth.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class CheckerboardDepth extends h3d.shader.ScreenShader { 4 | static var SRC = { 5 | 6 | @param var source : Sampler2D; 7 | @param var texRatio : Float; 8 | 9 | final offsets : Array = [ 10 | vec2(0, 0), vec2(0, 1), 11 | vec2(1, 0), vec2(1, 1) 12 | ]; 13 | 14 | function fragment() { 15 | var invDimensions = 1.0 / source.size(); 16 | var pixels = floor(fragCoord.xy); 17 | var upscalePixels = pixels * texRatio + vec2(0.5); 18 | var s00 = source.get( ( upscalePixels + offsets[0] ) * invDimensions ); 19 | var s01 = source.get( ( upscalePixels + offsets[1] ) * invDimensions ); 20 | var s10 = source.get( ( upscalePixels + offsets[2] ) * invDimensions ); 21 | var s11 = source.get( ( upscalePixels + offsets[3] ) * invDimensions ); 22 | #if js 23 | if ( mod(pixels.x, 2) != mod(pixels.y, 2) ) 24 | #else 25 | if ( (int(pixels.x) & 1) != (int(pixels.y) & 1) ) 26 | #end 27 | pixelColor = max(s00, max(s01, max(s10, s11))); 28 | else 29 | pixelColor = min(s00, min(s01, min(s10, s11))); 30 | 31 | } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /h3d/shader/ColorAdd.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ColorAdd extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | 8 | @param var color : Vec3; 9 | 10 | function fragment() { 11 | pixelColor.rgb += color; 12 | } 13 | 14 | }; 15 | 16 | public function new( color : Int = 0 ) { 17 | super(); 18 | this.color.setColor(color); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /h3d/shader/ColorKey.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ColorKey extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param var colorKey : Vec4; 7 | var textureColor : Vec4; 8 | 9 | function fragment() { 10 | var cdiff = textureColor - colorKey; 11 | if( cdiff.dot(cdiff) < 0.00001 ) discard; 12 | } 13 | } 14 | 15 | public function new( v = 0 ) { 16 | super(); 17 | colorKey.setColor(v); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /h3d/shader/ColorMatrix.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ColorMatrix extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | 8 | @param var matrix : Mat4; 9 | @const var enabled : Bool = true; // allows for drop shadow toggle 10 | 11 | function fragment() { 12 | if ( enabled ) 13 | pixelColor = vec4( (vec4(pixelColor.rgb,1.) * matrix).rgb, (pixelColor * matrix).a); 14 | } 15 | 16 | }; 17 | 18 | public function new( ?m : Array ) { 19 | super(); 20 | if( m != null ) this.matrix.loadValues(m) else this.matrix.identity(); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /h3d/shader/ColorMult.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ColorMult extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | 8 | @perInstance @param var color : Vec4; 9 | @param var amount : Float = 1.0; 10 | 11 | function fragment() { 12 | pixelColor.rgba = mix(pixelColor.rgba, pixelColor.rgba * color, amount); 13 | } 14 | 15 | }; 16 | 17 | } -------------------------------------------------------------------------------- /h3d/shader/ColorSpaces.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ColorSpaces extends hxsl.Shader { 4 | static var SRC = { 5 | 6 | //HSV from https://gist.github.com/983/e170a24ae8eba2cd174f 7 | function rgb2hsv(c : Vec3) : Vec3 { 8 | var K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 9 | var p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 10 | var q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 11 | 12 | var d = q.x - min(q.w, q.y); 13 | var e = 1.0e-8; 14 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); 15 | } 16 | 17 | function hsv2rgb(c : Vec3) : Vec3 { 18 | var K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 19 | var p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 20 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 21 | } 22 | 23 | //HSL 24 | function hsl2rgb( c : Vec3 ) : Vec3 { 25 | var rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 ); 26 | 27 | return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0)); 28 | } 29 | 30 | //YCoCg 31 | function rgb2ycocg( rgb : Vec3 ) : Vec3 { 32 | var co = rgb.r - rgb.b; 33 | var t = rgb.b + co * 0.5; 34 | var cg = rgb.g - t; 35 | var y = t + cg * 0.5; 36 | return vec3(y, co, cg); 37 | } 38 | 39 | function ycocg2rgb( ycocg : Vec3 ) : Vec3 { 40 | var t = ycocg.r - ycocg.b * 0.5; 41 | var g = ycocg.b + t; 42 | var b = t - ycocg.g * 0.5; 43 | var r = ycocg.g + b; 44 | return vec3(r, g, b); 45 | } 46 | 47 | function int2rgba( c : Int ) : Vec4 { 48 | return vec4((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF, (c >> 24) & 0xFF) * (1.0 / float(0xFF)); 49 | } 50 | 51 | function rgba2int( c : Vec4 ) : Int { 52 | var cInt = ivec4(saturate(c) * 255 + 0.499); 53 | return cInt.a << 24 | cInt.r << 16 | cInt.g << 8 | cInt.b; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /h3d/shader/CubeMap.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class CubeMap extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var pixelColor : Vec4; 8 | var transformedNormal : Vec3; 9 | 10 | @const var reflection : Bool; 11 | @param var texture : SamplerCube; 12 | @global var camera : { 13 | var position : Vec3; 14 | }; 15 | var pixelTransformedPosition : Vec3; 16 | 17 | function fragment() { 18 | var n = if( reflection ) reflect(-normalize(camera.position - pixelTransformedPosition), transformedNormal) else transformedNormal; 19 | pixelColor.rgb *= texture.get(n).rgb; 20 | } 21 | 22 | } 23 | 24 | public function new(texture, reflection=false) { 25 | super(); 26 | this.texture = texture; 27 | this.reflection = reflection; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /h3d/shader/DirLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class DirLight extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param var color : Vec3; 7 | @param var direction : Vec3; 8 | @const var enableSpecular : Bool; 9 | @global var camera : { 10 | var position : Vec3; 11 | }; 12 | 13 | var lightColor : Vec3; 14 | var lightPixelColor : Vec3; 15 | var transformedNormal : Vec3; 16 | var transformedPosition : Vec3; 17 | var specPower : Float; 18 | var specColor : Vec3; 19 | 20 | function calcLighting() : Vec3 { 21 | var diff = transformedNormal.dot(-direction).max(0.); 22 | if( !enableSpecular ) 23 | return color * diff; 24 | var r = reflect(direction, transformedNormal).normalize(); 25 | var specValue = r.dot((camera.position - transformedPosition).normalize()).max(0.); 26 | return color * (diff + specColor * pow(specValue, specPower)); 27 | } 28 | 29 | function vertex() { 30 | lightColor.rgb += calcLighting(); 31 | } 32 | 33 | function fragment() { 34 | lightPixelColor.rgb += calcLighting(); 35 | } 36 | 37 | } 38 | 39 | public function new() { 40 | super(); 41 | color.set(1, 1, 1); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /h3d/shader/Displacement.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Displacement extends ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @param var texture : Sampler2D; 8 | @param var normalMap : Sampler2D; 9 | @param var normalScale : Vec2; 10 | @param var normalPos : Vec2; 11 | @param var displacement : Vec2; 12 | 13 | function fragment() { 14 | var n = unpackNormal(normalMap.get(input.uv * normalScale + normalPos)); 15 | output.color = texture.get(input.uv + n.xy * displacement); 16 | } 17 | 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /h3d/shader/DisplacementDisplay.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class DisplacementDisplay extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var pixelColor : Vec4; 7 | 8 | @param var tex : Sampler2D; 9 | 10 | var calculatedUV : Vec2; 11 | 12 | function fragment() { 13 | pixelColor.rgb = tex.get(calculatedUV).aaa; 14 | } 15 | 16 | }; 17 | } -------------------------------------------------------------------------------- /h3d/shader/DistanceFade.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class DistanceFade extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param @const var nearFadeEnabled : Bool; 7 | @param var nearMinFade : Float; 8 | @param var nearMaxFade : Float; 9 | 10 | @param @const var farFadeEnabled : Bool; 11 | @param var farMinFade : Float; 12 | @param var farMaxFade : Float; 13 | 14 | @:import h3d.shader.BaseMesh; 15 | 16 | function fragment() { 17 | var distFromCam = length(transformedPosition - camera.position); 18 | 19 | var alphaNear = 1.0; 20 | var alphaFar = 1.0; 21 | 22 | if (farFadeEnabled) 23 | alphaFar = 1.0 - saturate((distFromCam - farMinFade) / (farMaxFade - farMinFade)); 24 | 25 | if (nearFadeEnabled) 26 | alphaNear = saturate((distFromCam - nearMinFade) / (nearMaxFade - nearMinFade)); 27 | 28 | pixelColor.a *= min(alphaFar, alphaNear); 29 | } 30 | }; 31 | } -------------------------------------------------------------------------------- /h3d/shader/FixedColor.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class FixedColor extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param var color : Vec4; 7 | @const @param var USE_ALPHA : Bool; 8 | var output : { color : Vec4 }; 9 | function fragment() { 10 | if( USE_ALPHA ) 11 | output.color = color; 12 | else 13 | output.color.rgb = color.rgb; 14 | } 15 | } 16 | 17 | public function new( color = 0, alpha = 1. ) { 18 | super(); 19 | this.color.setColor(color); 20 | this.color.w = alpha; 21 | USE_ALPHA = true; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /h3d/shader/FlipBackFaceNormal.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class FlipBackFaceNormal extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var transformedNormal : Vec3; 8 | 9 | function __init__fragment() { 10 | if ( !frontFacing ) 11 | transformedNormal *= -1.0; 12 | } 13 | }; 14 | } -------------------------------------------------------------------------------- /h3d/shader/GenTexture.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class GenTexture extends ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @const var mode : Int; 8 | @param var color : Vec4; 9 | 10 | function fragment() { 11 | switch( mode ) { 12 | case 0: 13 | pixelColor = output.position.xy.length() > 1 ? vec4(0.) : color; 14 | } 15 | } 16 | 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /h3d/shader/KillAlpha.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class KillAlpha extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @param var threshold : Float; 8 | var pixelColor : Vec4; 9 | 10 | function fragment() { 11 | // Put the result of the check in a var. This way the DCE can correctly say that only the alpha channel of pixelColor is needed. 12 | var doDiscard = pixelColor.a < threshold; 13 | if( doDiscard ) discard; 14 | } 15 | } 16 | 17 | public function new(threshold = 0.) { 18 | super(); 19 | this.threshold = threshold; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /h3d/shader/LineShader.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class LineShader extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @global var camera : { 8 | var view : Mat4; 9 | var proj : Mat4; 10 | var viewProj : Mat4; 11 | }; 12 | 13 | @global var global : { 14 | var pixelSize : Vec2; 15 | @perObject var modelView : Mat4; 16 | }; 17 | 18 | @input var input : { 19 | var position : Vec3; 20 | var normal : Vec3; 21 | var uv : Vec2; 22 | } 23 | 24 | var output : { 25 | var position : Vec4; 26 | }; 27 | 28 | var transformedNormal : Vec3; 29 | var transformedPosition : Vec3; 30 | var projectedPosition : Vec4; 31 | 32 | @param var lengthScale : Float; 33 | @param var width : Float; 34 | 35 | var pdir : Vec4; 36 | 37 | function __init__() { 38 | { 39 | var dir = input.normal * global.modelView.mat3(); // keep scale 40 | pdir = vec4(dir * mat3(camera.view), 1) * camera.proj; 41 | pdir.xy *= 1 / sqrt(pdir.x * pdir.x + pdir.y * pdir.y); 42 | transformedPosition += dir * input.uv.x * lengthScale; 43 | transformedNormal = dir.normalize(); 44 | } 45 | } 46 | 47 | function vertex() { 48 | projectedPosition.xy += (pdir.yx * vec2(1,-1)) * (input.uv.y - 0.5) * projectedPosition.z * global.pixelSize * width; 49 | } 50 | 51 | }; 52 | 53 | public function new( width = 1.5, lengthScale = 1. ) { 54 | super(); 55 | this.width = width; 56 | this.lengthScale = lengthScale; 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /h3d/shader/MinMaxShader.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class MinMaxShader extends ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @param var texA : Sampler2D; 8 | @param var texB : Sampler2D; 9 | @const var isMax : Bool; 10 | 11 | function fragment() { 12 | var a = texA.get(calculatedUV); 13 | var b = texB.get(calculatedUV); 14 | pixelColor = isMax ? max(a,b) : min(a,b); 15 | } 16 | }; 17 | } 18 | 19 | class CubeMinMaxShader extends ScreenShader { 20 | 21 | static var SRC = { 22 | 23 | @param var texA : SamplerCube; 24 | @param var texB : SamplerCube; 25 | @const var isMax : Bool; 26 | @param var mat : Mat3; 27 | 28 | function fragment() { 29 | var uv = calculatedUV * 2.0 - 1.0; 30 | var dir = vec3(uv , 1) * mat; 31 | var a = texA.get(dir); 32 | var b = texB.get(dir); 33 | pixelColor = isMax ? max(a,b) : min(a,b); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /h3d/shader/NormalMap.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class NormalMap extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @global var camera : { 8 | var position : Vec3; 9 | @var var dir : Vec3; 10 | }; 11 | 12 | @global var global : { 13 | @perObject var modelView : Mat4; 14 | }; 15 | 16 | @input var input : { 17 | var normal : Vec3; 18 | var tangent : Vec3; 19 | }; 20 | 21 | @param var texture : Sampler2D; 22 | 23 | var calculatedUV : Vec2; 24 | var transformedPosition : Vec3; 25 | var transformedNormal : Vec3; 26 | 27 | @var var transformedTangent : Vec4; 28 | 29 | function __init__vertex() { 30 | transformedTangent = vec4(input.tangent * global.modelView.mat3(),input.tangent.dot(input.tangent) > 0.5 ? 1. : -1.); 31 | } 32 | 33 | function fragment() { 34 | var n = transformedNormal; 35 | var nf = unpackNormal(texture.get(calculatedUV)); 36 | var tanX = transformedTangent.xyz.normalize(); 37 | var tanY = n.cross(tanX) * -transformedTangent.w; 38 | transformedNormal = (nf.x * tanX + nf.y * tanY + nf.z * n).normalize(); 39 | } 40 | 41 | }; 42 | 43 | public function new(?texture) { 44 | super(); 45 | this.texture = texture; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /h3d/shader/Outline.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Outline extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @:import BaseMesh; 8 | 9 | @param var size : Float; 10 | @param var distance : Float; 11 | @param var color : Vec4; 12 | 13 | function __init__vertex() { 14 | transformedPosition += transformedNormal * size; 15 | } 16 | 17 | function vertex() { 18 | projectedPosition.z -= distance * projectedPosition.w; 19 | } 20 | 21 | function fragment() { 22 | output.color = color; 23 | } 24 | 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /h3d/shader/Outline2D.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Outline2D extends ScreenShader { 4 | static var SRC = { 5 | @param var texture : Sampler2D; 6 | @param var size : Vec2; 7 | @param @const var samples : Int; 8 | @param var color : Vec4; 9 | @param @const var multiplyAlpha : Int; 10 | function fragment() { 11 | var ownColor : Vec4 = texture.get(input.uv); 12 | var maxAlpha = 0.; 13 | var curColor : Vec4; 14 | var displaced : Vec2; 15 | var angle = 0.; 16 | var doublePi = 6.28318530717958647692528; 17 | var step = doublePi / samples; 18 | @unroll for (i in 0...samples) { 19 | angle += step; 20 | displaced.x = input.uv.x + size.x * cos(angle); 21 | displaced.y = input.uv.y + size.y * sin(angle); 22 | curColor = texture.get(displaced); 23 | maxAlpha = max(maxAlpha, curColor.a); 24 | } 25 | var resultAlpha = max(maxAlpha, ownColor.a); 26 | var resultColor = ownColor.rgb + color.rgb * (1. - ownColor.a); 27 | var out = resultColor * max(float(multiplyAlpha), resultAlpha); 28 | output.color = vec4(out, resultAlpha * mix(color.a, 1, ownColor.a)); 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /h3d/shader/ParticleShader.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ParticleShader extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @global var camera : { 8 | var viewProj : Mat4; 9 | var position : Vec3; 10 | }; 11 | 12 | @global var global : { 13 | @perObject var modelView : Mat4; 14 | }; 15 | 16 | @input var input : { 17 | var position : Vec3; 18 | var rpos : Vec2; 19 | var rot : Float; 20 | var size : Vec2; 21 | var uv : Vec2; 22 | }; 23 | 24 | var transformedPosition : Vec3; 25 | var transformedNormal : Vec3; 26 | var projectedPosition : Vec4; 27 | @param var rotationAxis : Mat3; 28 | 29 | // we store the corner coordinates and rotation in the input.normal 30 | 31 | @param var size : Vec2; 32 | @const var is3D : Bool; 33 | @const var isAbsolute : Bool; 34 | 35 | function __init__() { 36 | if( isAbsolute ) transformedPosition = input.position; 37 | } 38 | 39 | function vertex() { 40 | var rpos = input.rpos; 41 | var rot = input.rot; 42 | var cr = rot.cos(); 43 | var sr = rot.sin(); 44 | var pos = input.size * rpos; 45 | if( is3D ) pos *= size; 46 | var rtmp = pos.x * cr + pos.y * sr; 47 | pos.y = pos.y * cr - pos.x * sr; 48 | pos.x = rtmp; 49 | if( is3D ) { 50 | transformedPosition += vec3(pos,0) * rotationAxis; 51 | } else { 52 | projectedPosition = vec4(transformedPosition,1) * camera.viewProj; 53 | projectedPosition.xy += pos * size; 54 | } 55 | transformedNormal = (transformedPosition - camera.position).normalize(); 56 | } 57 | 58 | } 59 | 60 | public function new() { 61 | super(); 62 | rotationAxis.initRotationAxis(new h3d.Vector(1, 0, 0), Math.PI / 2); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /h3d/shader/PointLight.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class PointLight extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @const var enableSpecular : Bool; 8 | @param var color : Vec3; 9 | @param var params : Vec3; // [constant, linear, quadratic] 10 | @param var lightPosition : Vec3; 11 | @global var camera : { 12 | var position : Vec3; 13 | }; 14 | 15 | /** 16 | Don't use model normal to calculate light amount 17 | **/ 18 | @const var isAmbient : Bool; 19 | 20 | var lightColor : Vec3; 21 | var lightPixelColor : Vec3; 22 | var transformedPosition : Vec3; 23 | var pixelTransformedPosition : Vec3; 24 | var transformedNormal : Vec3; 25 | var specPower : Float; 26 | var specColor : Vec3; 27 | 28 | 29 | function calcLighting( position : Vec3 ) : Vec3 { 30 | var dvec = lightPosition - position; 31 | var dist2 = dvec.dot(dvec); 32 | var dist = dist2.sqrt(); 33 | var diff : Float = isAmbient ? 1. : transformedNormal.dot(dvec).max(0.); 34 | var factor = 1 / vec3(dist, dist2, dist * dist2).dot(params); 35 | if( !enableSpecular ) 36 | return color * diff * factor; 37 | var r = reflect(-dvec.normalize(), transformedNormal).normalize(); 38 | var specValue = r.dot((camera.position - position).normalize()).max(0.); 39 | return color * (diff * factor + specColor * pow(specValue, specPower)); 40 | } 41 | 42 | function vertex() { 43 | lightColor.rgb += calcLighting(transformedPosition); 44 | } 45 | 46 | function fragment() { 47 | lightPixelColor.rgb += calcLighting(pixelTransformedPosition); 48 | } 49 | 50 | }; 51 | 52 | public function new() { 53 | super(); 54 | color.set(1, 1, 1); 55 | params.set(0, 0, 1); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /h3d/shader/ScreenShader.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ScreenShader extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @input var input : { 7 | position : Vec2, 8 | uv : Vec2, 9 | }; 10 | 11 | @param var flipY : Float; 12 | 13 | var output : { 14 | position : Vec4, 15 | color : Vec4, 16 | }; 17 | 18 | var pixelColor : Vec4; 19 | var calculatedUV : Vec2; 20 | 21 | function __init__() { 22 | output.color = pixelColor; 23 | calculatedUV = input.uv; 24 | } 25 | 26 | function vertex() { 27 | output.position = vec4(input.position.x, input.position.y * flipY, 0, 1); 28 | } 29 | }; 30 | 31 | } -------------------------------------------------------------------------------- /h3d/shader/Shadow.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Shadow extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @global var shadow : { 7 | map : Channel, 8 | proj : Mat3x4, 9 | color : Vec3, 10 | power : Float, 11 | bias : Float, 12 | }; 13 | var pixelColor : Vec4; 14 | var transformedPosition : Vec3; 15 | var pixelTransformedPosition : Vec3; 16 | @private var shadowPos : Vec3; 17 | 18 | function fragment() { 19 | var shadowPos = pixelTransformedPosition * shadow.proj; 20 | var depth = shadow.map.get(screenToUv(shadowPos.xy)); 21 | var zMax = shadowPos.z.saturate(); 22 | var delta = (depth + shadow.bias).min(zMax) - zMax; 23 | var shade = exp( shadow.power * delta ).saturate(); 24 | pixelColor.rgb *= (1 - shade) * shadow.color.rgb + shade; 25 | } 26 | }; 27 | 28 | public function new() { 29 | super(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /h3d/shader/SignedDistanceField.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class SignedDistanceField extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @:import h3d.shader.Base2d; 8 | 9 | // Mode of operation - single-channel or multi-channel. 10 | // 0123 = RGBA, evertyhing else is MSDF. 11 | @const var channel : Int = 0; 12 | /** 13 | Use automatic edge smoothing based on derivatives. 14 | **/ 15 | @const var autoSmoothing : Bool = false; 16 | /** 17 | Variable used to determine the edge of the field. ( default : 0.5 ) 18 | Can be used to provide cheaper Outline for Text compared to Filter usage. 19 | **/ 20 | @param var alphaCutoff : Float = 0.5; 21 | /** 22 | Determines smoothing of the edge. Lower value is sharper. 23 | **/ 24 | @param var smoothing : Float = 0.04166666666666666666666666666667; // 1/24 25 | 26 | function median(r : Float, g : Float, b : Float) : Float { 27 | return max(min(r, g), min(max(r, g), b)); 28 | } 29 | 30 | function fragment() { 31 | var textureSample : Vec4 = textureColor; 32 | var distance : Float; 33 | 34 | distance = if (channel == 0) textureSample.r; 35 | else if (channel == 1) textureSample.g; 36 | else if (channel == 2) textureSample.b; 37 | else if (channel == 3) textureSample.a; 38 | else median(textureSample.r, textureSample.g, textureSample.b); 39 | 40 | var smoothVal = autoSmoothing ? abs(fwidth(distance) * 0.5) : smoothing; 41 | textureColor = vec4(1.0, 1.0, 1.0, smoothstep(alphaCutoff - smoothVal, alphaCutoff + smoothVal, distance)); 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /h3d/shader/SinusDeform.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class SinusDeform extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @global var time : Float; 8 | @param var speed : Float; 9 | @param var frequency : Float; 10 | @param var amplitude : Float; 11 | 12 | var calculatedUV : Vec2; 13 | 14 | function fragment() { 15 | calculatedUV.x += sin(calculatedUV.y * frequency + time * speed) * amplitude; 16 | } 17 | 18 | }; 19 | 20 | public function new( frequency = 10., amplitude = 0.01, speed = 1. ) { 21 | super(); 22 | this.frequency = frequency; 23 | this.amplitude = amplitude; 24 | this.speed = speed; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /h3d/shader/SkinBase.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class SkinBase extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var relativePosition : Vec3; 8 | var transformedPosition : Vec3; 9 | var transformedNormal : Vec3; 10 | 11 | @const var MaxBones : Int; 12 | @const @param var fourBonesByVertex = false; 13 | @const var calcPrevPos : Bool = false; 14 | 15 | @ignore @param var bonesMatrixes : Array; 16 | @ignore @param var prevBonesMatrixes : Array; 17 | }; 18 | 19 | public function new() { 20 | super(); 21 | MaxBones = 34; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /h3d/shader/SkinTangent.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class SkinTangent extends SkinBase { 4 | 5 | static var SRC = { 6 | 7 | @:import h3d.shader.Skin.Utils; 8 | 9 | @input var input : { 10 | var position : Vec3; 11 | var normal : Vec3; 12 | var tangent : Vec3; 13 | var weights : Vec3; 14 | var indexes : Bytes4; 15 | }; 16 | 17 | var transformedTangent : Vec4; 18 | var previousTransformedPosition : Vec3; 19 | 20 | function vertex() { 21 | if ( calcPrevPos ) { 22 | boneMatrixX = prevBonesMatrixes[int(input.indexes.x)]; 23 | boneMatrixY = prevBonesMatrixes[int(input.indexes.y)]; 24 | boneMatrixZ = prevBonesMatrixes[int(input.indexes.z)]; 25 | boneMatrixW = prevBonesMatrixes[int(input.indexes.w)]; 26 | skinWeights = vec4(input.weights, 0.0); 27 | if ( fourBonesByVertex ) 28 | skinWeights.w = 1 - (input.weights.x + input.weights.y + input.weights.z); 29 | 30 | previousTransformedPosition = applySkinPoint(relativePosition); 31 | } 32 | 33 | boneMatrixX = bonesMatrixes[int(input.indexes.x)]; 34 | boneMatrixY = bonesMatrixes[int(input.indexes.y)]; 35 | boneMatrixZ = bonesMatrixes[int(input.indexes.z)]; 36 | boneMatrixW = bonesMatrixes[int(input.indexes.w)]; 37 | skinWeights = vec4(input.weights, 0.0); 38 | if ( fourBonesByVertex ) 39 | skinWeights.w = 1 - (input.weights.x + input.weights.y + input.weights.z); 40 | 41 | transformedPosition = applySkinPoint(relativePosition); 42 | transformedNormal = applySkinVec(input.normal); 43 | transformedTangent.xyz = applySkinVec(input.tangent.xyz); 44 | 45 | transformedNormal = normalize(transformedNormal); 46 | transformedTangent.xyz = normalize(transformedTangent.xyz); 47 | 48 | if ( !calcPrevPos ) 49 | previousTransformedPosition = transformedPosition; 50 | } 51 | 52 | }; 53 | 54 | } -------------------------------------------------------------------------------- /h3d/shader/SpecularTexture.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class SpecularTexture extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param var texture : Sampler2D; 7 | var calculatedUV : Vec2; 8 | var specColor : Vec3; 9 | 10 | function fragment() { 11 | specColor *= texture.get(calculatedUV).rgb; 12 | } 13 | } 14 | 15 | public function new(?tex) { 16 | super(); 17 | this.texture = tex; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /h3d/shader/Texture.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class Texture extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @input var input : { 7 | var uv : Vec2; 8 | }; 9 | 10 | @const var additive : Bool; 11 | @const var killAlpha : Bool; 12 | @const var specularAlpha : Bool; 13 | @range(0,1) @param var killAlphaThreshold : Float; 14 | 15 | @param var texture : Sampler2D; 16 | var calculatedUV : Vec2; 17 | var pixelColor : Vec4; 18 | var specColor : Vec3; 19 | 20 | function vertex() { 21 | calculatedUV = input.uv; 22 | } 23 | 24 | function fragment() { 25 | var c = texture.get(calculatedUV); 26 | if( killAlpha && c.a - killAlphaThreshold < 0 ) discard; 27 | if( additive ) 28 | pixelColor += c; 29 | else 30 | pixelColor *= c; 31 | if( specularAlpha ) 32 | specColor *= c.aaa; 33 | } 34 | } 35 | 36 | 37 | public function new(?tex) { 38 | super(); 39 | this.texture = tex; 40 | killAlphaThreshold = h3d.mat.Defaults.defaultKillAlphaThreshold; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /h3d/shader/Texture2.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | /** 4 | This is similar to [Texture] shader but uses a second UV set. 5 | **/ 6 | class Texture2 extends hxsl.Shader { 7 | 8 | static var SRC = { 9 | @input var input : { 10 | var uv2 : Vec2; 11 | }; 12 | 13 | @const var additive : Bool; 14 | @const var killAlpha : Bool; 15 | @param var killAlphaThreshold : Float; 16 | 17 | @param var texture : Sampler2D; 18 | var calculatedUV2 : Vec2; 19 | var pixelColor : Vec4; 20 | 21 | function vertex() { 22 | calculatedUV2 = input.uv2; 23 | } 24 | 25 | function fragment() { 26 | var c = texture.get(calculatedUV2); 27 | if( killAlpha && c.a - killAlphaThreshold < 0 ) discard; 28 | if( additive ) 29 | pixelColor += c; 30 | else 31 | pixelColor *= c; 32 | } 33 | } 34 | 35 | 36 | public function new(?tex) { 37 | super(); 38 | this.texture = tex; 39 | this.killAlphaThreshold = h3d.mat.Defaults.defaultKillAlphaThreshold; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /h3d/shader/UVAnim.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class UVAnim extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var calculatedUV : Vec2; 8 | 9 | @global var global : { 10 | var time : Float; 11 | }; 12 | @param var speed : Float; 13 | @param var frameDivision : Float; 14 | @param var totalFrames : Float; 15 | @param var startTime : Float; 16 | @const var loop : Bool; 17 | 18 | function vertex() { 19 | var frame = float(int((global.time - startTime) * speed)); 20 | if( loop ) frame %= totalFrames else frame = min(frame, totalFrames - 1); 21 | var delta = vec2(1. / frameDivision, 1. / frameDivision) * vec2( frame % frameDivision, float(int(frame / frameDivision)) ); 22 | calculatedUV += delta; 23 | } 24 | }; 25 | 26 | public function new(frameDivision : Int, totalFrames = -1, ?speed = 1.) { 27 | super(); 28 | if( totalFrames < 0 ) totalFrames = frameDivision; 29 | this.frameDivision = frameDivision; 30 | this.totalFrames = totalFrames; 31 | this.speed = speed; 32 | this.loop = true; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /h3d/shader/UVDelta.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class UVDelta extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @param var uvDelta : Vec2; 7 | @param var uvScale : Vec2; 8 | var calculatedUV : Vec2; 9 | function vertex() { 10 | calculatedUV = calculatedUV * uvScale + uvDelta; 11 | } 12 | }; 13 | 14 | public function new( dx = 0., dy = 0., sx = 1., sy = 1. ) { 15 | super(); 16 | uvDelta.set(dx, dy); 17 | uvScale.set(sx, sy); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /h3d/shader/UVScroll.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class UVScroll extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @global var global : { 7 | var time : Float; 8 | }; 9 | @param var uvSpeed : Vec2; 10 | var calculatedUV : Vec2; 11 | function vertex() { 12 | calculatedUV += uvSpeed * global.time; 13 | } 14 | }; 15 | 16 | public function new( vx = 0., vy = 0. ) { 17 | super(); 18 | uvSpeed.set(vx, vy); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /h3d/shader/VertexColor.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class VertexColor extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @input var input : { 7 | var color : Vec3; 8 | }; 9 | 10 | var pixelColor : Vec4; 11 | @const var additive : Bool; 12 | 13 | function fragment() { 14 | if( additive ) 15 | pixelColor.rgb += input.color; 16 | else 17 | pixelColor.rgb *= input.color; 18 | } 19 | 20 | }; 21 | 22 | } -------------------------------------------------------------------------------- /h3d/shader/VertexColorAlpha.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class VertexColorAlpha extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @input var input : { 7 | var color : Vec4; 8 | }; 9 | 10 | var pixelColor : Vec4; 11 | @const var additive : Bool; 12 | 13 | function fragment() { 14 | if( additive ) 15 | pixelColor += input.color; 16 | else 17 | pixelColor *= input.color; 18 | } 19 | 20 | }; 21 | 22 | } -------------------------------------------------------------------------------- /h3d/shader/VolumeDecal.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class VolumeDecal extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | @:import BaseMesh; 8 | 9 | @global var depthMap : Channel; 10 | 11 | @param var scale : Vec2; 12 | @param var normal : Vec3; 13 | @param var tangent : Vec3; 14 | @const var isCentered : Bool = true; 15 | var calculatedUV : Vec2; 16 | var transformedTangent : Vec4; 17 | 18 | function __init__vertex() { 19 | transformedNormal = (normal * global.modelView.mat3()).normalize(); 20 | transformedTangent = vec4((tangent * global.modelView.mat3()).normalize(),1.); 21 | } 22 | 23 | function fragment() { 24 | var matrix = camera.inverseViewProj * global.modelViewInverse; 25 | var screenPos = projectedPosition.xy / projectedPosition.w; 26 | var ruv = vec4( 27 | screenPos, 28 | depthMap.get(screenToUv(screenPos)), 29 | 1 30 | ); 31 | var wpos = ruv * matrix; 32 | var ppos = ruv * camera.inverseViewProj; 33 | pixelTransformedPosition = ppos.xyz / ppos.w; 34 | calculatedUV = scale * (wpos.xy / wpos.w); 35 | if( isCentered ) calculatedUV += 0.5; 36 | if( min(min(calculatedUV.x, calculatedUV.y), min(1 - calculatedUV.x, 1 - calculatedUV.y)) < 0 ) 37 | discard; 38 | } 39 | 40 | }; 41 | 42 | public function new( objectWidth : Float, objectHeight : Float ) { 43 | super(); 44 | normal.set(0, 0, 1); 45 | tangent.set(1, 0, 0); 46 | scale.set(1/objectWidth, 1/objectHeight); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /h3d/shader/WhiteAlpha.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class WhiteAlpha extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var textureColor : Vec4; 8 | 9 | function fragment() { 10 | textureColor.rgb = vec3(1.0); 11 | } 12 | 13 | }; 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /h3d/shader/ZCut.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader; 2 | 3 | class ZCut extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @:import h3d.shader.BaseMesh; 7 | 8 | @param var zMin : Float; 9 | @param var zMax : Float; 10 | 11 | function vertex() { 12 | var z = projectedPosition.z / projectedPosition.w; 13 | z -= min(z - zMin, 0.) * 1e8; 14 | z += min(zMax - z, 0.) * 1e8; 15 | projectedPosition.z = z * projectedPosition.w; 16 | pixelColor.rgb = z.xxx; 17 | } 18 | 19 | }; 20 | 21 | public function new(zMin = 0., zMax = 1.) { 22 | super(); 23 | this.zMin = zMin; 24 | this.zMax = zMax; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /h3d/shader/pbr/AlphaMultiply.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class AlphaMultiply extends hxsl.Shader { 4 | static var SRC = { 5 | var pixelColor : Vec4; 6 | function fragment() { 7 | pixelColor.rgb *= pixelColor.a; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /h3d/shader/pbr/CubeLod.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class CubeLod extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var pixelColor : Vec4; 8 | var transformedNormal : Vec3; 9 | @param var texture : SamplerCube; 10 | @param var lod : Float; 11 | function fragment() { 12 | pixelColor.rgb *= textureLod(texture,transformedNormal,lod).rgb; 13 | } 14 | 15 | } 16 | 17 | public function new(?texture) { 18 | super(); 19 | this.texture = texture; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /h3d/shader/pbr/Distortion.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class Distortion extends h3d.shader.ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @param var distortion : Sampler2D; 8 | 9 | function fragment() { 10 | var baseUV = calculatedUV; 11 | var distortionVal = distortion.get(calculatedUV).rg; 12 | calculatedUV = baseUV + distortionVal; 13 | } 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /h3d/shader/pbr/GammaCorrect.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class GammaCorrect extends hxsl.Shader { 4 | static var SRC = { 5 | var pixelColor : Vec4; 6 | 7 | @const var useEmissiveHDR : Bool; 8 | var emissive : Float; 9 | 10 | function fragment() { 11 | pixelColor.rgb *= pixelColor.rgb; 12 | // use emissive value to increase light intensity 13 | if( useEmissiveHDR ) pixelColor.rgb *= 1 + emissive; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /h3d/shader/pbr/PerformanceViewer.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class PerformanceViewer extends ScreenShader { 4 | 5 | static var SRC = { 6 | 7 | @param var hdrMap : Sampler2D; 8 | @param var gradient : Sampler2D; 9 | 10 | function fragment() { 11 | pixelColor = gradient.get(vec2(hdrMap.get(calculatedUV).saturate().r, 0.0)); 12 | } 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /h3d/shader/pbr/PropsDefinition.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class PropsDefinition extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | var albedo : Vec3; 7 | var depth : Float; 8 | var normal : Vec3; 9 | var metalness : Float; 10 | var roughness : Float; 11 | var occlusion : Float; 12 | var emissive : Float; 13 | var custom1 : Float; 14 | var custom2 : Float; 15 | var pbrSpecularColor : Vec3; 16 | var transformedPosition : Vec3; 17 | 18 | var view : Vec3; 19 | var NdV : Float; 20 | 21 | @param var cameraPosition : Vec3; 22 | var pixelColor : Vec4; 23 | var shadow : Float; 24 | 25 | function __init__fragment() { 26 | shadow = 1.; 27 | pixelColor = vec4(0.,0.,0.,1.); 28 | { 29 | view = (cameraPosition - transformedPosition).normalize(); 30 | NdV = normal.dot(view).max(0.); 31 | } 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /h3d/shader/pbr/PropsTexture.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class PropsTexture extends hxsl.Shader { 4 | static var SRC = { 5 | 6 | @param var texture : Sampler2D; 7 | @param var emissiveValue : Float; 8 | @param var custom1Value : Float; 9 | @param var custom2Value : Float; 10 | 11 | var output : { 12 | metalness : Float, 13 | roughness : Float, 14 | occlusion : Float, 15 | emissive : Float, 16 | custom1 : Float, 17 | custom2 : Float, 18 | }; 19 | 20 | var metalness : Float; 21 | var roughness : Float; 22 | var occlusion : Float; 23 | var emissive : Float; 24 | var custom1 : Float; 25 | var custom2 : Float; 26 | 27 | var calculatedUV : Vec2; 28 | 29 | function __init__fragment() { 30 | { 31 | var v = texture.get(calculatedUV); 32 | metalness = v.r; 33 | roughness = 1 - v.g * v.g; 34 | occlusion = v.b; 35 | emissive = emissiveValue * v.a; 36 | } 37 | custom1 = custom1Value; 38 | custom2 = custom2Value; 39 | } 40 | 41 | function fragment() { 42 | output.metalness = metalness; 43 | output.roughness = roughness; 44 | output.occlusion = occlusion; 45 | output.emissive = emissive; 46 | output.custom1 = custom1; 47 | output.custom2 = custom2; 48 | } 49 | 50 | } 51 | 52 | public function new(?t) { 53 | super(); 54 | this.texture = t; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /h3d/shader/pbr/PropsValues.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class PropsValues extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var output : { 8 | metalness : Float, 9 | roughness : Float, 10 | occlusion : Float, 11 | emissive : Float, 12 | custom1 : Float, 13 | custom2 : Float, 14 | }; 15 | 16 | @param var metalnessValue : Float; 17 | @param var roughnessValue : Float; 18 | @param var occlusionValue : Float; 19 | @param var emissiveValue : Float; 20 | @param var custom1Value : Float; 21 | @param var custom2Value : Float; 22 | 23 | var metalness : Float; 24 | var roughness : Float; 25 | var occlusion : Float; 26 | var emissive : Float; 27 | var custom1 : Float; 28 | var custom2 : Float; 29 | 30 | function __init__() { 31 | metalness = metalnessValue; 32 | roughness = roughnessValue; 33 | occlusion = occlusionValue; 34 | emissive = emissiveValue; 35 | custom1 = custom1Value; 36 | custom2 = custom2Value; 37 | } 38 | 39 | function fragment() { 40 | output.metalness = metalness; 41 | output.roughness = roughness; 42 | output.occlusion = occlusion; 43 | output.emissive = emissive; 44 | output.custom1 = custom1; 45 | output.custom2 = custom2; 46 | } 47 | 48 | }; 49 | 50 | public function new(metalness=0.,roughness=1.,occlusion=1.,emissive=0.,custom1=0.,custom2=0.) { 51 | super(); 52 | this.metalnessValue = metalness; 53 | this.roughnessValue = roughness; 54 | this.occlusionValue = occlusion; 55 | this.emissiveValue = emissive; 56 | this.custom1Value = custom1; 57 | this.custom2Value = custom2; 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /h3d/shader/pbr/StrengthValues.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | class StrengthValues extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | 7 | var output : { 8 | albedoStrength : Float, 9 | normalStrength : Float, 10 | pbrStrength : Float, 11 | emissiveStrength : Float 12 | }; 13 | 14 | var pixelColor : Vec4; 15 | @param var albedoStrength : Float; 16 | @param var normalStrength : Float; 17 | @param var pbrStrength : Float; 18 | @param var emissiveStrength : Float; 19 | 20 | function fragment() { 21 | output.albedoStrength = albedoStrength * pixelColor.a; 22 | output.normalStrength = normalStrength * pixelColor.a; 23 | output.pbrStrength = pbrStrength * pixelColor.a; 24 | output.emissiveStrength = emissiveStrength * pixelColor.a; 25 | } 26 | 27 | }; 28 | 29 | public function new(albedoStrength=1.,normalStrength=1.,pbrStrength=1., emissiveStrength=1.) { 30 | super(); 31 | this.albedoStrength = albedoStrength; 32 | this.normalStrength = normalStrength; 33 | this.pbrStrength = pbrStrength; 34 | this.emissiveStrength = emissiveStrength; 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /h3d/shader/pbr/ToneMapping.hx: -------------------------------------------------------------------------------- 1 | package h3d.shader.pbr; 2 | 3 | 4 | class ToneMapping extends ScreenShader { 5 | 6 | static var SRC = { 7 | 8 | @param var hdrTexture : Sampler2D; 9 | @param var exposureExp : Float; 10 | @const var isSRBG : Bool; 11 | @const var mode : Int; 12 | @param var invGamma : Float; 13 | @param var a : Float; 14 | @param var b : Float; 15 | @param var c : Float; 16 | @param var d : Float; 17 | @param var e : Float; 18 | 19 | var hdrColor : Vec4; 20 | 21 | function __init__fragment() { 22 | hdrColor = hdrTexture.get(calculatedUV); 23 | } 24 | 25 | function fragment() { 26 | var color = hdrColor; 27 | color.rgb *= exposureExp; 28 | switch( mode ) { 29 | case 0: 30 | // linear 31 | color.rgb = color.rgb.saturate(); 32 | case 1: 33 | // reinhard 34 | color.rgb = color.rgb / (color.rgb + vec3(1.)); 35 | case 2: 36 | // filmic 37 | color.rgb = saturate((color.rgb*(a*color.rgb+b))/(color.rgb*(c*color.rgb+d)+e)); 38 | } 39 | // gamma correct 40 | if( !isSRBG ) 41 | color.rgb = pow(color.rgb, vec3(invGamma)); 42 | pixelColor = color; 43 | } 44 | } 45 | 46 | public var exposure(default,set) : Float; 47 | public var gamma(default,set) : Float; 48 | 49 | public function new() { 50 | super(); 51 | exposure = 0; 52 | gamma = 2.0; 53 | a = 2.51; 54 | b = 0.03; 55 | c = 2.43; 56 | d = 0.59; 57 | e = 0.14; 58 | } 59 | 60 | function set_exposure(v) { 61 | exposureExp = Math.exp(v); 62 | return exposure = v; 63 | } 64 | 65 | function set_gamma(v:Float) { 66 | invGamma = 1.0/v; 67 | return gamma = v; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "heaps", 3 | "url" : "http://heaps.io", 4 | "license" : "BSD", 5 | "description" : "The GPU Game Framework", 6 | "version" : "2.1.0", 7 | "releasenote" : "See CHANGELOG.md", 8 | "contributors" : ["ncannasse"], 9 | "dependencies" : { "format" : "" } 10 | } -------------------------------------------------------------------------------- /hxd/ByteConversions.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | import haxe.io.Bytes; 4 | 5 | /** 6 | * Tries to provide consistent access to haxe.io.bytes from any primitive 7 | */ 8 | class ByteConversions{ 9 | 10 | #if js 11 | 12 | //public static inline function arrayBufferToBytes( v : hxd.impl.TypedArray.ArrayBuffer ) : haxe.io.Bytes{ 13 | // return haxe.io.Bytes.ofData(v); 14 | //} 15 | 16 | #end 17 | 18 | } 19 | -------------------------------------------------------------------------------- /hxd/BytesBuffer.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | abstract BytesBuffer(haxe.io.BytesOutput) { 4 | 5 | public var length(get, never) : Int; 6 | 7 | public inline function new() { 8 | this = new haxe.io.BytesOutput(); 9 | } 10 | 11 | public static inline function fromU8Array(arr:Array) { 12 | var v = new BytesBuffer(); 13 | for ( i in 0...arr.length) 14 | v.writeByte( arr[i] ); 15 | return v; 16 | } 17 | 18 | public static inline function fromIntArray(arr:Array) { 19 | var v = new BytesBuffer(); 20 | for ( i in 0...arr.length) 21 | v.writeInt32(arr[i]); 22 | return v; 23 | } 24 | 25 | public inline function writeByte( v : Int ) { 26 | this.writeByte(v&255); 27 | } 28 | 29 | public inline function writeFloat( v : Float ) { 30 | this.writeFloat(v); 31 | } 32 | 33 | public inline function writeInt32( v : Int ) { 34 | this.writeInt32(v); 35 | } 36 | 37 | public inline function getBytes() : haxe.io.Bytes { 38 | return this.getBytes(); 39 | } 40 | 41 | inline function get_length() { 42 | return this.length; 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /hxd/Direction.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | enum abstract Direction(Int) { 4 | 5 | public var Up = 1; 6 | public var Left = 4; 7 | public var Right = 6; 8 | public var Down = 9; 9 | 10 | public var x(get, never) : Int; 11 | public var y(get, never) : Int; 12 | public var angle(get, never) : Float; 13 | public var name(get, never) : String; 14 | 15 | inline function new(v) { 16 | this = v; 17 | } 18 | 19 | inline function get_x() { 20 | return (this & 3) - 1; 21 | } 22 | 23 | inline function get_y() { 24 | return (this >> 2) - 1; 25 | } 26 | 27 | inline function get_name() { 28 | return VALUES[this]; 29 | } 30 | 31 | inline function get_angle() { 32 | return Math.atan2(y, x); 33 | } 34 | 35 | public inline function inverse() { 36 | return INVERT[this]; 37 | } 38 | 39 | static var VALUES = ["none", "up", null, null, "left", null, "right", null, null, "down"]; 40 | static var INVERT = [ffrom(1, 1), Down, ffrom(1, -1), ffrom(0, 0), Right, ffrom(0, 0), Left, ffrom(0, 0), ffrom( -1, 1), Up, ffrom( -1, -1), ffrom(0, 0)]; 41 | inline function toString() { 42 | return name; 43 | } 44 | 45 | public static inline function ffrom(dx:Int, dy:Int) { 46 | return new Direction((dx + 1) | ((dy + 1) << 2)); 47 | } 48 | 49 | public static function from(x:Float, y:Float) : Direction { 50 | if( x != 0 && y != 0 ) { 51 | if( Math.abs(x) > Math.abs(y) ) 52 | y = 0; 53 | else 54 | x = 0; 55 | } 56 | var ix = if( x < 0 ) -1 else if( x > 0 ) 1 else 0; 57 | var iy = if( y < 0 ) -1 else if( y > 0 ) 1 else 0; 58 | return cast ((ix + 1) | ((iy + 1) << 2)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hxd/DropFileEvent.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | import haxe.ds.ReadOnlyArray; 4 | import haxe.io.Bytes; 5 | 6 | /** 7 | The information about the dropped file. 8 | **/ 9 | abstract class DroppedFile { 10 | /** 11 | The dropped file name/path. 12 | **/ 13 | public var file(default, null) : String; 14 | #if js 15 | /** 16 | The native JS data transfer file. 17 | **/ 18 | public var native(default, null) : js.html.File; 19 | 20 | #end 21 | 22 | public function new( file : String ) { 23 | this.file = file; 24 | } 25 | 26 | 27 | /** 28 | Retrieve the dropped file contents asynchronously and pass it to `callback`. 29 | **/ 30 | abstract public function getBytes( callback : (data : Bytes) -> Void ) : Void; 31 | } 32 | 33 | /** 34 | The drag&drop operation event. 35 | 36 | @see `hxd.Window.addDragAndDropTarget` 37 | @see `hxd.Window.removeDragAndDropTarget` 38 | **/ 39 | class DropFileEvent { 40 | /** 41 | The list of the files that were dropped. 42 | 43 | Only guaranteed to be populated when `kind == Drop`. 44 | **/ 45 | public var files(default, null): ReadOnlyArray; 46 | /** 47 | The first dropped file. Alias to `files[0]`. 48 | **/ 49 | public var file(get, never): Null; 50 | /** 51 | The X position inside the window at which the file was dropped. 52 | **/ 53 | public var dropX(default, null): Int; 54 | /** 55 | The Y position inside the window at which the file was dropped. 56 | **/ 57 | public var dropY(default, null): Int; 58 | 59 | public function new( files : Array, dx : Int, dy : Int ) { 60 | this.files = files; 61 | this.dropX = dx; 62 | this.dropY = dy; 63 | } 64 | 65 | inline function get_file() return files[0]; 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /hxd/Event.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | enum EventKind { 4 | EPush; 5 | ERelease; 6 | EMove; 7 | EOver; 8 | EOut; 9 | EWheel; 10 | EFocus; 11 | EFocusLost; 12 | EKeyDown; 13 | EKeyUp; 14 | EReleaseOutside; 15 | ETextInput; 16 | /** 17 | Used to check if we are still on the interactive if no EMove was triggered this frame. 18 | **/ 19 | ECheck; 20 | } 21 | 22 | class Event { 23 | 24 | public var kind : EventKind; 25 | public var relX : Float; 26 | public var relY : Float; 27 | public var relZ : Float; 28 | /** 29 | Will propagate the event to other interactives that are below the current one. 30 | **/ 31 | public var propagate : Bool; 32 | /** 33 | Will cancel the default behavior for this event as if it had happen outside of the interactive zone. 34 | **/ 35 | public var cancel : Bool; 36 | public var button : Int = 0; 37 | public var touchId : Int; 38 | public var keyCode : Int; 39 | public var charCode : Int; 40 | public var wheelDelta : Float; 41 | 42 | public function new(k,x=0.,y=0.) { 43 | kind = k; 44 | this.relX = x; 45 | this.relY = y; 46 | } 47 | 48 | public function toString() { 49 | return kind + "[" + Std.int(relX) + "," + Std.int(relY) + "]" + switch( kind ) { 50 | case EPush, ERelease, EReleaseOutside: ",button=" + button; 51 | case EMove, EOver, EOut, EFocus, EFocusLost, ECheck: ""; 52 | case EWheel: ",wheelDelta=" + wheelDelta; 53 | case EKeyDown, EKeyUp: ",keyCode=" + keyCode; 54 | case ETextInput: ",charCode=" + charCode; 55 | } 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /hxd/FloatBufferLoader.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | class FloatBufferLoader { 4 | public var buf(default, null) : FloatBuffer; 5 | public var pos : Int; 6 | 7 | public inline function new(b : FloatBuffer, p : Int){ 8 | buf = b; 9 | pos = p; 10 | } 11 | 12 | public inline function loadMatrix(m:h3d.Matrix) { 13 | buf[pos++] = m._11; 14 | buf[pos++] = m._21; 15 | buf[pos++] = m._31; 16 | buf[pos++] = m._41; 17 | buf[pos++] = m._12; 18 | buf[pos++] = m._22; 19 | buf[pos++] = m._32; 20 | buf[pos++] = m._42; 21 | buf[pos++] = m._13; 22 | buf[pos++] = m._23; 23 | buf[pos++] = m._33; 24 | buf[pos++] = m._43; 25 | buf[pos++] = m._14; 26 | buf[pos++] = m._24; 27 | buf[pos++] = m._34; 28 | buf[pos++] = m._44; 29 | } 30 | 31 | public inline function loadFloat(v : Float) { 32 | buf[pos++] = v; 33 | } 34 | 35 | public inline function loadVec2(v : h3d.Vector) { 36 | buf[pos++] = v.x; 37 | buf[pos++] = v.y; 38 | } 39 | 40 | public inline function loadVec3(v : h3d.Vector) { 41 | buf[pos++] = v.x; 42 | buf[pos++] = v.y; 43 | buf[pos++] = v.z; 44 | } 45 | 46 | public inline function loadVec4(v : h3d.Vector4) { 47 | buf[pos++] = v.x; 48 | buf[pos++] = v.y; 49 | buf[pos++] = v.z; 50 | buf[pos++] = v.w; 51 | } 52 | } -------------------------------------------------------------------------------- /hxd/IndexBuffer.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | private typedef InnerData = Array; 4 | 5 | private class InnerIterator { 6 | var b : InnerData; 7 | var len : Int; 8 | var pos : Int; 9 | public inline function new( b : InnerData ) { 10 | this.b = b; 11 | this.len = this.b.length; 12 | this.pos = 0; 13 | } 14 | public inline function hasNext() { 15 | return pos < len; 16 | } 17 | public inline function next() : Int { 18 | return b[pos++]; 19 | } 20 | } 21 | 22 | abstract IndexBuffer(InnerData) { 23 | 24 | public var length(get, never) : Int; 25 | 26 | public inline function new(length = 0) { 27 | #if js 28 | this = js.Syntax.construct(Array, length); 29 | #else 30 | this = new InnerData(); 31 | if( length > 0 ) grow(length); 32 | #end 33 | } 34 | 35 | public inline function push( v : Int ) { 36 | this.push(v); 37 | } 38 | 39 | public inline function grow( v : Int ) { 40 | #if js 41 | while( this.length < v ) this.push(0); 42 | #else 43 | if( v > this.length ) this[v - 1] = 0; 44 | #end 45 | } 46 | 47 | @:arrayAccess inline function arrayRead(key:Int) : Int { 48 | return this[key]; 49 | } 50 | 51 | @:arrayAccess inline function arrayWrite(key:Int, value : Int) : Int { 52 | return this[key] = value; 53 | } 54 | 55 | public inline function getNative() : InnerData { 56 | return this; 57 | } 58 | 59 | public inline function iterator() { 60 | return new InnerIterator(this); 61 | } 62 | 63 | inline function get_length() : Int { 64 | return this.length; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /hxd/PixelFormat.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | enum PixelFormat { 4 | ARGB; 5 | BGRA; 6 | RGBA; 7 | RGBA16F; 8 | RGBA32F; 9 | R8; 10 | R16F; 11 | R32F; 12 | RG8; 13 | RG16F; 14 | RG32F; 15 | RGB8; 16 | RGB16F; 17 | RGB32F; 18 | SRGB; 19 | SRGB_ALPHA; 20 | RGB10A2; 21 | RG11B10UF; // unsigned float 22 | R16U; 23 | RG16U; 24 | RGB16U; 25 | RGBA16U; 26 | S3TC( v : Int ); 27 | Depth16; 28 | Depth24; 29 | Depth24Stencil8; 30 | Depth32; 31 | } -------------------------------------------------------------------------------- /hxd/Res.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | #if !macro 4 | @:build(hxd.res.FileTree.build()) 5 | #end 6 | class Res { 7 | 8 | #if !macro 9 | public static function load(name:String) { 10 | return loader.load(name); 11 | } 12 | #end 13 | 14 | public static macro function initEmbed(?options:haxe.macro.Expr.ExprOf) { 15 | return macro hxd.Res.loader = new hxd.res.Loader(hxd.fs.EmbedFileSystem.create(null,$options)); 16 | } 17 | 18 | public static macro function initLocal( ?configuration : String ) { 19 | var dir = haxe.macro.Context.definedValue("resourcesPath"); 20 | if( dir == null ) dir = "res"; 21 | dir = haxe.macro.Context.resolvePath(dir); 22 | return macro hxd.Res.loader = new hxd.res.Loader(new hxd.fs.LocalFileSystem($v{dir},$v{configuration})); 23 | } 24 | 25 | public static macro function initPak( ?file : String ) { 26 | if( file == null ) 27 | file = haxe.macro.Context.definedValue("resourcesPath"); 28 | if( file == null ) 29 | file = "res"; 30 | return macro { 31 | var file = $v{file}; 32 | var pak = new hxd.fmt.pak.FileSystem(); 33 | pak.loadPak(file + ".pak"); 34 | var i = 1; 35 | while( true ) { 36 | if( !hxd.File.exists(file + i + ".pak") ) break; 37 | pak.loadPak(file + i + ".pak"); 38 | i++; 39 | } 40 | hxd.Res.loader = new hxd.res.Loader(pak); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /hxd/Stage.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | @:deprecated("hxd.Stage is now hxd.Window") 4 | @:noCompletion 5 | typedef Stage = Window; -------------------------------------------------------------------------------- /hxd/WaitEvent.hx: -------------------------------------------------------------------------------- 1 | package hxd; 2 | 3 | class WaitEvent { 4 | 5 | var updateList : Array Bool> ; 6 | 7 | public function new() { 8 | updateList = []; 9 | } 10 | 11 | public inline function hasEvent() { 12 | return updateList.length > 0; 13 | } 14 | 15 | public function clear() { 16 | updateList = []; 17 | } 18 | 19 | public function add( callb ) { 20 | updateList.push(callb); 21 | } 22 | 23 | public function remove( callb : Float->Bool ) { 24 | for( e in updateList ) 25 | if( Reflect.compareMethods(e, callb) ) { 26 | updateList.remove(e); 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | public function wait( time : Float, callb : Void -> Void ) { 33 | function tmp(dt:Float) { 34 | time -= dt; 35 | if( time < 0 ) { 36 | callb(); 37 | return true; 38 | } 39 | return false; 40 | } 41 | updateList.push(tmp); 42 | } 43 | 44 | public function waitUntil( callb ) { 45 | updateList.push(callb); 46 | } 47 | 48 | public function update(dt:Float) { 49 | var i = 0; 50 | var max = updateList.length; 51 | while (i < updateList.length) { 52 | if( i == max ) break; 53 | var f = updateList[i]; 54 | if(f(dt)) { 55 | updateList.remove(f); 56 | max--; 57 | } else 58 | ++i; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /hxd/clipper/ClipType.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | enum ClipType { 4 | Intersection; 5 | Union; 6 | Difference; 7 | Xor; 8 | } 9 | -------------------------------------------------------------------------------- /hxd/clipper/EndType.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | enum EndType { 4 | ClosedPol; 5 | ClosedLine; 6 | OpenButt; 7 | OpenSquare; 8 | OpenRound; 9 | } 10 | -------------------------------------------------------------------------------- /hxd/clipper/JoinType.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | enum JoinType { 4 | Square; 5 | Round; 6 | Miter; 7 | } 8 | -------------------------------------------------------------------------------- /hxd/clipper/PolyFillType.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | enum PolyFillType { 4 | EvenOdd; 5 | NonZero; 6 | Positive; 7 | Negative; 8 | } 9 | -------------------------------------------------------------------------------- /hxd/clipper/PolyType.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | enum PolyType { 4 | Subject; 5 | Clip; 6 | } 7 | -------------------------------------------------------------------------------- /hxd/clipper/Rect.hx: -------------------------------------------------------------------------------- 1 | package hxd.clipper; 2 | 3 | class Rect { 4 | public var left : Int; 5 | public var top : Int; 6 | public var right : Int; 7 | public var bottom : Int; 8 | 9 | public function new(l=0,t=0,r=0,b=0) { 10 | this.left = l; this.top = t; 11 | this.right = r; this.bottom = b; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /hxd/fmt/bfnt/Reader.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.bfnt; 2 | 3 | import haxe.io.Input; 4 | 5 | @:access(h2d.Font) 6 | class Reader { 7 | 8 | var i : Input; 9 | 10 | public function new( i : Input ) { 11 | this.i = i; 12 | } 13 | 14 | public function read( resolveTile: String -> h2d.Tile ) : h2d.Font { 15 | 16 | if (i.readString(4) != "BFNT" || i.readByte() != 0) throw "Not a BFNT file!"; 17 | 18 | var font : h2d.Font = null; 19 | 20 | switch (i.readByte()) { 21 | case 1: 22 | font = new h2d.Font(i.readString(i.readUInt16()), i.readInt16()); 23 | font.tilePath = i.readString(i.readUInt16()); 24 | var tile = font.tile = resolveTile(font.tilePath); 25 | font.lineHeight = i.readInt16(); 26 | font.baseLine = i.readInt16(); 27 | var defaultChar = i.readInt32(); 28 | var id : Int; 29 | while ( ( id = i.readInt32() ) != 0 ) { 30 | var t = tile.sub(i.readUInt16(), i.readUInt16(), i.readUInt16(), i.readUInt16(), i.readInt16(), i.readInt16()); 31 | var glyph = new h2d.Font.FontChar(t, i.readInt16()); 32 | font.glyphs.set(id, glyph); 33 | if (id == defaultChar) font.defaultChar = glyph; 34 | 35 | var prevChar : Int; 36 | while ( ( prevChar = i.readInt32() ) != 0 ) { 37 | glyph.addKerning(prevChar, i.readInt16()); 38 | } 39 | } 40 | case ver: 41 | throw "Unknown BFNT version: " + ver; 42 | } 43 | 44 | return font; 45 | } 46 | 47 | public static inline function parse(bytes : haxe.io.Bytes, resolveTile : String -> h2d.Tile ) : h2d.Font { 48 | return new Reader(new haxe.io.BytesInput(bytes)).read(resolveTile); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /hxd/fmt/fbx/Filter.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.fbx; 2 | using hxd.fmt.fbx.Data; 3 | 4 | class Filter { 5 | 6 | var ignoreList : Array>; 7 | var removedObjects : Map; 8 | 9 | public function new() { 10 | ignoreList = []; 11 | } 12 | 13 | public function ignore( path : String ) { 14 | ignoreList.push(path.split(".")); 15 | } 16 | 17 | public function filter( f : FbxNode ) : FbxNode { 18 | removedObjects = new Map(); 19 | var f2 = filterRec(f, ignoreList, 0); 20 | for( i in 0...f2.childs.length ) { 21 | var c = f2.childs[i]; 22 | if( c.name == "Connections" ) { 23 | var cnx = []; 24 | for( c in c.childs ) 25 | if( !removedObjects.exists(c.props[1].toInt()) && !removedObjects.exists(c.props[2].toInt()) ) 26 | cnx.push(c); 27 | f2.childs[i] = { 28 | name : c.name, 29 | props : c.props, 30 | childs : cnx, 31 | }; 32 | } 33 | } 34 | return f2; 35 | } 36 | 37 | function filterRec( f : FbxNode, match : Array>, index : Int ) { 38 | var sub = []; 39 | for( m in match ) 40 | if( m[index] == f.name ) { 41 | if( m.length == index + 1 ) 42 | return null; 43 | sub.push(m); 44 | } 45 | if( sub.length == 0 ) 46 | return f; 47 | var f2 = { 48 | name : f.name, 49 | props : f.props.copy(), 50 | childs : [], 51 | }; 52 | var isObjects = index == 1 && f.name == "Objects"; 53 | index++; 54 | for( c in f.childs ) { 55 | var fs = filterRec(c, sub, index); 56 | if( fs != null ) 57 | f2.childs.push(fs); 58 | else if( isObjects ) 59 | removedObjects.set(c.getId(),true); 60 | } 61 | return f2; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /hxd/fmt/grd/Data.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.grd; 2 | 3 | class Gradient { 4 | public var name : String; 5 | public var interpolation : Float; 6 | public var colorStops : Array; 7 | public var transparencyStops : Array; 8 | public var gradientStops : Array; 9 | 10 | public function new() { 11 | colorStops = []; 12 | transparencyStops = []; 13 | gradientStops = []; 14 | } 15 | } 16 | 17 | class ColorStop { 18 | public var color : Color; 19 | public var location : Int; 20 | public var midpoint : Int; 21 | public var type : ColorStopType; 22 | 23 | public function new() {} 24 | } 25 | 26 | enum ColorStopType { 27 | User; 28 | Background; 29 | Foreground; 30 | } 31 | 32 | class TransparencyStop { 33 | public var opacity : Float; 34 | public var location : Int; 35 | public var midpoint : Int; 36 | 37 | public function new() {} 38 | } 39 | 40 | enum Color { 41 | RGB(r:Float, g:Float, b:Float); 42 | HSB(h:Float, s:Float, b:Float); 43 | } 44 | 45 | class GradientStop { 46 | public var opacity : Float; 47 | public var colorStop : ColorStop; 48 | 49 | public function new() {} 50 | } 51 | 52 | class Data extends haxe.ds.StringMap { } 53 | -------------------------------------------------------------------------------- /hxd/fmt/kframes/Data.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.kframes; 2 | 3 | // https://github.com/HeapsIO/Keyframes 4 | 5 | abstract KFSize(Array) { 6 | public var x(get, set) : T; 7 | public var y(get, set) : T; 8 | inline function get_x() return this[0]; 9 | inline function get_y() return this[1]; 10 | inline function set_x(v) return this[0] = v; 11 | inline function set_y(v) return this[1] = v; 12 | } 13 | 14 | enum abstract KFAnimProp(String) { 15 | var AnchorPoint = "ANCHOR_POINT"; 16 | var XPosition = "X_POSITION"; 17 | var YPosition = "Y_POSITION"; 18 | var Scale = "SCALE"; 19 | var Opacity = "OPACITY"; 20 | var Rotation = "ROTATION"; 21 | } 22 | 23 | typedef KFAnimValue = { 24 | var start_frame : Int; 25 | var data : Array; 26 | } 27 | 28 | typedef KFAnimation = { 29 | var property : KFAnimProp; 30 | var key_values : Array; 31 | var timing_curves : Array>>; 32 | } 33 | 34 | typedef KFFeature = { 35 | var name : String; 36 | var feature_id : Int; 37 | var size : KFSize; 38 | var feature_animations : Array; 39 | @:optional var backed_image : String; 40 | @:optional var from_frame : Int; 41 | @:optional var to_frame : Int; 42 | } 43 | 44 | typedef KeyframesFile = { 45 | var formatVersion : String; 46 | var name : String; // COMP 47 | var key : Int; 48 | var frame_rate : Float; 49 | var animation_frame_count : Int; 50 | var canvas_size : KFSize; 51 | var features : Array; 52 | var animation_groups : Array<{}>; // TODO 53 | } 54 | 55 | -------------------------------------------------------------------------------- /hxd/fmt/pak/Data.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.pak; 2 | 3 | class File { 4 | public var name : String; 5 | public var isDirectory : Bool; 6 | public var content : Array; 7 | public var dataPosition : Float; 8 | public var dataSize : Int; 9 | public var checksum : Int; 10 | public function new() { 11 | } 12 | } 13 | 14 | class Data { 15 | public var version : Int; 16 | public var root : File; 17 | public var headerSize : Int; 18 | public var dataSize : Int; 19 | public function new() { 20 | } 21 | } -------------------------------------------------------------------------------- /hxd/fmt/pak/Reader.hx: -------------------------------------------------------------------------------- 1 | package hxd.fmt.pak; 2 | import hxd.fmt.pak.Data; 3 | 4 | class Reader { 5 | 6 | var i : haxe.io.Input; 7 | 8 | public function new(i) { 9 | this.i = i; 10 | } 11 | 12 | public function readHeader() : Data { 13 | if( i.readString(3) != "PAK" ) throw "Invalid PAK file"; 14 | var pak = new Data(); 15 | pak.version = i.readByte(); 16 | pak.headerSize = i.readInt32(); 17 | pak.dataSize = i.readInt32(); 18 | // single read header 19 | var old = i; 20 | i = new haxe.io.BytesInput(i.read(pak.headerSize - 16)); 21 | pak.root = readFile(); 22 | i = old; 23 | if( i.readString(4) != "DATA" ) throw "Corrupted PAK header"; 24 | return pak; 25 | } 26 | 27 | function readFile() : File { 28 | var f = new File(); 29 | f.name = i.readString(i.readByte()); 30 | var flags = i.readByte(); 31 | if( flags & 1 != 0 ) { 32 | f.isDirectory = true; 33 | f.content = []; 34 | for( i in 0...i.readInt32() ) 35 | f.content.push(readFile()); 36 | } else { 37 | f.dataPosition = flags & 2 != 0 ? i.readDouble() : i.readInt32(); 38 | f.dataSize = i.readInt32(); 39 | f.checksum = i.readInt32(); 40 | } 41 | return f; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /hxd/fs/FileSystem.hx: -------------------------------------------------------------------------------- 1 | package hxd.fs; 2 | 3 | interface FileSystem { 4 | public function getRoot() : FileEntry; 5 | public function get( path : String ) : FileEntry; 6 | public function exists( path : String ) : Bool; 7 | public function dispose() : Void; 8 | public function dir( path : String ) : Array ; 9 | } -------------------------------------------------------------------------------- /hxd/fs/LoadedBitmap.hx: -------------------------------------------------------------------------------- 1 | package hxd.fs; 2 | 3 | #if js 4 | typedef LoadedBitmapData = js.html.Image; 5 | #else 6 | typedef LoadedBitmapData = hxd.BitmapData; 7 | #end 8 | 9 | abstract LoadedBitmap(LoadedBitmapData) { 10 | 11 | public inline function new(data) { 12 | this = data; 13 | } 14 | 15 | public function toBitmap() : hxd.BitmapData { 16 | #if js 17 | var bmp = new hxd.BitmapData(this.width, this.height); 18 | @:privateAccess bmp.ctx.drawImage(this, 0, 0); 19 | return bmp; 20 | #else 21 | return this; 22 | #end 23 | } 24 | 25 | public inline function toNative() : LoadedBitmapData { 26 | return this; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /hxd/fs/NotFound.hx: -------------------------------------------------------------------------------- 1 | package hxd.fs; 2 | 3 | class NotFound { 4 | public var path : String; 5 | public function new(path) { 6 | this.path = path; 7 | } 8 | @:keep function toString() { 9 | return "Resource file not found '" + path + "'"; 10 | } 11 | } -------------------------------------------------------------------------------- /hxd/fs/SourceLoader.hx: -------------------------------------------------------------------------------- 1 | package hxd.fs; 2 | 3 | class SourceLoader { 4 | 5 | static var RELOAD_LFS : Array = []; 6 | #if sys 7 | public static function addLivePath( path : String ) { 8 | RELOAD_LFS.push(new hxd.fs.LocalFileSystem(path,"")); 9 | } 10 | public static function addLivePathHaxelib( libs : Array ) { 11 | var p = new sys.io.Process("haxelib",["path"].concat(libs)); 12 | var out = p.stdout.readAll().toString().split("\r\n").join("\n").split("\n"); 13 | p.exitCode(); 14 | for( line in out ) { 15 | if( line.charCodeAt(0) == "-".code ) continue; 16 | addLivePath(line); 17 | } 18 | } 19 | public static function initLivePaths() { 20 | addLivePath("."); 21 | addLivePathHaxelib(["heaps" #if hide,"hide"#end]); 22 | } 23 | #end 24 | 25 | public static function isActive() { 26 | return RELOAD_LFS.length > 0; 27 | } 28 | 29 | public static function resolve( path : String ) { 30 | for( fs in RELOAD_LFS ) 31 | try return fs.get(path) catch( e : hxd.res.NotFound ) {}; 32 | return null; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /hxd/impl/AllocPos.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | class AllocPos { 4 | 5 | static var ENABLED : Bool = false; 6 | 7 | public var position : String; 8 | public var stack : Array = []; 9 | public static var ENGINE_PACKAGES = ["h3d","hxd","h2d","haxe","sys","hrt" /* HIDE */]; 10 | 11 | public static function make() { 12 | if ( !ENABLED ) 13 | return null; 14 | return new AllocPos(); 15 | } 16 | 17 | function new() { 18 | var curStack = haxe.CallStack.callStack(); 19 | curStack.shift(); 20 | for( s in curStack ) { 21 | switch( s ) { 22 | case FilePos(_,file,line,_): 23 | var idx = file.indexOf("\\std/"); 24 | if( idx > 0 ) 25 | file = file.substr(idx + 5); 26 | var pos = file+":"+line; 27 | stack.push(pos); 28 | if( position == null ){ 29 | var p = file.indexOf("/"); 30 | var pack = p < 0 ? "" : file.substr(0,p); 31 | if( ENGINE_PACKAGES.indexOf(pack) < 0 ) position = pos; 32 | } 33 | case Method(cl,meth): 34 | // TODO 35 | case CFunction, Module(_), LocalFunction(_): 36 | // skip 37 | } 38 | } 39 | if( position == null ) position = stack[0]; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /hxd/impl/AnyProps.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | class AnyProps { 4 | 5 | public var props(default, set) : Any; 6 | 7 | function set_props(p) { 8 | this.props = p; 9 | refreshProps(); 10 | return p; 11 | } 12 | 13 | public function setDefaultProps( kind : String ) { 14 | props = getDefaultProps(kind); 15 | } 16 | 17 | public function getDefaultProps( ?kind : String ) : Any { 18 | return {}; 19 | } 20 | 21 | public function refreshProps() { 22 | } 23 | 24 | #if (editor && js) 25 | public function editProps() { 26 | return new js.jquery.JQuery('

No properties for this object

'); 27 | } 28 | #end 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hxd/impl/AppContext.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | #if hl 4 | /** 5 | Create an app context to allow multiple apps to run in parallel. 6 | Requires compilation with -D multidriver 7 | **/ 8 | class AppContext { 9 | 10 | static var contexts : Array = []; 11 | 12 | public var win : hxd.Window; 13 | public var engine : h3d.Engine; 14 | public var app : hxd.App; 15 | 16 | public function new(app) { 17 | #if !multidriver 18 | throw "Needs -D multidriver"; 19 | #end 20 | this.app = app; 21 | win = hxd.Window.getInstance(); 22 | win.onClose = function() { 23 | @:privateAccess app.dispose(); 24 | return true; 25 | }; 26 | engine = h3d.Engine.getCurrent(); 27 | var curReady = engine.onReady; 28 | engine.onReady = function() { 29 | curReady(); 30 | reset(); 31 | hxd.System.setLoop(run); 32 | }; 33 | contexts.push(this); 34 | reset(); 35 | } 36 | 37 | public function update() { 38 | if( app.sevents == null ) 39 | return; 40 | engine.setCurrent(); 41 | @:privateAccess { 42 | hxd.System.loopFunc = app.mainLoop; 43 | hxd.System.mainLoop(); 44 | hxd.System.loopFunc = run; 45 | } 46 | reset(); 47 | } 48 | 49 | static function run() { 50 | for( c in contexts ) 51 | c.update(); 52 | } 53 | 54 | public static function reset() @:privateAccess { 55 | h3d.Engine.CURRENT = null; 56 | hxd.Window.inst = null; 57 | } 58 | 59 | public static function set( app : hxd.App ) { 60 | for( c in contexts ) 61 | if( c.app == app ) 62 | c.engine.setCurrent(); 63 | } 64 | 65 | } 66 | #end 67 | -------------------------------------------------------------------------------- /hxd/impl/ArrayIterator.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | @:generic class ArrayIterator { 4 | var i : Int; 5 | var l : Int; 6 | var a : Array; 7 | public inline function new(a) { 8 | this.i = 0; 9 | this.a = a; 10 | this.l = this.a.length; 11 | } 12 | public inline function hasNext() { 13 | return i < l; 14 | } 15 | public inline function next() : T { 16 | return a[i++]; 17 | } 18 | } -------------------------------------------------------------------------------- /hxd/impl/BitSet.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | abstract BitSet(haxe.io.Bytes) { 4 | 5 | public function new(count:Int) { 6 | this = haxe.io.Bytes.alloc((count + 7) >> 3); 7 | } 8 | 9 | public function get(index:Int) { 10 | return this.get(index>>3) & (1 << (index&7)) != 0; 11 | } 12 | 13 | public function set(index:Int) { 14 | var p = index >> 3; 15 | this.set(p, this.get(p) | (1 << (index&7))); 16 | } 17 | 18 | public function unset(index:Int) { 19 | var p = index >> 3; 20 | this.set(p, this.get(p) & ~(1 << (index&7))); 21 | } 22 | 23 | public function toggle(index:Int, b : Bool) { 24 | var p = index >> 3; 25 | var v = this.get(p); 26 | var mask = 1 << (index&7); 27 | this.set(p, b ? v | mask : v & ~mask); 28 | } 29 | 30 | public function clear(b=false) { 31 | this.fill(0,this.length,b?0xFF:0); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /hxd/impl/Float32.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | typedef Float32 = #if hl hl.F32 #else Float #end; -------------------------------------------------------------------------------- /hxd/impl/TypedArray.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | #if js 4 | 5 | typedef Float32Array = js.lib.Float32Array; 6 | typedef Uint16Array = js.lib.Uint16Array; 7 | typedef Int16Array = js.lib.Int16Array; 8 | typedef Uint8Array = js.lib.Uint8Array; 9 | typedef ArrayBuffer = js.lib.ArrayBuffer; 10 | typedef Uint32Array = js.lib.Uint32Array; 11 | typedef ArrayBufferView = js.lib.ArrayBufferView; 12 | 13 | #else 14 | typedef Float32Array = haxe.ds.Vector; 15 | #end -------------------------------------------------------------------------------- /hxd/impl/UInt16.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | typedef UInt16 = #if hl hl.UI16 #else Int #end; -------------------------------------------------------------------------------- /hxd/impl/UncheckedBytes.hx: -------------------------------------------------------------------------------- 1 | package hxd.impl; 2 | 3 | private typedef InnerData = #if hl hl.Bytes #elseif js TypedArray.Uint8Array #else haxe.io.BytesData #end 4 | 5 | abstract UncheckedBytes(InnerData) { 6 | 7 | inline function new(v) { 8 | this = v; 9 | } 10 | 11 | @:arrayAccess inline function get( i : Int ) : Int { 12 | #if neko 13 | return untyped $sget(b,i); 14 | #else 15 | return this[i]; 16 | #end 17 | } 18 | 19 | @:arrayAccess inline function set( i : Int, v : Int ) : Int { 20 | #if neko 21 | untyped $sset(b,i,v); 22 | #else 23 | this[i] = v; 24 | #end 25 | return v; 26 | } 27 | 28 | @:from public static inline function fromBytes( b : haxe.io.Bytes ) : UncheckedBytes { 29 | #if hl 30 | return new UncheckedBytes(b); 31 | #elseif js 32 | return new UncheckedBytes(@:privateAccess b.b); 33 | #else 34 | return new UncheckedBytes(b.getData()); 35 | #end 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /hxd/net/BinaryLoader.hx: -------------------------------------------------------------------------------- 1 | package hxd.net; 2 | 3 | class BinaryLoader { 4 | 5 | public var url(default, null) : String; 6 | 7 | public function new( url : String ) { 8 | this.url = url; 9 | } 10 | 11 | public dynamic function onLoaded( bytes : haxe.io.Bytes ) { 12 | } 13 | 14 | public dynamic function onProgress( cur : Int, max : Int ) { 15 | } 16 | 17 | public dynamic function onError( msg : String ) { 18 | throw msg; 19 | } 20 | 21 | public function load() { 22 | #if js 23 | 24 | var xhr = new js.html.XMLHttpRequest(); 25 | xhr.open('GET', url, true); 26 | xhr.responseType = js.html.XMLHttpRequestResponseType.ARRAYBUFFER; 27 | xhr.onerror = function(e) onError(xhr.statusText); 28 | 29 | xhr.onload = function(e) { 30 | 31 | if (xhr.status != 200) { 32 | onError(xhr.statusText); 33 | return; 34 | } 35 | onLoaded(haxe.io.Bytes.ofData(xhr.response)); 36 | } 37 | 38 | xhr.onprogress = function(e) { 39 | onProgress(Std.int(js.Syntax.code("{0}.loaded || {0}.position", e)), Std.int(js.Syntax.code("{0}.total || {0}.totalSize", e))); 40 | } 41 | xhr.send(); 42 | 43 | #else 44 | 45 | throw "Not available on this platform"; 46 | 47 | #end 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /hxd/poly2tri/Basin.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class Basin 4 | { 5 | public var left_node:Node; 6 | public var bottom_node:Node; 7 | public var right_node:Node; 8 | public var width:Float; 9 | public var left_highest:Bool; 10 | 11 | public function new() 12 | { 13 | width = 0; 14 | } 15 | 16 | public function clear() 17 | { 18 | 19 | this.left_node = null ; 20 | this.bottom_node = null ; 21 | this.right_node = null ; 22 | this.width = 0.0 ; 23 | this.left_highest = false; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /hxd/poly2tri/Constants.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | #if fastPoly2tri 4 | typedef Unit = Int; 5 | #else 6 | typedef Unit = Float; 7 | #end 8 | 9 | class Constants { 10 | /* 11 | * Inital triangle factor, seed triangle will extend 30% of 12 | * PointSet width to both left and right. 13 | */ 14 | static public var kAlpha:Float = 0.3; 15 | #if fastPoly2tri 16 | static public var EPSILON = 0; 17 | #else 18 | static public var EPSILON:Float = 1e-24; 19 | #end 20 | static public var PI_2:Float = Math.PI / 2; 21 | static public var PI_3div4:Float = 3 * Math.PI / 4; 22 | } 23 | -------------------------------------------------------------------------------- /hxd/poly2tri/Edge.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class Edge 4 | { 5 | public var p:Point; 6 | public var q:Point; 7 | 8 | public function new(p1:Point, p2:Point) 9 | { 10 | if (p1==null || p2==null) throw "Edge::new p1 or p2 is null"; 11 | 12 | var swap = false; 13 | 14 | if (p1.y > p2.y) 15 | { 16 | swap = true; 17 | } 18 | else if (p1.y == p2.y) 19 | { 20 | if (p1.x == p2.x) throw "Edge::repeat points " + p1; 21 | 22 | swap = (p1.x > p2.x); 23 | } 24 | 25 | 26 | if (swap) 27 | { 28 | q = p1; 29 | p = p2; 30 | } 31 | else 32 | { 33 | p = p1; 34 | q = p2; 35 | } 36 | 37 | q.edge_list.push( this ); 38 | } 39 | 40 | 41 | 42 | public function toString() 43 | { 44 | return "Edge(" + this.p + ", " + this.q + ")"; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /hxd/poly2tri/EdgeEvent.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class EdgeEvent 4 | { 5 | public var constrained_edge:Edge; 6 | public var right:Bool; 7 | 8 | public function new() 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /hxd/poly2tri/Node.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class Node 4 | { 5 | 6 | 7 | public var point:Point; 8 | public var triangle:Triangle; 9 | public var prev:Node; 10 | public var next:Node; 11 | public var value:Float; 12 | 13 | public function new(point:Point = null, triangle:Triangle = null) 14 | { 15 | 16 | this.point = point; 17 | this.triangle = triangle; 18 | this.value = this.point.x; 19 | } 20 | 21 | /** 22 | * 23 | * @param node - middle node 24 | * @return the angle between 3 front nodes 25 | */ 26 | public function getHoleAngle():Float 27 | { 28 | /* Complex plane 29 | * ab = cosA +i*sinA 30 | * ab = (ax + ay*i)(bx + by*i) = (ax*bx + ay*by) + i(ax*by-ay*bx) 31 | * atan2(y,x) computes the principal value of the argument function 32 | * applied to the complex number x+iy 33 | * Where x = ax*bx + ay*by 34 | * y = ax*by - ay*bx 35 | */ 36 | var ax = this.next.point.x - this.point.x; 37 | var ay = this.next.point.y - this.point.y; 38 | var bx = this.prev.point.x - this.point.x; 39 | var by = this.prev.point.y - this.point.y; 40 | return Math.atan2( 41 | ax * by - ay * bx, 42 | ax * bx + ay * by 43 | ); 44 | } 45 | 46 | public function getBasinAngle():Float 47 | { 48 | return Math.atan2( 49 | this.point.y - this.next.next.point.y, // ay 50 | this.point.x - this.next.next.point.x // ax 51 | ); 52 | } 53 | 54 | 55 | 56 | 57 | } -------------------------------------------------------------------------------- /hxd/poly2tri/Orientation.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class Orientation 4 | { 5 | inline public static var CW = 1; 6 | inline public static var CCW = -1; 7 | inline public static var COLLINEAR = 0; 8 | 9 | public static function orient2d(pa:Point, pb:Point, pc:Point):Int 10 | { 11 | var detleft = (pa.x - pc.x) * (pb.y - pc.y); 12 | var detright = (pa.y - pc.y) * (pb.x - pc.x); 13 | var val = detleft - detright; 14 | 15 | #if fastPoly2tri 16 | if( val == 0 ) return COLLINEAR; 17 | #else 18 | if ((val > -Constants.EPSILON) && (val < Constants.EPSILON)) return Orientation.COLLINEAR; 19 | #end 20 | if (val > 0) return Orientation.CCW; 21 | return Orientation.CW; 22 | } 23 | } -------------------------------------------------------------------------------- /hxd/poly2tri/Point.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class Point 4 | { 5 | public var id:Int; 6 | 7 | #if fastPoly2tri 8 | public var x:Int; 9 | public var y:Int; 10 | #else 11 | public var x:Float; 12 | public var y:Float; 13 | #end 14 | 15 | /// The edges this point constitutes an upper ending point 16 | #if haxe3 17 | public var edge_list(get, null):Array; 18 | #else 19 | public var edge_list(get_edge_list, null):Array; 20 | #end 21 | 22 | public function new(x,y) 23 | { 24 | this.x = x; 25 | this.y = y; 26 | 27 | id = C_ID; 28 | C_ID++; 29 | 30 | } 31 | 32 | 33 | function get_edge_list() 34 | { 35 | if (edge_list==null) edge_list = new Array(); 36 | return edge_list; 37 | } 38 | 39 | 40 | 41 | public inline function equals(that:Point):Bool 42 | { 43 | #if fastPoly2Tri 44 | return this == that; 45 | #else 46 | return (this.x == that.x) && (this.y == that.y); 47 | #end 48 | } 49 | 50 | public static function sortPoints(points:Array) 51 | { 52 | points.sort( cmpPoints ); 53 | } 54 | 55 | public static function cmpPoints(l:Point,r:Point) 56 | { 57 | var ret = l.y - r.y; 58 | if (ret == 0) ret = l.x - r.x; 59 | if (ret < 0) return -1; 60 | if (ret > 0) return 1; 61 | return 0; 62 | } 63 | 64 | public function toString() 65 | { 66 | return "Point(" + x + ", " + y + ")"; 67 | } 68 | 69 | public static var C_ID = 0; 70 | 71 | 72 | 73 | 74 | } 75 | 76 | -------------------------------------------------------------------------------- /hxd/poly2tri/VisiblePolygon.hx: -------------------------------------------------------------------------------- 1 | package hxd.poly2tri; 2 | 3 | class VisiblePolygon 4 | { 5 | 6 | var sweepContext:SweepContext; 7 | var sweep:Sweep; 8 | var triangulated:Bool; 9 | 10 | public function new() 11 | { 12 | reset(); 13 | } 14 | 15 | 16 | public function addPolyline(polyline:Array) 17 | { 18 | sweepContext.addPolyline(polyline); 19 | } 20 | 21 | public function reset() 22 | { 23 | sweepContext = new SweepContext(); 24 | sweep = new Sweep(sweepContext); 25 | triangulated = false; 26 | } 27 | 28 | public function performTriangulationOnce() 29 | { 30 | if (this.triangulated) return; 31 | triangulated = true; 32 | sweep.triangulate(); 33 | } 34 | 35 | //returns vertices in a 3D engine-friendly, XYZ format 36 | public function getVerticesAndTriangles() 37 | { 38 | if (!this.triangulated) return null; 39 | 40 | var vertices = new Array(); 41 | var ids = new Map(); 42 | 43 | for (i in 0...sweepContext.points.length) 44 | { 45 | var p = sweepContext.points[i]; 46 | vertices.push(p.x); 47 | vertices.push(p.y); 48 | vertices.push(0); 49 | ids[p.id] = i; 50 | } 51 | 52 | var tris = new Array(); 53 | for (t in sweepContext.triangles) 54 | { 55 | for (i in 0...3) 56 | { 57 | tris.push( ids[ t.points[i].id ] ); 58 | } 59 | } 60 | 61 | return { vertices: vertices, triangles:tris }; 62 | } 63 | 64 | public function getNumTriangles() 65 | { 66 | return sweepContext.triangles.length; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /hxd/res/AnimGraph.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | #if hide 4 | typedef AnimGraph = hrt.animgraph.Resource; 5 | #else 6 | typedef AnimGraph = hxd.res.Resource; 7 | #end 8 | -------------------------------------------------------------------------------- /hxd/res/Any.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | private class SingleFileSystem extends hxd.fs.BytesFileSystem { 4 | 5 | var path : String; 6 | var bytes : haxe.io.Bytes; 7 | 8 | public function new(path, bytes) { 9 | super(); 10 | this.path = path; 11 | this.bytes = bytes; 12 | } 13 | 14 | override function getBytes(p) { 15 | return p == path ? bytes : null; 16 | } 17 | 18 | } 19 | 20 | @:access(hxd.res.Loader) 21 | class Any extends Resource { 22 | 23 | var loader : Loader; 24 | 25 | public function new(loader, entry) { 26 | super(entry); 27 | this.loader = loader; 28 | } 29 | 30 | public function toModel() { 31 | return loader.loadCache(entry.path, hxd.res.Model); 32 | } 33 | 34 | public function toTexture() { 35 | return toImage().toTexture(); 36 | } 37 | 38 | public function toTile() { 39 | return toImage().toTile(); 40 | } 41 | 42 | public function toText() { 43 | return entry.getText(); 44 | } 45 | 46 | public function toImage() { 47 | return loader.loadCache(entry.path, hxd.res.Image); 48 | } 49 | 50 | public function toSound() { 51 | return loader.loadCache(entry.path, hxd.res.Sound); 52 | } 53 | 54 | public function toPrefab() { 55 | return loader.loadCache(entry.path, hxd.res.Prefab); 56 | } 57 | 58 | public function toAnimGraph() { 59 | return loader.loadCache(entry.path, hxd.res.AnimGraph); 60 | } 61 | 62 | public function to( c : Class ) : T { 63 | return loader.loadCache(entry.path, c); 64 | } 65 | 66 | public inline function iterator() { 67 | return new hxd.impl.ArrayIterator([for( f in entry ) new Any(loader,f)]); 68 | } 69 | 70 | public static function fromBytes( path : String, bytes : haxe.io.Bytes ) { 71 | var fs = new SingleFileSystem(path,bytes); 72 | return new Loader(fs).load(path); 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /hxd/res/DefaultFont.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | class DefaultFont { 4 | 5 | public static function get() : h2d.Font { 6 | var engine = h3d.Engine.getCurrent(); 7 | var fnt : h2d.Font = engine.resCache.get(DefaultFont); 8 | if( fnt == null ) { 9 | var BYTES = hxd.res.Embed.getResource("hxd/res/defaultFont.png"); 10 | var DESC = hxd.res.Embed.getResource("hxd/res/defaultFont.fnt"); 11 | var bmp = new BitmapFont(DESC.entry); 12 | @:privateAccess bmp.loader = BYTES.loader; 13 | fnt = bmp.toFont(); 14 | engine.resCache.set(DefaultFont, fnt); 15 | } 16 | return fnt; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /hxd/res/EmbedOptions.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | typedef EmbedOptions = { 4 | ?configuration : String, 5 | ?fontsChars : String, 6 | } -------------------------------------------------------------------------------- /hxd/res/Font.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | /** 4 | Allows to build a font bitmap to be used by h2d.Text. Only some platforms support such runtime Font building 5 | and the result in terms of font quality, antialiasing, etc might vary depending on the platform. 6 | It is recommended to use offline BitmapFont instead, read https://heaps.io/documentation/text.html 7 | **/ 8 | class Font extends Resource { 9 | 10 | public function build( size : Int, ?options ) : h2d.Font { 11 | #if js 12 | var name = "R_" + ~/[^A-Za-z0-9_]/g.replace(entry.path, "_"); 13 | return FontBuilder.getFont(name, size, options); 14 | #else 15 | throw "Not implemented for this platform"; 16 | return null; 17 | #end 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /hxd/res/Loader.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | class Loader { 4 | 5 | /** 6 | Set when initializing hxd.Res, or manually. 7 | Allows code to resolve resources without compiling hxd.Res 8 | */ 9 | public static var currentInstance : Loader; 10 | 11 | public var fs(default,null) : hxd.fs.FileSystem; 12 | var cache : Map; 13 | 14 | public function new(fs) { 15 | this.fs = fs; 16 | cache = new Map(); 17 | } 18 | 19 | public function cleanCache() { 20 | cache = new Map(); 21 | } 22 | 23 | public function dir( path : String ) : Array { 24 | var r : Array = []; 25 | var entries = fs.dir(path); 26 | for(e in entries) 27 | r.push(new Any(this, e)); 28 | return r; 29 | } 30 | 31 | public function exists( path : String ) : Bool { 32 | return fs.exists(path); 33 | } 34 | 35 | public function load( path : String ) : Any { 36 | return new Any(this, fs.get(path)); 37 | } 38 | 39 | public function loadCache( path : String, c : Class ) : T { 40 | var res : T = cache.get(path); 41 | if( res == null ) { 42 | var entry = fs.get(path); 43 | var old = currentInstance; 44 | currentInstance = this; 45 | res = Type.createInstance(c, [entry]); 46 | currentInstance = old; 47 | cache.set(path, res); 48 | } else { 49 | if( Std.downcast(res,c) == null ) 50 | throw path+" has been reintrepreted from "+Type.getClass(res)+" to "+c; 51 | } 52 | return res; 53 | } 54 | 55 | public function dispose() { 56 | cleanCache(); 57 | fs.dispose(); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /hxd/res/Model.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | class Model extends Resource { 4 | 5 | public function toHmd() : hxd.fmt.hmd.Library { 6 | var fs = entry.open(); 7 | var hmd = new hxd.fmt.hmd.Reader(fs).readHeader(#if editor true #end); 8 | fs.close(); 9 | return new hxd.fmt.hmd.Library(this, hmd); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /hxd/res/NotFound.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | typedef NotFound = hxd.fs.NotFound; -------------------------------------------------------------------------------- /hxd/res/Prefab.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | #if hide 4 | typedef Prefab = hrt.prefab.Resource; 5 | #else 6 | typedef Prefab = hxd.res.Resource; 7 | #end 8 | -------------------------------------------------------------------------------- /hxd/res/Resource.hx: -------------------------------------------------------------------------------- 1 | package hxd.res; 2 | 3 | class Resource { 4 | 5 | public static var LIVE_UPDATE = #if debug true #else false #end; 6 | 7 | public var name(get, never) : String; 8 | public var entry(default,null) : hxd.fs.FileEntry; 9 | 10 | public function new(entry) { 11 | this.entry = entry; 12 | } 13 | 14 | inline function get_name() { 15 | return entry.name; 16 | } 17 | 18 | function toString() { 19 | return entry.path; 20 | } 21 | 22 | public function watch( onChanged : Null < Void -> Void > ) { 23 | if( LIVE_UPDATE ) entry.watch(onChanged); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /hxd/res/defaultFont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/hxd/res/defaultFont.png -------------------------------------------------------------------------------- /hxd/snd/ChannelGroup.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | 3 | class ChannelGroup extends ChannelBase { 4 | 5 | public var name (default, null) : String; 6 | 7 | public function new(name : String) { 8 | super(); 9 | this.name = name; 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /hxd/snd/Effect.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | 3 | import hxd.snd.Driver; 4 | 5 | @:allow(hxd.snd.Manager) 6 | class Effect { 7 | @:noCompletion public var next : Effect; 8 | var refs : Int; 9 | var retainTime : Float; 10 | var lastStamp : Float; 11 | var driver : EffectDriver; 12 | var priority : Int; 13 | 14 | public function new(type : String) { 15 | this.refs = 0; 16 | this.priority = 0; 17 | this.retainTime = 0.0; 18 | this.lastStamp = 0.0; 19 | 20 | @:privateAccess 21 | var managerDriver = hxd.snd.Manager.get().driver; 22 | if (managerDriver != null) { 23 | this.driver = managerDriver.getEffectDriver(type); 24 | } 25 | } 26 | 27 | // used to evaluate volume modification for virtualization sorting 28 | public function applyAudibleVolumeModifier(v : Float) : Float { 29 | return v; 30 | } 31 | 32 | // used to tweak channel volume after virtualization sorting 33 | public function getVolumeModifier() : Float { 34 | return 1; 35 | } 36 | } -------------------------------------------------------------------------------- /hxd/snd/Listener.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | 3 | class Listener { 4 | 5 | public var position : h3d.Vector; 6 | public var direction : h3d.Vector; 7 | public var velocity : h3d.Vector; 8 | public var up : h3d.Vector; 9 | 10 | public function new() { 11 | position = new h3d.Vector(); 12 | velocity = new h3d.Vector(); 13 | direction = new h3d.Vector(1, 0, 0); 14 | up = new h3d.Vector(0, 0, 1); 15 | } 16 | 17 | public function syncCamera( cam : h3d.Camera ) { 18 | position.load(cam.pos); 19 | direction.set(cam.target.x - cam.pos.x, cam.target.y - cam.pos.y, cam.target.z - cam.pos.z); 20 | direction.normalize(); 21 | up.load(cam.up); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /hxd/snd/LoadingData.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | 3 | class LoadingData extends Data { 4 | 5 | var snd : hxd.res.Sound; 6 | var waitCount = 0; 7 | 8 | public function new(snd) { 9 | this.snd = snd; 10 | } 11 | 12 | override function decode(out:haxe.io.Bytes, outPos:Int, sampleStart:Int, sampleCount:Int):Void { 13 | var d = snd.getData(); 14 | if( d is LoadingData ) 15 | throw "Sound data is not yet available, use load() first"; 16 | d.decode(out, outPos, sampleStart, sampleCount); 17 | } 18 | 19 | override public function load(onEnd:Void->Void) { 20 | if( waitCount > 10 ) 21 | throw "Failed to load data"; 22 | var d = snd.getData(); 23 | if( Std.isOfType(d, LoadingData) ) { 24 | waitCount++; 25 | haxe.Timer.delay(load.bind(onEnd), 100); 26 | return; 27 | } 28 | d.load(onEnd); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /hxd/snd/SoundGroup.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | 3 | @:allow(hxd.snd.Manager) 4 | class SoundGroup { 5 | public var name (default, null) : String; 6 | public var volume : Float; 7 | public var maxAudible : Int; 8 | public var mono : Bool; 9 | 10 | var numAudible : Int; 11 | var lastUpdate : Float; 12 | 13 | public function new(name : String) { 14 | this.name = name; 15 | maxAudible = -1; 16 | volume = 1; 17 | mono = false; 18 | } 19 | } -------------------------------------------------------------------------------- /hxd/snd/WavData.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd; 2 | import format.wav.Data; 3 | 4 | class WavData extends hxd.snd.Data { 5 | 6 | var rawData : haxe.io.Bytes; 7 | 8 | public function new(bytes) { 9 | if( bytes != null ) 10 | init(new format.wav.Reader(new haxe.io.BytesInput(bytes)).read()); 11 | } 12 | 13 | function init(d:format.wav.Data.WAVE) { 14 | var h = d.header; 15 | samplingRate = h.samplingRate; 16 | channels = h.channels; 17 | sampleFormat = switch( h.bitsPerSample ) { 18 | case 8: UI8; 19 | case 16: I16; 20 | default: 21 | throw "Unsupported WAV " + h.bitsPerSample + " bits"; 22 | } 23 | rawData = d.data; 24 | samples = Std.int(rawData.length / getBytesPerSample()); 25 | } 26 | 27 | override function decodeBuffer(out:haxe.io.Bytes, outPos:Int, sampleStart:Int, sampleCount:Int) { 28 | var bpp = getBytesPerSample(); 29 | out.blit(outPos, rawData, sampleStart * bpp, sampleCount * bpp); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /hxd/snd/effect/LowPass.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.effect; 2 | 3 | class LowPass extends hxd.snd.Effect { 4 | public var gainHF : Float; 5 | 6 | public function new() { 7 | super("lowpass"); 8 | priority = 100; 9 | gainHF = 1.0; 10 | } 11 | } -------------------------------------------------------------------------------- /hxd/snd/effect/Pitch.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.effect; 2 | 3 | class Pitch extends hxd.snd.Effect { 4 | public var value : Float; 5 | 6 | public function new(value = 1.0) { 7 | super("pitch"); 8 | this.value = value; 9 | } 10 | } -------------------------------------------------------------------------------- /hxd/snd/effect/Reverb.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.effect; 2 | 3 | // I3DL reverb 4 | 5 | class Reverb extends hxd.snd.Effect { 6 | public var wetDryMix : Float; // [0.0, 100.0] % 7 | public var room : Float; // [-10000 0] mb 8 | public var roomHF : Float; // [-10000, 0] mb 9 | public var roomRolloffFactor : Float; // [0.0, 10.0] 10 | public var decayTime : Float; // [0.1, 20.0] s 11 | public var decayHFRatio : Float; // [0.1, 2.0] 12 | public var reflections : Float; // [-10000, 1000] mb 13 | public var reflectionsDelay : Float; // [0.0, 0.3] s 14 | public var reverb : Float; // [-10000, 2000] mb 15 | public var reverbDelay : Float; // [0.0, 0.1] s 16 | public var diffusion : Float; // [0.0, 100.0] % 17 | public var density : Float; // [0.0, 100.0] % 18 | public var hfReference : Float; // [20.0, 20000.0] 19 | 20 | public function new(?preset : ReverbPreset) { 21 | super("reverb"); 22 | wetDryMix = 100.0; 23 | loadPreset(preset != null ? preset : ReverbPreset.DEFAULT); 24 | } 25 | 26 | public function loadPreset(preset : ReverbPreset) { 27 | room = preset.room; 28 | roomHF = preset.roomHF; 29 | roomRolloffFactor = preset.roomRolloffFactor; 30 | decayTime = preset.decayTime; 31 | decayHFRatio = preset.decayHFRatio; 32 | reflections = preset.reflections; 33 | reflectionsDelay = preset.reflectionsDelay; 34 | reverb = preset.reverb; 35 | reverbDelay = preset.reverbDelay; 36 | diffusion = preset.diffusion; 37 | density = preset.density; 38 | hfReference = preset.hfReference; 39 | } 40 | } -------------------------------------------------------------------------------- /hxd/snd/effect/Spatialization.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.effect; 2 | 3 | class Spatialization extends hxd.snd.Effect { 4 | public var position : h3d.Vector; 5 | public var velocity : h3d.Vector; 6 | public var direction : h3d.Vector; 7 | 8 | public var referenceDistance : Float; 9 | public var maxDistance : Null; 10 | public var fadeDistance : Null; 11 | public var rollOffFactor : Float; 12 | 13 | public function new() { 14 | super("spatialization"); 15 | position = new h3d.Vector(); 16 | velocity = new h3d.Vector(); 17 | direction = new h3d.Vector(); 18 | 19 | referenceDistance = 1.0; 20 | rollOffFactor = 1.0; 21 | } 22 | 23 | override function getVolumeModifier() { 24 | if( fadeDistance == null ) return 1.; 25 | var dist = Manager.get().listener.position.distance(position); 26 | if (maxDistance != null) dist -= maxDistance; 27 | else dist -= referenceDistance; 28 | var volume = 1 - dist / fadeDistance; 29 | if (volume > 1) volume = 1; 30 | if (volume < 0) volume = 0; 31 | return volume; 32 | } 33 | 34 | override function applyAudibleVolumeModifier(v : Float) { 35 | var dist = Manager.get().listener.position.distance(position); 36 | dist = Math.max(dist, referenceDistance); 37 | if (maxDistance != null) dist = Math.min(dist, maxDistance); 38 | var volume = referenceDistance/(referenceDistance + rollOffFactor * (dist - referenceDistance)); 39 | return v * volume; 40 | } 41 | } -------------------------------------------------------------------------------- /hxd/snd/openal/AudioTypes.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.openal; 2 | 3 | #if hlopenal 4 | import openal.AL.Source; 5 | import openal.AL.Buffer; 6 | typedef AL = openal.AL; 7 | typedef EFX = openal.EFX; 8 | #else 9 | import hxd.snd.openal.Emulator; 10 | typedef AL = Emulator; 11 | #end 12 | 13 | class BufferHandle { 14 | public var inst : Buffer; 15 | public var isEnd : Bool; 16 | public function new() { } 17 | } 18 | 19 | class SourceHandle { 20 | public var inst : Source; 21 | public var sampleOffset : Int; 22 | public var playing : Bool; 23 | var nextAuxiliarySend : Int; 24 | var freeAuxiliarySends : Array; 25 | var effectToAuxiliarySend : Map; 26 | 27 | public function new() { 28 | sampleOffset = 0; 29 | nextAuxiliarySend = 0; 30 | freeAuxiliarySends = []; 31 | effectToAuxiliarySend = new Map(); 32 | } 33 | 34 | public function acquireAuxiliarySend(effect : Effect) : Int { 35 | var send = freeAuxiliarySends.length > 0 36 | ? freeAuxiliarySends.shift() 37 | : nextAuxiliarySend++; 38 | effectToAuxiliarySend.set(effect, send); 39 | return send; 40 | } 41 | 42 | public function getAuxiliarySend(effect : Effect) : Int { 43 | return effectToAuxiliarySend.get(effect); 44 | } 45 | 46 | public function releaseAuxiliarySend(effect : Effect) : Int { 47 | var send = effectToAuxiliarySend.get(effect); 48 | effectToAuxiliarySend.remove(effect); 49 | freeAuxiliarySends.push(send); 50 | return send; 51 | } 52 | } -------------------------------------------------------------------------------- /hxd/snd/openal/LowPassDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.openal; 2 | 3 | import hxd.snd.openal.AudioTypes; 4 | import hxd.snd.effect.LowPass; 5 | 6 | class LowPassDriver extends hxd.snd.Driver.EffectDriver { 7 | var driver : Driver; 8 | var inst : openal.EFX.Filter; 9 | 10 | public function new(driver) { 11 | super(); 12 | this.driver = driver; 13 | } 14 | 15 | override function acquire() : Void { 16 | var bytes = driver.getTmpBytes(4); 17 | EFX.genFilters(1, bytes); 18 | inst = openal.EFX.Filter.ofInt(bytes.getInt32(0)); 19 | EFX.filteri(inst, EFX.FILTER_TYPE, EFX.FILTER_LOWPASS); 20 | } 21 | 22 | override function release() : Void { 23 | var bytes = driver.getTmpBytes(4); 24 | bytes.setInt32(0, inst.toInt()); 25 | EFX.deleteFilters(1, bytes); 26 | } 27 | 28 | override function update(e : LowPass) : Void { 29 | EFX.filterf(inst, EFX.LOWPASS_GAIN, 1.0); 30 | EFX.filterf(inst, EFX.LOWPASS_GAINHF, e.gainHF); 31 | } 32 | 33 | override function apply(e : LowPass, source : SourceHandle) : Void { 34 | AL.sourcei(source.inst, EFX.DIRECT_FILTER, inst.toInt()); 35 | } 36 | 37 | override function unbind(e : LowPass, source : SourceHandle) : Void { 38 | AL.sourcei(source.inst, EFX.DIRECT_FILTER, EFX.FILTER_NULL); 39 | } 40 | } -------------------------------------------------------------------------------- /hxd/snd/openal/PitchDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.openal; 2 | 3 | import hxd.snd.Driver; 4 | import hxd.snd.openal.AudioTypes; 5 | import hxd.snd.effect.Pitch; 6 | 7 | class PitchDriver extends EffectDriver { 8 | 9 | override function apply(e : Pitch, source : SourceHandle) : Void { 10 | AL.sourcef(source.inst, AL.PITCH, Std.downcast(e, hxd.snd.effect.Pitch).value); 11 | } 12 | 13 | override function unbind(e : Pitch, source : SourceHandle) : Void { 14 | AL.sourcef(source.inst, AL.PITCH, 1.); 15 | } 16 | } -------------------------------------------------------------------------------- /hxd/snd/openal/SpatializationDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.openal; 2 | 3 | import hxd.snd.Driver; 4 | import hxd.snd.openal.AudioTypes; 5 | import hxd.snd.effect.Spatialization; 6 | 7 | class SpatializationDriver extends EffectDriver { 8 | var driver : Driver; 9 | 10 | public function new(driver) { 11 | super(); 12 | this.driver = driver; 13 | } 14 | 15 | override function bind(e : Spatialization, s : SourceHandle) : Void { 16 | AL.sourcei(s.inst, AL.SOURCE_RELATIVE, AL.FALSE); 17 | } 18 | 19 | override function apply(e : Spatialization, s : SourceHandle) : Void { 20 | var e = Std.downcast(e, hxd.snd.effect.Spatialization); 21 | 22 | AL.source3f(s.inst, AL.POSITION, -e.position.x, e.position.y, e.position.z); 23 | AL.source3f(s.inst, AL.VELOCITY, -e.velocity.x, e.velocity.y, e.velocity.z); 24 | AL.source3f(s.inst, AL.DIRECTION, -e.direction.x, e.direction.y, e.direction.z); 25 | AL.sourcef(s.inst, AL.REFERENCE_DISTANCE, e.referenceDistance); 26 | AL.sourcef(s.inst, AL.ROLLOFF_FACTOR, e.rollOffFactor); 27 | var maxDist : Float = e.maxDistance == null ? 3.40282347e38 : e.maxDistance; 28 | AL.sourcef(s.inst, AL.MAX_DISTANCE, maxDist ); 29 | } 30 | 31 | override function unbind(e : Spatialization, s : SourceHandle) : Void { 32 | AL.sourcei (s.inst, AL.SOURCE_RELATIVE, AL.TRUE); 33 | AL.source3f(s.inst, AL.POSITION, 0, 0, 0); 34 | AL.source3f(s.inst, AL.VELOCITY, 0, 0, 0); 35 | AL.source3f(s.inst, AL.DIRECTION, 0, 0, 0); 36 | } 37 | } -------------------------------------------------------------------------------- /hxd/snd/webaudio/LowPassDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.webaudio; 2 | 3 | #if (js && !useal) 4 | import js.html.audio.BiquadFilterType; 5 | import js.html.audio.AudioContext; 6 | import js.html.audio.BiquadFilterNode; 7 | import hxd.snd.effect.LowPass; 8 | import hxd.snd.Driver.EffectDriver; 9 | import hxd.snd.webaudio.AudioTypes; 10 | 11 | class LowPassDriver extends EffectDriver { 12 | 13 | var pool : Array; 14 | 15 | public function new() { 16 | pool = []; 17 | super(); 18 | } 19 | 20 | function get( ctx : AudioContext ) { 21 | if ( pool.length != 0 ) { 22 | return pool.pop(); 23 | } 24 | var node = ctx.createBiquadFilter(); 25 | node.type = BiquadFilterType.LOWPASS; 26 | return node; 27 | } 28 | 29 | override public function bind(e:LowPass, source: SourceHandle) : Void { 30 | source.lowPass = get(source.driver.ctx); 31 | source.updateDestination(); 32 | apply(e, source); 33 | } 34 | 35 | override function apply(e : LowPass, source : SourceHandle) : Void { 36 | var min = 40; 37 | var max = source.driver.ctx.sampleRate / 2; 38 | var octaves = js.lib.Math.log(max / min) / js.lib.Math.LN2; 39 | source.lowPass.frequency.value = max * Math.pow(2, octaves * (e.gainHF - 1)); 40 | } 41 | 42 | override function unbind(e : LowPass, source : SourceHandle) : Void { 43 | pool.push(source.lowPass); 44 | source.lowPass.disconnect(); 45 | source.lowPass = null; 46 | if ( source.driver != null ) 47 | source.updateDestination(); 48 | } 49 | } 50 | #end -------------------------------------------------------------------------------- /hxd/snd/webaudio/PitchDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.webaudio; 2 | 3 | #if (js && !useal) 4 | import hxd.snd.Driver; 5 | import hxd.snd.webaudio.AudioTypes; 6 | import hxd.snd.effect.Pitch; 7 | 8 | class PitchDriver extends EffectDriver { 9 | 10 | override function apply(e : Pitch, source : SourceHandle) : Void { 11 | if ( source.pitch != e.value ) { 12 | source.pitch = e.value; 13 | source.applyPitch(); 14 | } 15 | } 16 | 17 | override function unbind(e : Pitch, source : SourceHandle) : Void { 18 | source.pitch = 1; 19 | source.applyPitch(); 20 | } 21 | } 22 | #end -------------------------------------------------------------------------------- /hxd/snd/webaudio/SpatializationDriver.hx: -------------------------------------------------------------------------------- 1 | package hxd.snd.webaudio; 2 | 3 | #if (js && !useal) 4 | import js.html.audio.PannerNode; 5 | import js.html.audio.AudioContext; 6 | import hxd.snd.effect.Spatialization; 7 | import hxd.snd.Driver.EffectDriver; 8 | import hxd.snd.webaudio.AudioTypes; 9 | 10 | class SpatializationDriver extends EffectDriver { 11 | 12 | var pool : Array; 13 | 14 | public function new() { 15 | pool = []; 16 | super(); 17 | } 18 | 19 | function get( ctx : AudioContext ) { 20 | if ( pool.length != 0 ) { 21 | return pool.pop(); 22 | } 23 | var node = ctx.createPanner(); 24 | return node; 25 | } 26 | 27 | override public function bind(e : Spatialization, source: SourceHandle) : Void { 28 | source.panner = get(source.driver.ctx); 29 | source.updateDestination(); 30 | apply(e, source); 31 | } 32 | 33 | override function apply(e : Spatialization, source : SourceHandle) : Void { 34 | source.panner.setPosition(-e.position.x, e.position.y, e.position.z); 35 | source.panner.setOrientation(-e.direction.x, e.direction.y, e.direction.z); 36 | // TODO: Velocity 37 | source.panner.rolloffFactor = e.rollOffFactor; 38 | source.panner.refDistance = e.referenceDistance; 39 | var maxDist : Float = e.maxDistance == null ? 3.40282347e38 : e.maxDistance; 40 | source.panner.maxDistance = maxDist; 41 | } 42 | 43 | override function unbind(e : Spatialization, source : SourceHandle) : Void { 44 | pool.push(source.panner); 45 | source.panner.disconnect(); 46 | source.panner = null; 47 | if ( source.driver != null ) 48 | source.updateDestination(); 49 | } 50 | } 51 | #end -------------------------------------------------------------------------------- /hxd/tools/Mikktspace.hx: -------------------------------------------------------------------------------- 1 | package hxd.tools; 2 | 3 | #if hl 4 | class Mikktspace { 5 | public var buffer:hl.BytesAccess; 6 | public var stride:Int; 7 | public var xPos:Int; 8 | public var normalPos:Int; 9 | public var uvPos:Int; 10 | public var tangents:hl.BytesAccess; 11 | public var tangentStride:Int; 12 | public var tangentPos:Int; 13 | public var indexes:hl.BytesAccess; 14 | public var indices:Int; 15 | 16 | public function new() {} 17 | 18 | public function compute(threshold = 180.) { 19 | if (!_compute(this, threshold)) 20 | throw "assert"; 21 | } 22 | 23 | #if (hl_ver >= version("1.15.0")) 24 | @:hlNative("heaps", "compute_mikkt_tangents") 25 | #else 26 | @:hlNative("fmt", "compute_mikkt_tangents") 27 | #end 28 | static function _compute(m:Dynamic, threshold:Float):Bool { 29 | return false; 30 | } 31 | } 32 | #end 33 | -------------------------------------------------------------------------------- /hxsl/BatchShader.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | class BatchShader extends hxsl.Shader { 4 | 5 | static var SRC = { 6 | @const var Batch_HasOffset : Bool; 7 | @const var Batch_UseStorage : Bool; 8 | @const(4096) var Batch_Count : Int; 9 | @param var Batch_Buffer : Buffer; 10 | @param var Batch_StorageBuffer : RWBuffer; 11 | }; 12 | 13 | public var params : RuntimeShader.AllocParam; 14 | public var paramsSize : Int; 15 | 16 | } -------------------------------------------------------------------------------- /hxsl/Channel.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | enum Channel { 4 | Unknown; 5 | R; 6 | G; 7 | B; 8 | A; 9 | PackedFloat; 10 | PackedNormal; 11 | } 12 | -------------------------------------------------------------------------------- /hxsl/ChannelTexture.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | typedef ChannelTexture = { texture : hxsl.Types.TextureChannel, channel : hxsl.Channel }; 4 | -------------------------------------------------------------------------------- /hxsl/Debug.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | class Debug { 4 | 5 | public static var VAR_IDS = #if shader_debug_var_ids true #else false #end; 6 | public static var TRACE = #if shader_debug_dump true #else false #end; 7 | 8 | public static macro function trace(str) { 9 | return macro if( hxsl.Debug.TRACE ) trace($str); 10 | } 11 | 12 | public static function varName( v : Ast.TVar, swizBits = 15 ) { 13 | var name = v.name; 14 | if( swizBits != 15 ) name += swizStr(swizBits); 15 | return VAR_IDS ? name+"@"+v.id : name; 16 | } 17 | 18 | static function swizStr( bits : Int ) { 19 | var str = "."; 20 | if( bits & 1 != 0 ) str += "x"; 21 | if( bits & 2 != 0 ) str += "y"; 22 | if( bits & 4 != 0 ) str += "z"; 23 | if( bits & 8 != 0 ) str += "w"; 24 | return str; 25 | } 26 | 27 | public static macro function traceDepth(str) { 28 | return macro if( hxsl.Debug.TRACE ) { 29 | var msg = $str; 30 | for( i in 0...debugDepth ) msg = " " + msg; 31 | trace(msg); 32 | }; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /hxsl/Output.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | enum Output { 4 | Const( v : Float); 5 | Value( v : String, ?size : Int ); 6 | PackNormal( v : Output ); 7 | PackFloat( v : Output ); 8 | Vec2( a : Array ); 9 | Vec3( a : Array ); 10 | Vec4( a : Array ); 11 | Swiz( a : Output, swiz : Array ); 12 | } 13 | -------------------------------------------------------------------------------- /hxsl/Types.hx: -------------------------------------------------------------------------------- 1 | package hxsl; 2 | 3 | typedef Vec = h3d.Vector; 4 | typedef Vec4 = h3d.Vector4; 5 | typedef IVec = Array; 6 | typedef BVec = Array; 7 | typedef Matrix = h3d.Matrix; 8 | typedef Texture = h3d.mat.Texture; 9 | typedef TextureArray = h3d.mat.TextureArray; 10 | typedef TextureChannel = h3d.mat.Texture; 11 | typedef Buffer = h3d.Buffer; 12 | 13 | class ChannelTools { 14 | public static inline function isPackedFormat( c : TextureChannel ) { 15 | return c.format == h3d.mat.Texture.nativeFormat; 16 | } 17 | } -------------------------------------------------------------------------------- /samples/AdjustColor.hx: -------------------------------------------------------------------------------- 1 | 2 | class AdjustColor extends SampleApp { 3 | 4 | var hue = 0.; 5 | var sat = 0.; 6 | var bright = 0.; 7 | var contrast = 0.; 8 | 9 | var bmps : Array; 10 | 11 | override function init() { 12 | super.init(); 13 | 14 | engine.backgroundColor = 0x404040; 15 | 16 | bmps = []; 17 | for( i in 0...4 ) { 18 | var gradient = new hxd.BitmapData(256, 256); 19 | var red = (i + 1) & 1; 20 | var green = ((i + 1) >> 1) & 1; 21 | var blue = (i + 1) >> 2; 22 | for( x in 0...gradient.width ) 23 | for( y in 0...gradient.height ) 24 | gradient.setPixel(x,y, 0xFF000000 | ((x << 16) * red) | ((y << 8) * green) | (((x + y) >> 1) * blue)); 25 | 26 | var bmp = new h2d.Bitmap(h2d.Tile.fromBitmap(gradient), s2d); 27 | bmp.x = 50 + (i&1) * 270; 28 | bmp.y = 100 + (i >> 1) * 270; 29 | bmps.push(bmp); 30 | } 31 | 32 | addSlider("Hue", function() return hue, function(s) hue = s, -180, 180); 33 | addSlider("Saturation", function() return sat, function(s) sat = s, -100, 100); 34 | addSlider("Brightness", function() return bright, function(s) bright = s, -100, 100); 35 | addSlider("Contrast", function() return contrast, function(s) contrast = s, -100, 100); 36 | } 37 | 38 | override function update(dt:Float) { 39 | for( b in bmps ) 40 | b.adjustColor({ saturation : sat / 100, lightness : bright / 100, hue : hue * Math.PI / 180, contrast : contrast / 100 }); 41 | } 42 | 43 | public static function main() { 44 | new AdjustColor(); 45 | } 46 | 47 | 48 | } -------------------------------------------------------------------------------- /samples/ExtraTests.hx: -------------------------------------------------------------------------------- 1 | 2 | class CheckMacroCompilation { 3 | 4 | // check correct compilation of these files in macro mode 5 | //var t : h2d.Tile; 6 | //var tex : h3d.mat.Texture; 7 | 8 | public static function check() { 9 | return macro null; 10 | } 11 | } 12 | 13 | #if !macro 14 | class ExtraTests extends hxd.App { 15 | 16 | override function init() { 17 | CheckMacroCompilation.check(); 18 | } 19 | 20 | static function main() { 21 | new ExtraTests(); 22 | } 23 | 24 | } 25 | #end -------------------------------------------------------------------------------- /samples/Fullscreen.hx: -------------------------------------------------------------------------------- 1 | class Fullscreen extends SampleApp { 2 | 3 | override function init() { 4 | super.init(); 5 | addButton("Toggle FullScreen", function() { 6 | engine.fullScreen = !engine.fullScreen; 7 | }); 8 | addButton("Error Message Test", function() throw "Error!"); 9 | 10 | if( hxd.System.allowTimeout ) 11 | addButton("Infinite loop test", function() while(true) {}); 12 | } 13 | 14 | static function main() { 15 | new Fullscreen(); 16 | } 17 | } -------------------------------------------------------------------------------- /samples/FxView.hx: -------------------------------------------------------------------------------- 1 | import hrt.prefab.fx.FX; 2 | import hrt.prefab.l3d.Polygon; 3 | 4 | class ColorMult extends hxsl.Shader { 5 | static var SRC = { 6 | @param var color : Vec3; 7 | @param var amount : Float = 1.0; 8 | var pixelColor : Vec4; 9 | 10 | function fragment() { 11 | pixelColor.rgb = mix(pixelColor.rgb, pixelColor.rgb * color, amount); 12 | } 13 | } 14 | } 15 | 16 | //PARAM=-lib hide 17 | class FxView extends hxd.App { 18 | 19 | 20 | override function init() { 21 | var prefab = hxd.Res.hideEffect.load(); 22 | var unk = prefab.getOpt(hrt.prefab.Unknown); 23 | if( unk != null ) 24 | throw "Prefab "+unk.type+" was not compiled"; 25 | 26 | var ctx = new hrt.prefab.ContextShared(s2d, s3d); 27 | 28 | function play() { 29 | var i = prefab.make(ctx); 30 | var obj = i.to(hrt.prefab.Object3D); 31 | if( obj != null ) { 32 | var fx = cast(obj.local3d, hrt.prefab.fx.FX.FXAnimation); 33 | fx.onEnd = function() { 34 | fx.remove(); 35 | play(); 36 | }; 37 | } 38 | } 39 | play(); 40 | 41 | new h3d.scene.CameraController(20,s3d); 42 | var text = new h2d.Text(hxd.res.DefaultFont.get(), s2d); 43 | text.text = "Drag and move with your mouse!"; 44 | 45 | } 46 | 47 | static function main() { 48 | h3d.mat.PbrMaterialSetup.set(); 49 | hxd.Res.initEmbed(); 50 | new FxView(); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /samples/Input.hx: -------------------------------------------------------------------------------- 1 | class Input extends hxd.App { 2 | 3 | var input : h2d.TextInput; 4 | var debug : h2d.Text; 5 | 6 | override function init() { 7 | 8 | engine.backgroundColor = 0x202020; 9 | 10 | var font = hxd.res.DefaultFont.get(); 11 | var console = new h2d.Console(font, s2d); 12 | console.addCommand("hello", "Prints the correct answer", [], function() console.log("World", 0xFF00FF)); 13 | 14 | debug = new h2d.Text(font, s2d); 15 | debug.scale(2); 16 | debug.x = debug.y = 5; 17 | 18 | input = new h2d.TextInput(font, s2d); 19 | input.backgroundColor = 0x80808080; 20 | // input.inputWidth = 100; 21 | 22 | input.text = "Click to édit"; 23 | input.textColor = 0xAAAAAA; 24 | 25 | input.scale(2); 26 | input.x = input.y = 50; 27 | 28 | input.onFocus = function(_) { 29 | input.textColor = 0xFFFFFF; 30 | } 31 | input.onFocusLost = function(_) { 32 | input.textColor = 0xAAAAAA; 33 | } 34 | 35 | input.onChange = function() { 36 | while( input.text.length > 20 ) 37 | input.text = input.text.substr(0, -1); 38 | } 39 | } 40 | 41 | function getKeyName(id) { 42 | var name = hxd.Key.getKeyName(id); 43 | if( name == null ) name = "#"+id; 44 | return name; 45 | } 46 | 47 | override function update(dt:Float) { 48 | // check special keys state 49 | debug.text = "Cursor: " + input.cursorIndex + ", Sel: " + input.getSelectedText()+", Touch screen: " + hxd.System.getValue(IsTouch) + ", Down: "+[for( i in 0...1024 ) if( hxd.Key.isDown(i) ) getKeyName(i)].join(","); 50 | } 51 | 52 | static function main() { 53 | new Input(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /samples/Skin.hx: -------------------------------------------------------------------------------- 1 | import h3d.scene.*; 2 | import h3d.scene.fwd.*; 3 | 4 | class Skin extends SampleApp { 5 | 6 | var cache : h3d.prim.ModelCache; 7 | 8 | override function init() { 9 | cache = new h3d.prim.ModelCache(); 10 | 11 | var obj = cache.loadModel(hxd.Res.Model); 12 | obj.scale(0.1); 13 | s3d.addChild(obj); 14 | s3d.camera.pos.set( -3, -5, 3); 15 | s3d.camera.target.z += 1; 16 | 17 | obj.playAnimation(cache.loadAnimation(hxd.Res.Model)); 18 | 19 | // add lights and setup materials 20 | var dir = new DirLight(new h3d.Vector( -1, 3, -10), s3d); 21 | for( m in obj.getMaterials() ) { 22 | var t = m.mainPass.getShader(h3d.shader.Texture); 23 | if( t != null ) t.killAlpha = true; 24 | m.mainPass.culling = None; 25 | m.getPass("shadow").culling = None; 26 | } 27 | cast(s3d.lightSystem,h3d.scene.fwd.LightSystem).ambientLight.set(0.4, 0.4, 0.4); 28 | 29 | var shadow = s3d.renderer.getPass(h3d.pass.DefaultShadowMap); 30 | shadow.power = 20; 31 | shadow.color.setColor(0x301030); 32 | dir.enableSpecular = true; 33 | 34 | new h3d.scene.CameraController(s3d).loadFromCamera(); 35 | } 36 | 37 | static function main() { 38 | hxd.Res.initEmbed(); 39 | new Skin(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/Tiled.hx: -------------------------------------------------------------------------------- 1 | import hxd.res.TiledMap.TiledMapData; 2 | 3 | // Renders a Tiled tile map directly from a .tmx source file 4 | // Tiled Options Required in your map: 5 | // Tile Layer Format: Base64 (zlib compressed) 6 | // Tile Render Order: Left Down 7 | 8 | class Tiled extends hxd.App { 9 | 10 | inline static var TILE_SIZE:Int = 16; 11 | var tiles:h2d.TileGroup; 12 | var obj:h2d.Object; 13 | 14 | override function init() { 15 | var tiledMapData = hxd.Res.tileMap.toMap(); // .tmx file 16 | var tiles = hxd.Res.tiles.toTile(); // tile sheet used in .tmx file above 17 | 18 | // Specify the layers in the order they appear in the .tmx file 19 | // Currently the layer id and name attribute or not stored in the TiledMapData format 20 | drawLayer(tiledMapData, tiles, 0, TILE_SIZE); 21 | drawLayer(tiledMapData, tiles, 1, TILE_SIZE); 22 | drawLayer(tiledMapData, tiles, 2, TILE_SIZE); 23 | drawLayer(tiledMapData, tiles, 3, TILE_SIZE); 24 | } 25 | 26 | function drawLayer(map:TiledMapData, tiles:h2d.Tile, layer:Int, size:Int) { 27 | var tileGroup = new h2d.TileGroup(tiles); 28 | var tileSetArray = tiles.gridFlatten(TILE_SIZE, 0, 0); 29 | if( map.layers.length > 0 && layer < map.layers.length ) { 30 | var tileX = 0; 31 | var tileY = 0; 32 | for( tileId in map.layers[layer].data ) { 33 | // Tiled stores empty tiles as 0 and offsets the tileId by 1 so we must skip empty tiles and adjust the tileId back to the proper index 34 | if( tileId > 0 && tileId < tileSetArray.length ) tileGroup.add(tileX, tileY, tileSetArray[tileId - 1]); 35 | tileX += size; 36 | if( tileX >= map.width * size ) { 37 | tileX = 0; 38 | tileY += size; 39 | } 40 | } 41 | } 42 | 43 | s2d.addChild(tileGroup); 44 | } 45 | 46 | static function main() { 47 | hxd.Res.initEmbed(); 48 | new Tiled(); 49 | } 50 | } -------------------------------------------------------------------------------- /samples/Video.hx: -------------------------------------------------------------------------------- 1 | 2 | class Video extends hxd.App { 3 | 4 | var video : h2d.Video; 5 | var tf : h2d.Text; 6 | 7 | override function init() { 8 | tf = new h2d.Text(hxd.res.DefaultFont.get(), s2d); 9 | video = new h2d.Video(s2d); 10 | video.onError = function(e) { 11 | tf.text = e; 12 | tf.textColor = 0xFF0000; 13 | }; 14 | function start() { 15 | #if hl 16 | video.loadFile("testVideo.avi"); 17 | #elseif js 18 | video.loadFile("testVideo.mp4"); 19 | #end 20 | } 21 | video.onEnd = start; 22 | start(); 23 | } 24 | 25 | override function update(dt:Float) { 26 | if( video.videoWidth != 0 && video.videoHeight != 0 ) { 27 | tf.text = (Std.int(video.time*10)/10)+"s"; 28 | var scale = hxd.Math.min(s2d.width / video.videoWidth, s2d.height / video.videoHeight); 29 | video.setScale(scale); 30 | video.x = Std.int((s2d.width - video.videoWidth * scale) * 0.5); 31 | video.y = Std.int((s2d.height - video.videoHeight * scale) * 0.5); 32 | } 33 | } 34 | 35 | static function main() { 36 | new Video(); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /samples/all.hxml: -------------------------------------------------------------------------------- 1 | -D silent 2 | gen.hxml 3 | --next 4 | --macro Generator.compile() -------------------------------------------------------------------------------- /samples/domkit_res/style.css: -------------------------------------------------------------------------------- 1 | .mybox { 2 | background: #080; 3 | padding: -10; 4 | } 5 | 6 | view.mybox { 7 | padding: 10; 8 | } 9 | 10 | container { 11 | max-width: 300; 12 | layout: vertical; 13 | } 14 | 15 | button { 16 | background: #333; 17 | fill-width: true; 18 | height: 30; 19 | transition: background 0.5; 20 | } 21 | 22 | button.highlight { 23 | background: #a33; 24 | } 25 | 26 | button text { 27 | align: middle middle; 28 | } 29 | 30 | button:hover { 31 | background: #444; 32 | } 33 | 34 | button text { 35 | align: middle middle; 36 | color : #aaa; 37 | transition : color; 38 | } 39 | 40 | button:hover text { 41 | color : white; 42 | } 43 | 44 | button:active { 45 | background: #666; 46 | } -------------------------------------------------------------------------------- /samples/fxView_res/ray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/fxView_res/ray.jpg -------------------------------------------------------------------------------- /samples/gen.hxml: -------------------------------------------------------------------------------- 1 | -lib hscript 2 | -dce no 3 | --macro Generator.generateProjects() -------------------------------------------------------------------------------- /samples/particles2d_res/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/particles2d_res/arrow.png -------------------------------------------------------------------------------- /samples/pbr_res/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/back.jpg -------------------------------------------------------------------------------- /samples/pbr_res/bottom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/bottom.jpg -------------------------------------------------------------------------------- /samples/pbr_res/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/front.jpg -------------------------------------------------------------------------------- /samples/pbr_res/left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/left.jpg -------------------------------------------------------------------------------- /samples/pbr_res/right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/right.jpg -------------------------------------------------------------------------------- /samples/pbr_res/top.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/pbr_res/top.jpg -------------------------------------------------------------------------------- /samples/res/customFont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/res/customFont.png -------------------------------------------------------------------------------- /samples/res/hxlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/res/hxlogo.png -------------------------------------------------------------------------------- /samples/res/normalmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/res/normalmap.png -------------------------------------------------------------------------------- /samples/skin_res/Skeleton01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/skin_res/Skeleton01.png -------------------------------------------------------------------------------- /samples/skin_res/Sword01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/skin_res/Sword01.png -------------------------------------------------------------------------------- /samples/sound_res/music_loop.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/sound_res/music_loop.mp3 -------------------------------------------------------------------------------- /samples/sound_res/music_loop.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/sound_res/music_loop.ogg -------------------------------------------------------------------------------- /samples/sound_res/sound_fx.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/sound_res/sound_fx.wav -------------------------------------------------------------------------------- /samples/templates/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Utilisez IntelliSense pour en savoir plus sur les attributs possibles. 3 | // Pointez pour afficher la description des attributs existants. 4 | // Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "HashLink", 9 | "request": "launch", 10 | "type": "hl", 11 | "hxml": "::name::_hl.hxml", 12 | "cwd": "${workspaceRoot}", 13 | "preLaunchTask": "HeapsHL" 14 | }, 15 | { 16 | "type": "chrome", 17 | "request": "launch", 18 | "name": "Chrome WebGL", 19 | "url": "file://${workspaceFolder}/index.html", 20 | "webRoot": "${workspaceFolder}", 21 | "preLaunchTask": "HeapsJS" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /samples/templates/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "haxe", 8 | "args": "active configuration", 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | }, 14 | { 15 | "label": "HeapsJS", 16 | "type": "hxml", 17 | "file": "::name::_js.hxml" 18 | }, 19 | { 20 | "label": "HeapsHL", 21 | "type": "hxml", 22 | "file": "::name::_hl.hxml" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /samples/templates/__name_hl.hxml: -------------------------------------------------------------------------------- 1 | -lib heaps 2 | -lib hlsdl 3 | -hl ::name::.hl 4 | -main ::main:: 5 | -D windowSize=1024x768 6 | -cp ../.. 7 | -cp . 8 | ::params:: 9 | -------------------------------------------------------------------------------- /samples/templates/__name_js.hxml: -------------------------------------------------------------------------------- 1 | -lib heaps 2 | -js ::name::.js 3 | -main ::main:: 4 | -cp ../.. 5 | -cp . 6 | -debug 7 | ::params:: 8 | -------------------------------------------------------------------------------- /samples/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | ::name:: 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/text_res/bmfont_binary.fnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/bmfont_binary.fnt -------------------------------------------------------------------------------- /samples/text_res/bmfont_binary_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/bmfont_binary_0.png -------------------------------------------------------------------------------- /samples/text_res/gravityFont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/gravityFont.png -------------------------------------------------------------------------------- /samples/text_res/littera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/littera.png -------------------------------------------------------------------------------- /samples/text_res/sdf_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/sdf_font.png -------------------------------------------------------------------------------- /samples/text_res/trueTypeFont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/text_res/trueTypeFont.ttf -------------------------------------------------------------------------------- /samples/tiled_res/tileMap.tmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | eJxTZWBgUAViNSA+x8jAcB6ILwCxNpAvSwZWHcHmbQaaswWIt1JgngMUO6K5Tx3IdyYDT2dE4CtAvAuILzOiiqPjaXjkNpGBN+KRO0sGPoPE3gnEV4F4B5TPxUA+5kYLcwGk+CUHY0sTlJqHnmZHzRs1b9S8UfNGzRuc5gEAzcisrw== 9 | 10 | 11 | 12 | 13 | eJzt1LFuQVEcBnB3kWgnrdVQia14hZrQUU1qKkY1YTJgwdQatEPbd9AO6DNgwFt4CZ/kk9ycnHvu6bk3HcQ/+eUk31++/GO4gYD77CBk6dGZoGaXbt8NfhfTZDJRhfOc9sRd5OFBomDYV4NnibqirwiPghJ3fRhIDBV9DWgKWtyF4QqubSLMnfpe4FUw4u4WspCzuWfu1NeGDnSpx+ywy0ACkjYp5k597/ABn/TFzPS+H5jCjObMjvfJ+lT3rWANG9oyO+yeoAwVmypz2dx5kJb0vVlmxny3wjf52zIz4fsr9C0tMwu+c6HvwoNLyf/n9j1QkY1qpxqdvr/c5Vef3/f9d98e+35l3A== 14 | 15 | 16 | 17 | 18 | eJxjYBgFo2AUjALiQTYjJqYEtDFiYlLdQCnAZ38OIyYmBAIZUTGloBloRisjgkYBUL4lIyp/FIwCaoLVQLyGAF5LgnnHgPg4AXxiiJsHAJyoLE8= 19 | 20 | 21 | 22 | 23 | eJxjYBgFlAIjRkyx2VjEKAEHqGvcsASzaBTmIgTM9WPEThMDXpLqKAJuINX+gQTfB9oBQOBK5bCqxmOeBAV2eQL1ekGx9xCJ36EOZtKpDJckwx5i9YgC1ekBsS4Q60MxiC86wGnIgwT7kwfArdRyHwD+bQxy 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /samples/tiled_res/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/tiled_res/tiles.png -------------------------------------------------------------------------------- /samples/world_res/rock.hmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/world_res/rock.hmd -------------------------------------------------------------------------------- /samples/world_res/rockTexture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/world_res/rockTexture.jpg -------------------------------------------------------------------------------- /samples/world_res/tree.hmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/world_res/tree.hmd -------------------------------------------------------------------------------- /samples/world_res/treeTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeapsIO/heaps/22d7329a15cb98f26d3a3d41c72a5016703c61de/samples/world_res/treeTexture.png -------------------------------------------------------------------------------- /tools/hxsl/hxsl.hxml: -------------------------------------------------------------------------------- 1 | -lib heaps 2 | -lib hscript 3 | -js hxsl.js 4 | -main Main 5 | -D hscriptPos 6 | -------------------------------------------------------------------------------- /tools/hxsl/hxsl.hxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /tools/meshTools/Makefile: -------------------------------------------------------------------------------- 1 | # these are the default paths where hashlink is installed with `make install` 2 | ifndef HASHLINK 3 | HASHLINK=/usr/local/include 4 | endif 5 | 6 | ifndef HASHLINK_BIN 7 | HASHLINK=/usr/local/lib 8 | endif 9 | 10 | all: codegen 11 | gcc -I $HASHLINK -I out out/main.c -lhl -L${HASHLINK_BIN}/heaps.hdll -o meshtools 12 | 13 | codegen: 14 | haxe meshtools.hxml -D no-compilation 15 | 16 | -------------------------------------------------------------------------------- /tools/meshTools/build_msvc.bat: -------------------------------------------------------------------------------- 1 | haxe meshtools.hxml -D no-compilation 2 | call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 3 | cl /Ox /Femeshtools.exe -I %HASHLINK_SRC%/src -I out out/main.c %HASHLINK_SRC%/x64/Release/libhl.lib %HASHLINK_SRC%/x64/Release/heaps.lib 4 | -------------------------------------------------------------------------------- /tools/meshTools/meshtools.hxml: -------------------------------------------------------------------------------- 1 | -hl out/main.c 2 | -lib heaps 3 | -main MeshTools 4 | -D hl-ver=1.15.0 5 | --------------------------------------------------------------------------------