├── .gitignore ├── .vscode └── launch.json ├── BFSInnerNode.cpp ├── BFSInnerNode.h ├── BFSJob.h ├── BFSOctree.cpp ├── BFSOctree.h ├── CMakeLists.txt ├── Camera.cpp ├── Camera.h ├── Glue.cpp ├── Glue.h ├── LICENSE.md ├── Light.cpp ├── Light.h ├── Object3D.cpp ├── Object3D.h ├── README.md ├── Renderer.cu ├── Renderer.h ├── Texture.cpp ├── Texture.h ├── VisualData.cpp ├── VisualData.h ├── VoxelData.h ├── content ├── diffuse.raw ├── illum.raw ├── imrod.asvo ├── normal.raw └── spec.raw ├── extended_helper_math.h ├── float4x4.h ├── main.cpp └── prototype ├── XNAnimation ├── ChangeLog.txt ├── Documentation.txt ├── FAQ.txt ├── TODO.txt ├── XNAnimation.sln ├── XNAnimation │ ├── AnimationChannel.cs │ ├── AnimationChannelDictionary.cs │ ├── AnimationChannelKeyframe.cs │ ├── AnimationClip.cs │ ├── AnimationClipDictionary.cs │ ├── Controllers │ │ ├── AnimationController.cs │ │ ├── IAnimationController.cs │ │ ├── IBlendController.cs │ │ ├── IBlendable.cs │ │ ├── ISkeletonController.cs │ │ └── SkeletonController.cs │ ├── Effects │ │ ├── ILight.cs │ │ ├── IMaterial.cs │ │ ├── IPointLight.cs │ │ ├── Material.cs │ │ ├── PointLight.cs │ │ ├── PointLightCollection.cs │ │ └── SkinnedModelBasicEffect.cs │ ├── Pipeline │ │ ├── AnimationClipReader.cs │ │ ├── SkinnedModelBasicEffectReader.cs │ │ ├── SkinnedModelBoneReader.cs │ │ ├── SkinnedModelMeshReader.cs │ │ └── SkinnedModelReader.cs │ ├── Pose.cs │ ├── Properties │ │ ├── AppManifest.xml │ │ ├── AssemblyInfo.cs │ │ └── WMAppManifest.xml │ ├── ReadOnlyDictionary.cs │ ├── SkinnedModel.cs │ ├── SkinnedModelBone.cs │ ├── SkinnedModelBoneCollection.cs │ ├── SkinnedModelBoneDictionary.cs │ ├── SkinnedModelMesh.cs │ ├── SkinnedModelMeshCollection.cs │ ├── XNAnimation (Windows Phone).csproj │ ├── XNAnimation (Xbox 360).csproj │ ├── XNAnimation.csproj │ ├── XNAnimation.snk │ ├── XNAnimationDiagram.cd │ ├── XNAnimationPhone.snk │ └── XNAnimationXbox.snk └── XNAnimationPipeline │ ├── AnimationChannelContent.cs │ ├── AnimationChannelContentDictionary.cs │ ├── AnimationClipContent.cs │ ├── AnimationClipContentDictionary.cs │ ├── AnimationKeyframeContent.cs │ ├── Effects │ └── SkinnedModelMaterialContent.cs │ ├── Pipeline │ ├── AnimationClipWriter.cs │ ├── AssemblyHelper.cs │ ├── PathType.cs │ ├── SkinnedModelBoneWriter.cs │ ├── SkinnedModelMaterialProcessor.cs │ ├── SkinnedModelMaterialWriter.cs │ ├── SkinnedModelMeshWriter.cs │ ├── SkinnedModelProcessor.cs │ └── SkinnedModelWriter.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Resources │ └── SkinnedModelEffect.txt │ ├── SkinnedModelBoneContent.cs │ ├── SkinnedModelBoneContentCollection.cs │ ├── SkinnedModelBoneContentDictionary.cs │ ├── SkinnedModelContent.cs │ ├── SkinnedModelMeshContent.cs │ ├── SkinnedModelMeshContentCollection.cs │ ├── XNAnimation.snk │ └── XNAnimationPipeline.csproj ├── asvo.sln └── asvo ├── BFSOctree.cs ├── Camera.cs ├── Content ├── asvoContent.contentproj ├── imrod_walk_high.fbx └── simple.fx ├── DynamicOctree.cs ├── Game.ico ├── Game1.cs ├── JobCenter.cs ├── Math3DHelper.cs ├── Object3d.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── Rasterizer.cs ├── SharedDepthBuffer.cs ├── TriangleMesh.cs └── asvo.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | *.bat 2 | *.cachefile 3 | *.dll 4 | *.pdb 5 | *.png 6 | *.shfb 7 | *.suo 8 | *.user 9 | *.vspscc 10 | *.vssscc 11 | 12 | /build 13 | 14 | /prototype/asvo/bin 15 | /prototype/asvo/Content/obj/ 16 | /prototype/asvo/obj/ 17 | 18 | /prototype/XNAnimation/XNAnimation/bin 19 | /prototype/XNAnimation/XNAnimation/obj 20 | /prototype/XNAnimation/XNAnimationPipeline/bin 21 | /prototype/XNAnimation/XNAnimationPipeline/obj 22 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug App", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/build/demo", 12 | "stopAtEntry": false, 13 | "cwd": "${workspaceFolder}/build", 14 | "externalConsole": false, 15 | "MIMode": "gdb", 16 | "setupCommands": [ 17 | { 18 | "description": "Enable pretty-printing for gdb", 19 | "text": "-enable-pretty-printing", 20 | "ignoreFailures": true 21 | } 22 | ] 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /BFSInnerNode.cpp: -------------------------------------------------------------------------------- 1 | #include "BFSInnerNode.h" 2 | 3 | void BFSInnerNode::deserialize( FILE * inFile ) 4 | { 5 | vd.deserialize( inFile ); 6 | 7 | fread( & mask, 4, 1, inFile ); 8 | fread( & childPtr, 4, 1, inFile ); 9 | } -------------------------------------------------------------------------------- /BFSInnerNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "VisualData.h" 6 | 7 | /** 8 | * Represents an inner node of a BFSOctree. 9 | */ 10 | class BFSInnerNode { 11 | public: 12 | VisualData vd; 13 | std::uint32_t mask; 14 | std::uint32_t childPtr; 15 | 16 | void deserialize(FILE* inFile); 17 | }; -------------------------------------------------------------------------------- /BFSJob.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct BFSJob 6 | { 7 | int index; 8 | short x; 9 | short y; 10 | short z; 11 | }; 12 | 13 | inline __host__ __device__ BFSJob make_BFSJob( int index, short x, short y, short z ) 14 | { 15 | BFSJob result = { index, x, y, z }; 16 | return result; 17 | } -------------------------------------------------------------------------------- /BFSOctree.cpp: -------------------------------------------------------------------------------- 1 | #include "BFSOctree.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "Glue.h" 8 | #include "float4x4.h" 9 | 10 | BFSOctree::BFSOctree() {} 11 | 12 | BFSOctree::BFSOctree(char const* model, char const* diffuse, char const* illum, 13 | char const* spec, char const* normal) 14 | : // TODO: Replace hard-coded values 15 | m_diffuse(diffuse, 1024, 1024), 16 | m_illum(illum, 1024, 1024), 17 | m_spec(spec, 1024, 1024), 18 | m_normal(normal, 1024, 1024) { 19 | FILE* file = fopen(model, "rb"); 20 | 21 | assert(file != nullptr); 22 | 23 | int innerNodeCount; 24 | int leafCount; 25 | 26 | fread(&m_dim, 4, 1, file); 27 | fread(&innerNodeCount, 4, 1, file); 28 | fread(&leafCount, 4, 1, file); 29 | 30 | thrust::host_vector innerNodes(innerNodeCount); 31 | thrust::host_vector leaves(leafCount); 32 | 33 | for (int i = 0; i < innerNodeCount; i++) { 34 | innerNodes[i].deserialize(file); 35 | } 36 | 37 | for (int i = 0; i < leafCount; i++) { 38 | leaves[i].deserialize(file); 39 | } 40 | 41 | fread(&m_frameCount, 4, 1, file); 42 | fread(&m_boneCount, 4, 1, file); 43 | 44 | thrust::host_vector animation(m_frameCount * m_boneCount); 45 | fread(&animation[0], sizeof(float4x4), m_frameCount * m_boneCount, file); 46 | 47 | fclose(file); 48 | 49 | m_currentFrame = 0.0; 50 | 51 | /* Copy data to device */ 52 | 53 | m_innerNodes = innerNodes; 54 | 55 | m_leaves = leaves; 56 | 57 | thrust::host_vector queue; 58 | for (std::uint32_t i = 0; i < 8; ++i) { 59 | queue.push_back( 60 | make_BFSJob(i + 1, i & 1ul, (i & 2ul) >> 1, (i & 4ul) >> 2)); 61 | } 62 | 63 | int level = 1, queueStart = 0, queueEnd = queue.size(); 64 | // TODO: Test for level == nLevels 65 | while ((queueEnd - queueStart) <= 512 || queueStart == queueEnd) { 66 | for (int i = queueStart; i < queueEnd; ++i) { 67 | BFSJob job = queue[i]; 68 | BFSInnerNode node = innerNodes[job.index]; 69 | unsigned char childIndex = 0; 70 | for (unsigned int j = 0; j < 8; ++j) { 71 | if ((node.mask & (1ul << j)) != 0) { 72 | queue.push_back(make_BFSJob( 73 | node.childPtr + childIndex, 2 * job.x + (j & 1u), 74 | 2 * job.y + ((j & 2u) >> 1), 2 * job.z + ((j & 4u) >> 2))); 75 | ++childIndex; 76 | } 77 | } 78 | } 79 | ++level; 80 | queueStart = queueEnd; 81 | queueEnd = queue.size(); 82 | } 83 | 84 | m_level = level; 85 | 86 | m_jobs.assign(queue.cbegin() + queueStart, queue.cbegin() + queueEnd); 87 | 88 | m_animation = animation; 89 | } 90 | 91 | int BFSOctree::update(double lastFrameTimeInMilliseconds) { 92 | m_currentFrame += lastFrameTimeInMilliseconds; 93 | return (int)(m_currentFrame * 0.06) % m_frameCount; 94 | } 95 | 96 | thrust::device_vector const& BFSOctree::innerNodes() const { 97 | return m_innerNodes; 98 | } 99 | 100 | thrust::device_vector const& BFSOctree::leaves() const { 101 | return m_leaves; 102 | } 103 | 104 | thrust::device_vector const& BFSOctree::jobs() const { return m_jobs; } 105 | 106 | thrust::device_vector const& BFSOctree::animation() const { 107 | return m_animation; 108 | } 109 | 110 | int BFSOctree::level() const { return m_level; } 111 | 112 | float BFSOctree::dim() const { return m_dim; } 113 | 114 | int BFSOctree::boneCount() const { return m_boneCount; } 115 | 116 | Texture const& BFSOctree::diffuse() const { return m_diffuse; } 117 | 118 | Texture const& BFSOctree::illum() const { return m_illum; } 119 | 120 | Texture const& BFSOctree::spec() const { return m_spec; } 121 | 122 | Texture const& BFSOctree::normal() const { return m_normal; } -------------------------------------------------------------------------------- /BFSOctree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "BFSInnerNode.h" 8 | #include "BFSJob.h" 9 | #include "Texture.h" 10 | #include "float4x4.h" 11 | 12 | 13 | class BFSOctree { 14 | public: 15 | BFSOctree(); 16 | 17 | BFSOctree(char const* model, char const* diffuse, char const* illum, 18 | char const* spec, char const* normal); 19 | 20 | /* Updates the character animation */ 21 | int update(double lastFrameTimeInMilliseconds); 22 | 23 | thrust::device_vector const& innerNodes() const; 24 | thrust::device_vector const& leaves() const; 25 | thrust::device_vector const& jobs() const; 26 | thrust::device_vector const& animation() const; 27 | 28 | int level() const; 29 | float dim() const; 30 | int boneCount() const; 31 | 32 | Texture const& diffuse() const; 33 | Texture const& illum() const; 34 | Texture const& spec() const; 35 | Texture const& normal() const; 36 | 37 | private: 38 | thrust::device_vector m_innerNodes; 39 | thrust::device_vector m_leaves; 40 | thrust::device_vector m_jobs; 41 | thrust::device_vector m_animation; 42 | 43 | unsigned char m_level; 44 | float m_dim; 45 | /* #frames of the character animation */ 46 | int m_boneCount; 47 | std::uint32_t m_frameCount; 48 | double m_currentFrame; 49 | 50 | Texture m_diffuse; 51 | Texture m_illum; 52 | Texture m_spec; 53 | Texture m_normal; 54 | }; -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | 3 | project(asvo_cuda LANGUAGES CXX CUDA) 4 | 5 | file(GLOB headers "*.h") 6 | file(GLOB sources "*.cpp" "*.cu") 7 | 8 | if(MSVC) 9 | source_group("Header Files" FILES ${headers}) 10 | source_group("Source Files" FILES ${sources}) 11 | endif() 12 | 13 | add_executable(demo ${headers} ${sources}) 14 | set_property(TARGET demo PROPERTY CXX_STANDARD 14) 15 | set_property(TARGET demo PROPERTY CUDA_ARCHITECTURES 50) 16 | 17 | find_package(OpenGL REQUIRED) 18 | find_package(GLUT REQUIRED) 19 | find_package(GLEW REQUIRED) 20 | target_include_directories(demo PRIVATE ${GLEW_INCLUDE_DIRS} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 21 | target_link_libraries(demo PRIVATE OpenGL::GL GLUT::GLUT ${GLEW_LIBRARIES}) -------------------------------------------------------------------------------- /Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "extended_helper_math.h" 10 | #include "float4x4.h" 11 | #include "Glue.h" 12 | 13 | 14 | 15 | Camera::Camera 16 | ( 17 | float3 const & position, float3 const & lookAt, 18 | float fov, float aspectRatio, 19 | float nearPlane, float farPlane 20 | ) : 21 | m_position( position ), 22 | m_lookAt( lookAt ), 23 | 24 | m_startX( 0 ), 25 | m_startY( 0 ), 26 | m_startZ( 0 ), 27 | m_endX( 0 ), 28 | m_endY( 0 ), 29 | m_endZ( 0 ), 30 | 31 | m_button1Down( false ), 32 | m_button2Down( false ) 33 | { 34 | m_projectionMatrix = make_perspective( fov, aspectRatio, nearPlane, farPlane ); 35 | } 36 | 37 | Camera::Camera 38 | ( 39 | float3 const & position, float3 const & lookAt, 40 | float4x4 projectionMatrix 41 | ) : 42 | m_position( position ), 43 | m_lookAt( lookAt ), 44 | 45 | m_projectionMatrix( projectionMatrix ), 46 | 47 | m_startX( 0 ), 48 | m_startY( 0 ), 49 | m_startZ( 0 ), 50 | m_endX( 0 ), 51 | m_endY( 0 ), 52 | m_endZ( 0 ), 53 | 54 | m_button1Down( false ), 55 | m_button2Down( false ) 56 | { 57 | 58 | } 59 | 60 | 61 | 62 | float3 Camera::position() const 63 | { 64 | return m_position; 65 | } 66 | 67 | float4x4 Camera::viewMatrix() const 68 | { 69 | return make_lookat( m_position, m_lookAt, make_float3( 0, 1, 0 ) ); 70 | } 71 | 72 | float4x4 Camera::projectionMatrix() const 73 | { 74 | return m_projectionMatrix; 75 | } 76 | 77 | float4x4 Camera::viewProjectionMatrix() const 78 | { 79 | return viewMatrix() * projectionMatrix(); 80 | } 81 | 82 | 83 | 84 | void Camera::update 85 | ( 86 | double msLastFrameTime, 87 | int windowWidthInPixels, 88 | int windowHeightInPixels 89 | ) 90 | { 91 | if( m_button1Down ) 92 | { 93 | float4x4 horRot = make_rotation( 94 | make_float3( 0, 1, 0 ), 95 | -( ( m_endX - m_startX ) / ( (double) windowWidthInPixels ) ) * msLastFrameTime * 0.01 96 | ); 97 | float4x4 vertRot = make_rotation( 98 | normalize( cross( normalize( m_lookAt - m_position ), make_float3( 0, 1, 0 ) ) ), 99 | ( ( m_endY - m_startY ) / ( (double) windowHeightInPixels ) ) * msLastFrameTime * 0.01 100 | ); 101 | m_position += m_lookAt; 102 | m_position = m_position * horRot; 103 | m_position = m_position * vertRot; 104 | m_position -= m_lookAt; 105 | } 106 | else if( m_button2Down ) 107 | { 108 | m_position -= m_lookAt; 109 | m_position += m_position * ( ( m_endZ - m_startZ ) / ( (float) windowHeightInPixels ) ) * msLastFrameTime * 0.01; 110 | m_position += m_lookAt; 111 | } 112 | } 113 | 114 | 115 | 116 | void Camera::handleMouseButtonPress( int button, int state, int x, int y ) 117 | { 118 | if( button == GLUT_LEFT_BUTTON ) 119 | { 120 | if( state == GLUT_DOWN ) 121 | { 122 | m_button1Down = true; 123 | m_startX = m_endX = x; 124 | m_startY = m_endY = y; 125 | } 126 | else if( state == GLUT_UP ) 127 | { 128 | m_button1Down = false; 129 | m_startX = m_endX; 130 | m_startY = m_endY; 131 | } 132 | } 133 | 134 | if( button == GLUT_RIGHT_BUTTON ) 135 | { 136 | if( state == GLUT_DOWN ) 137 | { 138 | m_button2Down = true; 139 | m_startZ = m_endZ = y; 140 | } 141 | else if( state == GLUT_UP ) 142 | { 143 | m_button2Down = false; 144 | m_startZ = m_endZ; 145 | } 146 | } 147 | } 148 | 149 | void Camera::handleMouseMovement( int newX, int newY ) 150 | { 151 | if( m_button1Down ) 152 | { 153 | m_endX = newX; 154 | m_endY = newY; 155 | } 156 | else if( m_button2Down ) 157 | { 158 | m_endZ = newY; 159 | } 160 | } -------------------------------------------------------------------------------- /Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "float4x4.h" 8 | 9 | class Camera 10 | { 11 | public: 12 | 13 | Camera 14 | ( 15 | float3 const & position, float3 const & lookAt, 16 | float fov, float aspectRatio, 17 | float nearPlane, float farPlane 18 | ); 19 | 20 | // HACK for Light::camera() 21 | // TODO: Improve design 22 | Camera 23 | ( 24 | float3 const & position, float3 const & lookAt, 25 | float4x4 projectionMatrix 26 | ); 27 | 28 | float3 position() const; 29 | float4x4 viewMatrix() const; 30 | float4x4 projectionMatrix() const; 31 | float4x4 viewProjectionMatrix() const; 32 | 33 | void update 34 | ( 35 | double msLastFrameTime, 36 | int windowWidthInPixels, 37 | int windowHeightInPixels 38 | ); 39 | 40 | void handleMouseButtonPress( int button, int state, int x, int y ); 41 | void handleMouseMovement( int newX, int newY ); 42 | 43 | private: 44 | 45 | float3 m_position; 46 | float3 m_lookAt; 47 | 48 | float4x4 m_projectionMatrix; 49 | 50 | // For handling GLUT events: 51 | int m_startX; 52 | int m_startY; 53 | int m_startZ; 54 | int m_endX; 55 | int m_endY; 56 | int m_endZ; 57 | 58 | bool m_button1Down; 59 | bool m_button2Down; 60 | }; -------------------------------------------------------------------------------- /Glue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The majority of this code is copied from Rob Farber's article 3 | "CUDA, Supercomputing for the Masses" 4 | (http://www.drdobbs.com/parallel/cuda-supercomputing-for-the-masses-part/207200659) 5 | */ 6 | 7 | #include "Glue.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "Light.h" 17 | 18 | // HACK 19 | #undef NDEBUG // Release mode doesn't work otherwise :S ??? 20 | #include "Object3D.h" 21 | #include "Renderer.h" 22 | 23 | // static 24 | Glue* Glue::m_globalInstance = nullptr; 25 | 26 | // static 27 | bool Glue::init(int argc, char** argv, int windowWidth, int windowHeight, 28 | Renderer* renderer, Object3D* model, Light light, 29 | Camera camera) { 30 | // preconds 31 | assert(windowWidth > 0); 32 | assert(windowHeight > 0); 33 | assert(renderer != nullptr); 34 | assert(model != nullptr); 35 | 36 | bool result = false; 37 | 38 | if (nullptr == m_globalInstance) { 39 | m_globalInstance = new Glue(argc, argv, windowWidth, windowHeight, renderer, 40 | model, light, camera, 41 | 42 | result); 43 | } 44 | 45 | return result; 46 | } 47 | 48 | // static 49 | void Glue::cleanUp() { 50 | if (m_globalInstance != nullptr) { 51 | delete m_globalInstance; 52 | } 53 | } 54 | 55 | // static 56 | void Glue::startGlutMainLoop() { glutMainLoop(); } 57 | 58 | Glue::Glue(int argc, char** argv, int windowWidth, int windowHeight, 59 | Renderer* renderer, Object3D* model, Light light, Camera camera, 60 | 61 | bool& outSuccess) 62 | : m_windowWidth(windowWidth), 63 | m_windowHeight(windowHeight), 64 | m_renderer(renderer), 65 | m_model(model), 66 | m_light(light), 67 | m_camera(camera), 68 | m_lastFrameTimeInMilliseconds(0) { 69 | // Initialize freeglut and OpenGL 70 | glutInit(&argc, argv); 71 | glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 72 | glutInitWindowSize(windowWidth, windowHeight); 73 | glutInitWindowPosition(50, 50); 74 | glutCreateWindow("asvo@cuda"); 75 | glutDisplayFunc(displayFunc); 76 | glutMouseFunc(mouseFunc); 77 | glutMotionFunc(motionFunc); 78 | 79 | glewInit(); 80 | if (!glewIsSupported("GL_VERSION_2_0")) { 81 | fprintf(stderr, "ERROR: Support for necessary OpenGL extensions missing."); 82 | outSuccess = false; 83 | return; 84 | } 85 | 86 | // Initialize CUDA 87 | cudaGLSetGLDevice(0); 88 | 89 | glViewport(0, 0, windowWidth, windowHeight); 90 | glClearColor(1, 1, 1, 0); 91 | glDisable(GL_DEPTH_TEST); 92 | 93 | glMatrixMode(GL_MODELVIEW); 94 | glLoadIdentity(); 95 | 96 | glMatrixMode(GL_PROJECTION); 97 | glLoadIdentity(); 98 | 99 | glOrtho(0, 1, 0, 1, 0, 1); 100 | 101 | // Create PBO 102 | glGenBuffers(1, &m_pbo); 103 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo); 104 | glBufferData(GL_PIXEL_UNPACK_BUFFER, windowResolution() * 4 * sizeof(GLubyte), 105 | nullptr, GL_DYNAMIC_COPY); 106 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 107 | 108 | assert(cudaSuccess == 109 | cudaGraphicsGLRegisterBuffer(&m_cuda_pbo_resource, m_pbo, 110 | cudaGraphicsMapFlagsWriteDiscard)); 111 | 112 | // Create texture to render into and display on the screen 113 | glEnable(GL_TEXTURE_2D); 114 | glGenTextures(1, &m_texture); 115 | glBindTexture(GL_TEXTURE_2D, m_texture); 116 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, windowWidth, windowHeight, 0, 117 | GL_BGRA, GL_UNSIGNED_BYTE, nullptr); 118 | // !!! 119 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 120 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 121 | 122 | outSuccess = true; 123 | } 124 | 125 | Glue::~Glue() { 126 | // delete pbo 127 | glBindBuffer(GL_ARRAY_BUFFER, m_pbo); 128 | glDeleteBuffers(1, &m_pbo); 129 | cudaGLUnregisterBufferObject(m_pbo); 130 | 131 | // delete texture 132 | glDeleteTextures(1, &m_texture); 133 | } 134 | 135 | // static 136 | void Glue::displayFunc() { m_globalInstance->display(); } 137 | 138 | void Glue::display() { 139 | uchar4* dptr = nullptr; 140 | 141 | m_camera.update(m_lastFrameTimeInMilliseconds, m_windowWidth, m_windowHeight); 142 | 143 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 144 | assert(cudaSuccess == cudaGraphicsMapResources(1, &m_cuda_pbo_resource, 0)); 145 | std::size_t size; 146 | assert(cudaSuccess == cudaGraphicsResourceGetMappedPointer( 147 | (void**)&dptr, &size, m_cuda_pbo_resource)); 148 | assert(size == windowResolution() * 4); 149 | int animationFrameIndex = m_model->data()->update(16.6f); 150 | auto t0 = std::chrono::high_resolution_clock::now(); 151 | m_renderer->render(*m_model, m_camera, m_light, animationFrameIndex, dptr); 152 | auto t1 = std::chrono::high_resolution_clock::now(); 153 | 154 | assert(cudaSuccess == cudaGraphicsUnmapResources(1, &m_cuda_pbo_resource, 0)); 155 | 156 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo); 157 | glBindTexture(GL_TEXTURE_2D, m_texture); 158 | 159 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_windowWidth, m_windowHeight, 160 | GL_RGBA, GL_UNSIGNED_BYTE, nullptr); 161 | 162 | glBegin(GL_QUADS); 163 | glTexCoord2f(0, 1); 164 | glVertex3f(0, 0, 0); 165 | glTexCoord2f(0, 0); 166 | glVertex3f(0, 1, 0); 167 | glTexCoord2f(1, 0); 168 | glVertex3f(1, 1, 0); 169 | glTexCoord2f(1, 1); 170 | glVertex3f(1, 0, 0); 171 | glEnd(); 172 | 173 | glutSwapBuffers(); 174 | glutPostRedisplay(); 175 | 176 | m_lastFrameTimeInMilliseconds = 177 | std::chrono::duration(t1 - t0).count() * 1000.0; 178 | 179 | char title[64]; 180 | sprintf(title, "asvo@cuda - %.1f fps", 181 | 1000.0 / m_lastFrameTimeInMilliseconds); 182 | glutSetWindowTitle(title); 183 | } 184 | 185 | // static 186 | void Glue::mouseFunc(int button, int state, int x, int y) { 187 | m_globalInstance->m_camera.handleMouseButtonPress(button, state, x, y); 188 | } 189 | 190 | // static 191 | void Glue::motionFunc(int newX, int newY) { 192 | m_globalInstance->m_camera.handleMouseMovement(newX, newY); 193 | } 194 | 195 | int Glue::windowResolution() const { return m_windowWidth * m_windowHeight; } 196 | 197 | double Glue::windowAspectRatio() const { 198 | return ((double)m_windowWidth / m_windowHeight); 199 | } -------------------------------------------------------------------------------- /Glue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | // prevent clang-format from re-ordering these two includes 5 | #include 6 | 7 | #include 8 | 9 | #include "Camera.h" 10 | #include "Light.h" 11 | 12 | class Object3D; 13 | class Renderer; 14 | 15 | /* 16 | A thin wrapper around freeglut which covers initialization 17 | of the CUDA device, creation of textures, render targets, 18 | setting up the view port, etc. 19 | */ 20 | class Glue { 21 | public: 22 | /* 23 | Initializes freeglut, OpenGL and CUDA and sets everything up 24 | for rendering (textures, render targets, etc.) 25 | @param renderer takes ownership of the pointer 26 | @param model takes ownership of the pointer 27 | 28 | @return true if the initialization was successful, 29 | false otherwise (in this case the app should be aborted) 30 | 31 | @precond windowWidth > 0 32 | @precond windowHeight > 0 33 | @precond renderer != nullptr 34 | @precond model != nullptr 35 | */ 36 | static bool init(int argc, char** argv, int windowWidth, int windowHeight, 37 | Renderer* renderer, Object3D* model, Light light, 38 | Camera camera); 39 | /* 40 | Cleans up all initialized resources. 41 | */ 42 | static void cleanUp(); 43 | 44 | static void startGlutMainLoop(); 45 | 46 | private: 47 | static Glue* m_globalInstance; 48 | 49 | Glue(int argc, char** argv, int windowWidth, int windowHeight, 50 | Renderer* renderer, Object3D* model, Light light, Camera camera, 51 | 52 | bool& outSuccess); 53 | ~Glue(); 54 | 55 | /* 56 | Registered as glutDisplayFunc. 57 | Calls display. 58 | If called without a preceding call to setGlobalInstance, the 59 | behavior is undefined! 60 | */ 61 | static void displayFunc(); 62 | /* 63 | Main render function. Binds buffers and calls Renderer::render 64 | */ 65 | void display(); 66 | 67 | /* 68 | Registered as glutMouseFunc. 69 | Calls Camera::handleMouseButtonPress 70 | */ 71 | static void mouseFunc(int button, int state, int x, int y); 72 | /* 73 | Registered as glutMotionFunc. 74 | Calls Camera::handleMouseMovement 75 | */ 76 | static void motionFunc(int newX, int newY); 77 | 78 | int m_windowWidth; 79 | int m_windowHeight; 80 | 81 | std::unique_ptr m_renderer; 82 | std::unique_ptr m_model; 83 | 84 | Light m_light; 85 | Camera m_camera; 86 | 87 | GLuint m_pbo; 88 | struct cudaGraphicsResource* m_cuda_pbo_resource; 89 | GLuint m_texture; 90 | 91 | double m_lastFrameTimeInMilliseconds; 92 | 93 | int windowResolution() const; 94 | // windowWidth() / windowHeight() 95 | double windowAspectRatio() const; 96 | }; -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | Copyright © 2011 Dennis Bautembach 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Light.cpp: -------------------------------------------------------------------------------- 1 | #include "Light.h" 2 | 3 | #include "extended_helper_math.h" 4 | 5 | Light::Light( float3 position, float diffusePower ) : 6 | m_direction( normalize( -position ) ), 7 | m_diffusePower( diffusePower ) 8 | { 9 | 10 | } 11 | 12 | 13 | 14 | float3 Light::direction() const 15 | { 16 | return m_direction; 17 | } 18 | 19 | 20 | 21 | float Light::diffusePower() const 22 | { 23 | return m_diffusePower; 24 | } 25 | 26 | float Light::ambientPower() const 27 | { 28 | return 1.0f - m_diffusePower; 29 | } 30 | 31 | 32 | 33 | Camera Light::camera() const 34 | { 35 | return Camera 36 | ( 37 | m_direction * 50.0f, 38 | make_float3( 0, 0, 0 ), 39 | make_orthographic( 100, 100, 10.f, 200.f ) 40 | ); 41 | } -------------------------------------------------------------------------------- /Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Camera.h" 6 | 7 | class Light 8 | { 9 | public: 10 | 11 | // Creates a directional light at position looking at the origin 12 | Light( float3 position, float diffusePower ); 13 | 14 | float3 direction() const; 15 | 16 | float diffusePower() const; 17 | float ambientPower() const; 18 | 19 | // Returns a camera which is equivalent to the 20 | // light's frustum 21 | Camera camera() const; 22 | 23 | private: 24 | 25 | float3 m_direction; 26 | float m_diffusePower; 27 | }; -------------------------------------------------------------------------------- /Object3D.cpp: -------------------------------------------------------------------------------- 1 | #include "Object3D.h" 2 | 3 | #include 4 | 5 | #include "extended_helper_math.h" 6 | 7 | Object3D::Object3D() 8 | { 9 | 10 | } 11 | 12 | Object3D::Object3D( BFSOctree * data, bool rhsCoordianteSystem ) : 13 | m_data( data ), 14 | m_rhsCoordSystem( rhsCoordianteSystem ) 15 | { 16 | m_transform = make_identity(); 17 | if( rhsCoordianteSystem ) 18 | { 19 | m_transform.m33 = -1; 20 | } 21 | } 22 | 23 | 24 | 25 | void Object3D::assignTransform( float4x4 const & transform ) 26 | { 27 | float4x4 mul = make_identity(); 28 | 29 | if( m_rhsCoordSystem ) 30 | { 31 | mul.m33 = -1.f; 32 | } 33 | 34 | m_transform = ( mul * transform ); 35 | } 36 | 37 | 38 | 39 | BFSOctree const * Object3D::data() const 40 | { 41 | return m_data.get(); 42 | } 43 | 44 | BFSOctree * Object3D::data() 45 | { 46 | return m_data.get(); 47 | } 48 | 49 | float4x4 const & Object3D::transform() const 50 | { 51 | return m_transform; 52 | } -------------------------------------------------------------------------------- /Object3D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "BFSOctree.h" 6 | #include "float4x4.h" 7 | 8 | /** 9 | * Encapsulates the raw data representation of a 3D object (the BFSOctree) 10 | * in a model that is easier to handle. It provides basic transformation. 11 | */ 12 | class Object3D 13 | { 14 | public: 15 | 16 | Object3D(); 17 | Object3D( BFSOctree * data, bool rhsCoordianteSystem ); 18 | 19 | void assignTransform( float4x4 const & transform ); 20 | 21 | BFSOctree const * data() const; 22 | BFSOctree * data(); 23 | float4x4 const & transform() const; 24 | 25 | private: 26 | 27 | std::shared_ptr< BFSOctree > m_data; 28 | float4x4 m_transform; 29 | bool m_rhsCoordSystem; 30 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Animated Sparse Voxel Octrees @ CUDA 2 | 3 | 4 | ## Introduction 5 | 6 | Animated Sparse Voxel Octrees (ASVO) is an animation technique for sparse voxel octrees. It allows you to apply rigid transformations or skinning to voxel based 3D models. 7 | 8 | You can find more detailed information on the [project page](http://bautembach.de/wordpress/?page_id=7). 9 | 10 | The project is divided into two sub projects: The root directory contains the high performance CUDA/C++ implementation and can be build with CMake. The 'prototype' subfolder contains the XNA/C# prototype that was used for data structure and algorithm design. 11 | 12 | 13 | ## Dependencies 14 | 15 | ### CUDA/C++ high performance implementation 16 | - CMAKE 3.0.0 17 | - CUDA 7.5 18 | - CUDA capable GPU with Compute Capability 3.0 or higher, 1GB VRAM or more. 19 | - freeglut 3.0.0 or later 20 | - GLEW 1.12.0 or later 21 | 22 | ### XNA/C# prototype 23 | - [Microsoft XNA Game Studio 4.0](http://www.microsoft.com/en-gb/download/details.aspx?id=23714) 24 | - [XNAnimation Library](http://xnanimation.codeplex.com/): This project contains a ported version of XNAnimation 0.7.0.0 BETA 3 to support XNA 4.0. Please use this copy as it contains custom changes and ASVO won't work with the official version. 25 | 26 | 27 | ## Usage 28 | 29 | After launching the program you can rotate the camera by holding down the *left* mouse button and moving your mouse. Holding down the *right* mouse button and moving your mouse allows you to zoom in and out. 30 | 31 | 32 | ## Known Issues 33 | 34 | - NOT platform-independant: Code assumes that 'long' refers to 32bit integers. 35 | 36 | 37 | ## License 38 | 39 | - Author: Dennis Bautembach 40 | - ASVO: Creative Commons Attribution (CC BY 3.0): If you use any of the source code in your own code, please mention the original author's name in a comment or other appropriate place. ASVO itself uses code released under CC BY 3.0 and mentions the original authors in comments. Please maintain this information. 41 | - XNAnimation Library: Microsoft Public License (Ms-PL) -------------------------------------------------------------------------------- /Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "Camera.h" 7 | #include "Light.h" 8 | #include "Object3D.h" 9 | #include "VoxelData.h" 10 | 11 | class Renderer 12 | { 13 | public: 14 | 15 | Renderer( int frameWidthInPixels, int frameHeightInPixels, bool shadowMapping ); 16 | ~Renderer(); 17 | 18 | void render 19 | ( 20 | Object3D const & obj, 21 | Camera const & cam, 22 | Light const & light, 23 | int animationFrameIndex, 24 | 25 | uchar4 * outColorBuffer 26 | ); 27 | 28 | private: 29 | 30 | /* Prevent Renderer from being copied */ 31 | Renderer( Renderer const & copy ); 32 | Renderer & operator=( Renderer const & rhs ); 33 | 34 | static int const nTHREADS_TRAV_KERNEL = 128; 35 | static int const nTHREADS_DRAW_KERNEL = 128; 36 | static int const nTHREADS_DRAW_SHADOW_KERNEL = 192; 37 | 38 | int m_frameWidth; 39 | int m_frameHeight; 40 | bool m_shadowMapping; 41 | 42 | thrust::device_vector< BFSJob > m_dJobQueue; 43 | 44 | thrust::device_vector< unsigned int > m_dDepthBuffer; 45 | thrust::device_vector< VoxelData > m_dVoxelBuffer; 46 | thrust::device_vector< float > m_dShadowMap; 47 | 48 | cudaTextureObject_t m_tDepthBuffer; 49 | 50 | void rasterize 51 | ( 52 | Object3D const & obj, 53 | Camera const & cam, 54 | Light const & light, 55 | int animationFrameIndex, 56 | 57 | bool shadowPass, 58 | 59 | uchar4 * outColorBuffer 60 | ); 61 | 62 | void clearColorBuffer( uchar4 * dpOutColorBuffer ); 63 | void clearDepthBuffer(); 64 | void clearShadowMap(); 65 | void fillJobQueue( BFSJob const * dpJobs, int jobCount ); 66 | 67 | int resolution() const; 68 | 69 | /* Computes ceil( (double) nElements / nThreadsPerBlock ) */ 70 | static int nBlocks( int nElements, int nThreadsPerBlock ); 71 | }; -------------------------------------------------------------------------------- /Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "Texture.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | Texture::Texture() : m_pData(nullptr), m_width(0), m_height(0) {} 13 | 14 | Texture::Texture(char const* fileName, int width, int height) 15 | : m_pData(nullptr), m_width(width), m_height(height) { 16 | // TODO: Handle errors more gracefully 17 | if (fileName != nullptr) { 18 | int resolution = width * height; 19 | 20 | FILE* file; 21 | file = fopen(fileName, "rb"); 22 | 23 | assert(file != nullptr); 24 | 25 | std::vector hImgRGB(3 * resolution); 26 | 27 | fread(&hImgRGB[0], 1, 3 * resolution, file); 28 | fclose(file); 29 | 30 | std::vector hImgRGBA(resolution); 31 | for (int i = 0; i < resolution; ++i) { 32 | hImgRGBA[i] = make_uchar4(hImgRGB[3 * i], hImgRGB[3 * i + 1], 33 | hImgRGB[3 * i + 2], 255); 34 | } 35 | 36 | cudaChannelFormatDesc desc = cudaCreateChannelDesc(); 37 | cudaMallocArray(&m_pData, &desc, width, height); 38 | cudaMemcpyToArray(m_pData, 0, 0, &hImgRGBA[0], resolution * sizeof(uchar4), 39 | cudaMemcpyHostToDevice); 40 | 41 | initTexture(); 42 | } 43 | } 44 | 45 | Texture::Texture(Texture const& copy) : m_pData(nullptr) { copyFrom(copy); } 46 | 47 | Texture& Texture::operator=(Texture const& rhs) { 48 | copyFrom(rhs); 49 | 50 | return *this; 51 | } 52 | 53 | Texture::~Texture() { 54 | cudaDestroyTextureObject(m_texture); 55 | cudaFreeArray(m_pData); 56 | } 57 | 58 | int Texture::width() const { return m_width; } 59 | 60 | int Texture::height() const { return m_height; } 61 | 62 | cudaTextureObject_t const& Texture::textureObject() const { return m_texture; } 63 | 64 | void Texture::copyFrom(Texture const& other) { 65 | if (this == &other) { 66 | return; 67 | } 68 | 69 | m_width = other.width(); 70 | m_height = other.height(); 71 | int resolution = m_width * m_height; 72 | 73 | if (m_pData != nullptr) { 74 | cudaDestroyTextureObject(m_texture); 75 | cudaFreeArray(m_pData); 76 | } 77 | 78 | cudaChannelFormatDesc desc = cudaCreateChannelDesc(); 79 | cudaMallocArray(&m_pData, &desc, m_width, m_height); 80 | 81 | cudaMemcpyArrayToArray(m_pData, 0, 0, other.m_pData, 0, 0, 82 | resolution * sizeof(uchar4), cudaMemcpyDeviceToDevice); 83 | 84 | initTexture(); 85 | } 86 | 87 | void Texture::initTexture() { 88 | cudaResourceDesc resDesc; 89 | std::memset(&resDesc, 0, sizeof(resDesc)); 90 | 91 | resDesc.resType = cudaResourceTypeArray; 92 | resDesc.res.array.array = m_pData; 93 | 94 | cudaTextureDesc texDesc; 95 | std::memset(&texDesc, 0, sizeof(texDesc)); 96 | 97 | texDesc.addressMode[0] = cudaAddressModeWrap; 98 | texDesc.addressMode[1] = cudaAddressModeWrap; 99 | texDesc.filterMode = cudaFilterModeLinear; 100 | texDesc.normalizedCoords = true; 101 | texDesc.readMode = cudaReadModeNormalizedFloat; 102 | 103 | cudaCreateTextureObject(&m_texture, &resDesc, &texDesc, nullptr); 104 | } -------------------------------------------------------------------------------- /Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Texture 6 | { 7 | public: 8 | 9 | // Default constructor. Does not initialize the texture 10 | Texture(); 11 | /* 12 | * Loads a raw rgb image (3 bytes per pixel, encoded as r, g, b). 13 | */ 14 | Texture( char const * fileName, int widthInTexels, int heightInTexels ); 15 | Texture( Texture const & copy ); 16 | Texture & operator=( Texture const & rhs ); 17 | ~Texture(); 18 | 19 | int width() const; // in texels 20 | int height() const; // in texels 21 | 22 | cudaTextureObject_t const & textureObject() const; 23 | 24 | private: 25 | 26 | cudaArray * m_pData; 27 | cudaTextureObject_t m_texture; 28 | int m_width; 29 | int m_height; 30 | 31 | void copyFrom( Texture const & other ); 32 | void initTexture(); 33 | }; -------------------------------------------------------------------------------- /VisualData.cpp: -------------------------------------------------------------------------------- 1 | #include "VisualData.h" 2 | 3 | void VisualData::deserialize( FILE * inFile ) 4 | { 5 | fread( & normal, 12, 1, inFile ); 6 | fread( & tangent, 12, 1, inFile ); 7 | fread( & texCoord, 8, 1, inFile ); 8 | fread( & boneIndex0, 1, 1, inFile ); 9 | fread( & boneIndex1, 1, 1, inFile ); 10 | fread( & boneIndex2, 1, 1, inFile ); 11 | fread( & boneIndex3, 1, 1, inFile ); 12 | fread( & boneWeights, 16, 1, inFile ); 13 | } -------------------------------------------------------------------------------- /VisualData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | /** 8 | * Stores the visual data of a voxel. 9 | */ 10 | class VisualData 11 | { 12 | public: 13 | 14 | float3 normal; 15 | float3 tangent; 16 | float2 texCoord; 17 | unsigned char boneIndex0; 18 | unsigned char boneIndex1; 19 | unsigned char boneIndex2; 20 | unsigned char boneIndex3; 21 | float4 boneWeights; 22 | 23 | void deserialize( FILE * inFile ); 24 | }; -------------------------------------------------------------------------------- /VoxelData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /** 6 | * Stores all the neccessary data for drawing a 7 | * voxel. Used by the renderer. The equivalent in 8 | * OpenGL would be the input to the pixel/fragment shader. 9 | */ 10 | struct VoxelData 11 | { 12 | float3 normal; 13 | float3 tangent; 14 | float4 pos; 15 | float2 texCoord; 16 | float3 eyeVec; 17 | float3 center; 18 | }; -------------------------------------------------------------------------------- /content/diffuse.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/content/diffuse.raw -------------------------------------------------------------------------------- /content/illum.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/content/illum.raw -------------------------------------------------------------------------------- /content/imrod.asvo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/content/imrod.asvo -------------------------------------------------------------------------------- /content/normal.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/content/normal.raw -------------------------------------------------------------------------------- /content/spec.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/content/spec.raw -------------------------------------------------------------------------------- /extended_helper_math.h: -------------------------------------------------------------------------------- 1 | // Adding a few functions to CUDA's 'helper_math.h' 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "float4x4.h" 11 | 12 | inline __host__ __device__ float3 operator/(float3 v, float f) { 13 | return make_float3(v.x / f, v.y / f, v.z / f); 14 | } 15 | 16 | inline __host__ __device__ float3 operator*(float3 v, float f) { 17 | return make_float3(v.x * f, v.y * f, v.z * f); 18 | } 19 | 20 | inline __host__ __device__ float3 operator+(float3 a, float3 b) { 21 | return make_float3(a.x + b.x, a.y + b.y, a.z + b.z); 22 | } 23 | 24 | inline __host__ __device__ float3& operator+=(float3& a, float3 b) { 25 | a.x += b.x; 26 | a.y += b.y; 27 | a.z += b.z; 28 | 29 | return a; 30 | } 31 | 32 | inline __host__ __device__ float3 operator-(float3 a, float3 b) { 33 | return make_float3(a.x - b.x, a.y - b.y, a.z - b.z); 34 | } 35 | 36 | inline __host__ __device__ float3& operator-=(float3& a, float3 b) { 37 | a.x -= b.x; 38 | a.y -= b.y; 39 | a.z -= b.z; 40 | 41 | return a; 42 | } 43 | 44 | inline __host__ __device__ float3 operator-(float3 v) { 45 | return make_float3(-v.x, -v.y, -v.z); 46 | } 47 | 48 | inline __host__ __device__ float dot(float3 a, float3 b) { 49 | return a.x * b.x + a.y * b.y + a.z * b.z; 50 | } 51 | 52 | inline __host__ __device__ float length(float3 v) { return sqrtf(dot(v, v)); } 53 | 54 | inline __host__ __device__ float3 normalize(float3 v) { return v / length(v); } 55 | 56 | inline __host__ __device__ float3 lerp(float3 a, float3 b, float weightB) { 57 | return a + (b - a) * weightB; 58 | } 59 | 60 | inline __host__ __device__ float3 cross(float3 a, float3 b) { 61 | return make_float3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, 62 | a.x * b.y - a.y * b.x); 63 | } 64 | 65 | // row vector times matrix with homogenization 66 | inline __host__ __device__ float3 operator*(float3 v, float4x4 m) { 67 | float3 result = make_float3(v.x * m.m11 + v.y * m.m21 + v.z * m.m31 + m.m41, 68 | v.x * m.m12 + v.y * m.m22 + v.z * m.m32 + m.m42, 69 | v.x * m.m13 + v.y * m.m23 + v.z * m.m33 + m.m43); 70 | 71 | float w = v.x * m.m14 + v.y * m.m24 + v.z * m.m34 + m.m44; 72 | 73 | return result / w; 74 | } 75 | 76 | // TODO: Test effects of passing by reference 77 | inline __host__ __device__ float4x4 operator*(float4x4 m1, float4x4 m2) { 78 | float4x4 result = { 79 | m1.m11 * m2.m11 + m1.m12 * m2.m21 + m1.m13 * m2.m31 + m1.m14 * m2.m41, 80 | m1.m11 * m2.m12 + m1.m12 * m2.m22 + m1.m13 * m2.m32 + m1.m14 * m2.m42, 81 | m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13 * m2.m33 + m1.m14 * m2.m43, 82 | m1.m11 * m2.m14 + m1.m12 * m2.m24 + m1.m13 * m2.m34 + m1.m14 * m2.m44, 83 | 84 | m1.m21 * m2.m11 + m1.m22 * m2.m21 + m1.m23 * m2.m31 + m1.m24 * m2.m41, 85 | m1.m21 * m2.m12 + m1.m22 * m2.m22 + m1.m23 * m2.m32 + m1.m24 * m2.m42, 86 | m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23 * m2.m33 + m1.m24 * m2.m43, 87 | m1.m21 * m2.m14 + m1.m22 * m2.m24 + m1.m23 * m2.m34 + m1.m24 * m2.m44, 88 | 89 | m1.m31 * m2.m11 + m1.m32 * m2.m21 + m1.m33 * m2.m31 + m1.m34 * m2.m41, 90 | m1.m31 * m2.m12 + m1.m32 * m2.m22 + m1.m33 * m2.m32 + m1.m34 * m2.m42, 91 | m1.m31 * m2.m13 + m1.m32 * m2.m23 + m1.m33 * m2.m33 + m1.m34 * m2.m43, 92 | m1.m31 * m2.m14 + m1.m32 * m2.m24 + m1.m33 * m2.m34 + m1.m34 * m2.m44, 93 | 94 | m1.m41 * m2.m11 + m1.m42 * m2.m21 + m1.m43 * m2.m31 + m1.m44 * m2.m41, 95 | m1.m41 * m2.m12 + m1.m42 * m2.m22 + m1.m43 * m2.m32 + m1.m44 * m2.m42, 96 | m1.m41 * m2.m13 + m1.m42 * m2.m23 + m1.m43 * m2.m33 + m1.m44 * m2.m43, 97 | m1.m41 * m2.m14 + m1.m42 * m2.m24 + m1.m43 * m2.m34 + m1.m44 * m2.m44}; 98 | return result; 99 | } 100 | 101 | inline __host__ __device__ float4x4 make_identity() { 102 | float4x4 result = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; 103 | return result; 104 | } 105 | 106 | inline __host__ __device__ float4x4 make_translation(float3 vec) { 107 | float4x4 result = make_identity(); 108 | 109 | result.m41 = vec.x; 110 | result.m42 = vec.y; 111 | result.m43 = vec.z; 112 | 113 | return result; 114 | } 115 | 116 | inline __host__ __device__ float4x4 make_rotation(float3 axis, float angle) { 117 | const float sinAngle = sinf(-angle); 118 | const float cosAngle = cosf(-angle); 119 | const float oneMinusCosAngle = 1.f - cosAngle; 120 | 121 | const float xTimesY = axis.x * axis.y; 122 | const float xTimesZ = axis.x * axis.z; 123 | const float yTimesZ = axis.y * axis.z; 124 | 125 | const float xTimesSin = axis.x * sinAngle; 126 | const float yTimesSin = axis.y * sinAngle; 127 | const float zTimesSin = axis.z * sinAngle; 128 | 129 | float4x4 result = {axis.x * axis.x * oneMinusCosAngle + cosAngle, 130 | xTimesY * oneMinusCosAngle - zTimesSin, 131 | xTimesZ * oneMinusCosAngle + yTimesSin, 132 | 0.f, 133 | 134 | xTimesY * oneMinusCosAngle + zTimesSin, 135 | axis.y * axis.y * oneMinusCosAngle + cosAngle, 136 | yTimesZ * oneMinusCosAngle - xTimesSin, 137 | 0.f, 138 | 139 | xTimesZ * oneMinusCosAngle - yTimesSin, 140 | yTimesZ * oneMinusCosAngle + xTimesSin, 141 | axis.z * axis.z * oneMinusCosAngle + cosAngle, 142 | 0.f, 143 | 144 | 0.f, 145 | 0.f, 146 | 0.f, 147 | 1.f}; 148 | return result; 149 | } 150 | 151 | inline __host__ __device__ float4x4 make_lookat(float3 pos, float3 lookAt, 152 | float3 up) { 153 | float3 zAxis = normalize(lookAt - pos); 154 | 155 | float3 xAxis = normalize(cross(up, zAxis)); 156 | 157 | float3 yAxis = normalize(cross(zAxis, xAxis)); 158 | 159 | float4x4 axes = {xAxis.x, yAxis.x, zAxis.x, 0.f, xAxis.y, yAxis.y, 160 | zAxis.y, 0.f, xAxis.z, yAxis.z, zAxis.z, 0.f, 161 | 0.f, 0.f, 0.f, 1.f}; 162 | 163 | return make_translation(-pos) * axes; 164 | } 165 | 166 | inline __host__ __device__ float4x4 make_orthographic(float width, float height, 167 | float nearPlane, 168 | float farPlane) { 169 | float oneThroughFMinusN = 1.0f / (farPlane - nearPlane); 170 | 171 | float4x4 result = {2.0f / width, 172 | 0.0f, 173 | 0.0f, 174 | 0.0f, 175 | 0.0f, 176 | 2.0f / height, 177 | 0.0f, 178 | 0.0f, 179 | 0.0f, 180 | 0.0f, 181 | oneThroughFMinusN, 182 | 0.0f, 183 | 0.0f, 184 | 0.0f, 185 | -nearPlane * oneThroughFMinusN, 186 | 1.0f}; 187 | 188 | return result; 189 | } 190 | 191 | inline __host__ __device__ float4x4 make_perspective(float fov, float ratio, 192 | float nearPlane, 193 | float farPlane) { 194 | float cotAlpha2 = 1.f / tan(fov * .5f); 195 | 196 | float fThroughFMinusN = farPlane / (farPlane - nearPlane); 197 | 198 | float4x4 result = {cotAlpha2 / ratio, 199 | 0.f, 200 | 0.f, 201 | 0.f, 202 | 0.f, 203 | cotAlpha2, 204 | 0.f, 205 | 0.f, 206 | 0.f, 207 | 0.f, 208 | fThroughFMinusN, 209 | 1.f, 210 | 0.f, 211 | 0.f, 212 | -fThroughFMinusN * nearPlane, 213 | 0.f}; 214 | 215 | return result; 216 | } -------------------------------------------------------------------------------- /float4x4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct __align__( 16 ) float4x4 4 | { 5 | // row x column 6 | float 7 | m11, m12, m13, m14, 8 | m21, m22, m23, m24, 9 | m31, m32, m33, m34, 10 | m41, m42, m43, m44; 11 | }; -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "Glue.h" 8 | #include "Light.h" 9 | #include "Object3D.h" 10 | #include "Renderer.h" 11 | #include "extended_helper_math.h" 12 | 13 | int main(int argc, char **argv) { 14 | // TODO @user: Replace hard-coded values 15 | int const frameWidthInPixels = 550; 16 | int const frameHeightInPixels = 800; 17 | double const aspectRatio = ((double)frameWidthInPixels) / frameHeightInPixels; 18 | bool const shadowMapping = true; 19 | 20 | // Set up the renderer 21 | auto renderer = 22 | new Renderer(frameWidthInPixels, frameHeightInPixels, shadowMapping); 23 | 24 | // Load an asvo from file. 25 | std::string path(argv[0]); 26 | int lastSlash = path.find_last_of("\\"); 27 | path.resize(lastSlash + 1); 28 | path.append("../content/"); 29 | 30 | auto model = new Object3D( 31 | new BFSOctree((path + "imrod.asvo").c_str(), 32 | (path + "diffuse.raw").c_str(), 33 | (path + "illum.raw").c_str(), (path + "spec.raw").c_str(), 34 | (path + "normal.raw").c_str()), 35 | true); 36 | float3 rotAxis = make_float3(1.f, 0.f, 0.f); 37 | model->assignTransform(make_rotation(rotAxis, -1.5707f)); 38 | 39 | // Set up the light. 40 | float3 lightPosition = make_float3(-1.f, -0.5f, 0.5f); 41 | float lightDiffusePower = 0.8; 42 | Light light(lightPosition, lightDiffusePower); 43 | 44 | // Set up the camera. 45 | float3 position = make_float3(0.f, 25.f, -100.f); 46 | float3 lookAt = make_float3(0.f, 0.f, 0.f); 47 | float fov = 1; 48 | Camera camera(position, lookAt, fov, aspectRatio, 10, 200); 49 | 50 | // Initialize the GLUT framework. 51 | if (!Glue::init(argc, argv, frameWidthInPixels, frameHeightInPixels, renderer, 52 | model, light, camera)) { 53 | return 1; 54 | } 55 | 56 | // Start the main render-and-update loop 57 | Glue::startGlutMainLoop(); 58 | 59 | Glue::cleanUp(); 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | VERSION 0.7.0.0 BETA 3 - CHANGELOG (02/05/2010) 2 | XNAnimation: 3 | - AnimationController: Added GetBoneAbsoluteTransform 4 | - AnimationController: Added per bone rotation controllers 5 | - SkinnedModelBoneCollection: Added bone name indexer/getboneid 6 | 7 | 8 | VERSION 0.7.0.0 BETA2 - CHANGELOG (06/30/2008) 9 | XNAnimation: 10 | - SkinnedModelBasicEffect: Completely rewritten using shader models 2_0 and 2_B for better compatible. 11 | - SkinnedModelBasicEffect: Point lights are now simpler (only color and position). 12 | - SkinnedModelBasicEffect: Added supports for just one light source. 13 | 14 | VERSION 0.7.0.0 BETA - CHANGELOG (06/30/2008) 15 | General: 16 | - Improved documentation 17 | - Changed skinned model processor name to "Model - XNAnimation" 18 | - Changed skinned model effect processor name to "Model Material - XNAnimation" 19 | - Skinned model effect processor is now hided 20 | 21 | XNAnimation: 22 | - AnimationController: Faster animation update using binary keyframe search 23 | - AnimationController: (bug fixed) Keyframe scale is now correct handled 24 | - AnimationController: Removing exception generate while updating an animation controller before any 25 | animation clip has started 26 | - AnimationController: (bug fixed) Loads the model's skeleton bind pose when a controller is created 27 | - SkinnedModelEffect: Improved number of supported bones from 58 to 80 (thanks to Jon Watte) 28 | - SkinnedModelEffect: (bug fixed) Properly handles translation on world transformation (thanks bryanedds) 29 | - SkinnedModelEffect: Reports vertex and pixel shader profile 30 | - SkinnedModelEffect: Added Normal Mapping support 31 | - SkinnedModelEffect: Added Specular Mapping support 32 | - Pose: Implements IEquatable, and == and != operators 33 | 34 | XNAnimationPipeline: 35 | - SkinnedModelProcessor: Added "Split Animation Filename". Uses an XML file to split the model's animations. 36 | - SkinnedModelProcessor: Added "Generate Tangent Frame". Generate tangent and binormal vectors for each vertex. 37 | - SkinnedModelProcessor: Added "Change Texture Path". Changes the path of all textures. 38 | - SkinnedModelProcessor: Added "Change Texture Path Type". Sets if the new texture path is absolute or relative. 39 | - SkinnedModelProcessor: Added "Model Rotation". Rotates the model over the Y,X,Z axes. 40 | - SkinnedModelProcessor: Added "Model Scaling". Scales the model. 41 | - SkinnedModelProcessor: Added ".Dump Hierarchy". (DEBUG) Dumps the model hierarchy 42 | - SkinnedModelProcessor: Added ".Dump Animations". (DEBuG) Dumps de model animations 43 | - SkinnedModelProcessor: "Bake Mesh Transforms" default is now TRUE 44 | - SkinnedModelProcessor: Skips invalid animations inside the model's skeleton 45 | - SkinnedModelProcessor: Skips invalid skeleton nodes inside the model's skeleton 46 | - SkinnedModelProcessor: Skips animation channels that does not affet the model's skeleton 47 | - SkinnedModelProcessor: Warning when processing a mesh child of a bone 48 | - SkinnedModelProcessor: Warning when processing a model without animations 49 | - SkinnedModelProcessor: Throws an exception when processing a geometry without material 50 | - SkinnedModelProcessor: Throws an exception when processing a geometry without blend weights channel 51 | - SkinnedModelProcessor: Throws an exception when the model's skeleton has more than 80 bones 52 | - SkinnedModelProcessor: Throws an exception when the model does not has a skeleton 53 | - SkinnedModelMaterialProcessor: Reads materials properties from the model's materials 54 | - SkinnedModelMaterialProcessor: Reads materials maps from the model's materials using pre-defined keys 55 | 56 | 57 | ------------------------------------------------------------------------------------ 58 | 59 | VERSION 0.3.0.0 - CHANGELOG (05/26/2008) 60 | - Keyframe data (translation, orientation, and scale) is now stored decomposed for better 61 | interpolation and low memory footprint. 62 | - Keyframe data (translation, orientation and scale) can be interpolated separately now. 63 | - Added cubic and spherical keyframe interpolation. 64 | - Added cross fade blending between animation clips. Allows smooth transitions between animations. 65 | - Added support for the Xbox 360. 66 | - Preliminary documentation released. 67 | - New sample for Windows and Xbox released. -------------------------------------------------------------------------------- /prototype/XNAnimation/Documentation.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/Documentation.txt -------------------------------------------------------------------------------- /prototype/XNAnimation/FAQ.txt: -------------------------------------------------------------------------------- 1 | - Error normalizing vertex bone weights. BoneWeightCollection does not contain any weighting values. 2 | - Clean all the solution. Close and open it. 3 | 4 | - Quais formatos de arquivos sao suportados? 5 | - Como exportar meu modelo 6 | - Como usar a biblioteca? 7 | - Ela [e suportada no xbox e windows? -------------------------------------------------------------------------------- /prototype/XNAnimation/TODO.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/TODO.txt -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/AnimationChannel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationChannel.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Collections.ObjectModel; 18 | 19 | namespace XNAnimation 20 | { 21 | public class AnimationChannel : ReadOnlyCollection 22 | { 23 | internal AnimationChannel(IList list) 24 | : base(list) 25 | { 26 | } 27 | 28 | /// 29 | /// Return the nearest keyframe for the given time 30 | /// 31 | /// 32 | /// 33 | public int GetKeyframeIndexByTime(TimeSpan time) 34 | { 35 | if (Count == 0) 36 | throw new InvalidOperationException("empty channel"); 37 | 38 | /* 39 | int keyframeIndex = 0; 40 | while (keyframeIndex < Count && Items[keyframeIndex].Time <= time) 41 | keyframeIndex++; 42 | 43 | keyframeIndex--; 44 | */ 45 | 46 | int keyframeIndex = 0; 47 | int startIndex = 0; 48 | int endIndex = Items.Count - 1; 49 | 50 | while (endIndex >= startIndex) 51 | { 52 | keyframeIndex = (startIndex + endIndex) / 2; 53 | 54 | if (Items[keyframeIndex].Time < time) 55 | startIndex = keyframeIndex + 1; 56 | else if (Items[keyframeIndex].Time > time) 57 | endIndex = keyframeIndex - 1; 58 | else 59 | break; 60 | } 61 | 62 | if (Items[keyframeIndex].Time > time) 63 | keyframeIndex--; 64 | 65 | return keyframeIndex; 66 | } 67 | 68 | public AnimationChannelKeyframe GetKeyframeByTime(TimeSpan time) 69 | { 70 | int index = GetKeyframeIndexByTime(time); 71 | return Items[index]; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/AnimationChannelDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationChannelDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | 17 | namespace XNAnimation 18 | { 19 | public class AnimationChannelDictionary : ReadOnlyDictionary 20 | { 21 | public AnimationChannelDictionary(IDictionary dictionary) 22 | : base(dictionary) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/AnimationChannelKeyframe.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationChannelKeyframe.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | 17 | namespace XNAnimation 18 | { 19 | public class AnimationChannelKeyframe 20 | { 21 | private readonly TimeSpan time; 22 | private readonly Pose pose; 23 | 24 | #region Properties 25 | 26 | public TimeSpan Time 27 | { 28 | get { return time; } 29 | } 30 | 31 | public Pose Pose 32 | { 33 | get { return pose; } 34 | } 35 | 36 | #endregion 37 | 38 | internal AnimationChannelKeyframe(TimeSpan time, Pose pose) 39 | { 40 | this.time = time; 41 | this.pose = pose; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/AnimationClip.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationClip.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using System.Collections.Generic; 17 | using Microsoft.Xna.Framework.Content; 18 | 19 | namespace XNAnimation 20 | { 21 | public class AnimationClip 22 | { 23 | private readonly string name; 24 | private readonly TimeSpan duration; 25 | private readonly AnimationChannelDictionary channels; 26 | 27 | #region Properties 28 | 29 | public string Name 30 | { 31 | get { return name; } 32 | } 33 | 34 | public TimeSpan Duration 35 | { 36 | get { return duration; } 37 | } 38 | 39 | public AnimationChannelDictionary Channels 40 | { 41 | get { return channels; } 42 | } 43 | 44 | #endregion 45 | 46 | internal AnimationClip(string name, TimeSpan duration, AnimationChannelDictionary channels) 47 | { 48 | this.name = name; 49 | this.duration = duration; 50 | this.channels = channels; 51 | } 52 | 53 | internal static AnimationClip Read(ContentReader input) 54 | { 55 | string animationName = input.ReadString(); 56 | TimeSpan animationDuration = input.ReadObject(); 57 | 58 | // Read animation clip channels 59 | Dictionary animationChannelDictionary = 60 | new Dictionary(); 61 | 62 | int numAnimationChannels = input.ReadInt32(); 63 | for (int i = 0; i < numAnimationChannels; i++) 64 | { 65 | string channelName = input.ReadString(); 66 | 67 | // Read animation channel keyframes 68 | int numChannelKeyframes = input.ReadInt32(); 69 | List keyframeList = 70 | new List(numChannelKeyframes); 71 | 72 | for (int j = 0; j < numChannelKeyframes; j++) 73 | { 74 | TimeSpan keyframeTime = input.ReadObject(); 75 | 76 | // Read keyframe pose 77 | Pose keyframePose; 78 | keyframePose.Translation = input.ReadVector3(); 79 | keyframePose.Orientation = input.ReadQuaternion(); 80 | keyframePose.Scale = input.ReadVector3(); 81 | 82 | keyframeList.Add(new AnimationChannelKeyframe(keyframeTime, keyframePose)); 83 | } 84 | 85 | AnimationChannel animationChannel = new AnimationChannel(keyframeList); 86 | 87 | // Add the animation channel to the dictionary 88 | animationChannelDictionary.Add(channelName, animationChannel); 89 | } 90 | 91 | return 92 | new AnimationClip(animationName, animationDuration, 93 | new AnimationChannelDictionary(animationChannelDictionary)); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/AnimationClipDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationClipDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | 17 | namespace XNAnimation 18 | { 19 | public class AnimationClipDictionary : ReadOnlyDictionary 20 | { 21 | public AnimationClipDictionary(IDictionary dictionary) 22 | : base(dictionary) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Controllers/IAnimationController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IAnimationController.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using Microsoft.Xna.Framework; 17 | 18 | namespace XNAnimation.Controllers 19 | { 20 | /// 21 | /// Specifies how translations, orientations and scales are interpolated between keyframes. 22 | /// 23 | public enum InterpolationMode 24 | { 25 | /// 26 | /// Does not use interpolation. 27 | /// 28 | None, 29 | 30 | /// 31 | /// Linear interpolation. Supported on translations and scales. 32 | /// 33 | Linear, 34 | 35 | /// 36 | /// Cubic interpolation. Supported on translations and scales. 37 | /// 38 | Cubic, 39 | 40 | /// 41 | /// Spherical interpolation. Only supported on orientations. 42 | /// 43 | Spherical 44 | } ; 45 | 46 | /// 47 | /// Specifies how an animation clip is played. 48 | /// 49 | public enum PlaybackMode 50 | { 51 | /// 52 | /// Plays the animation clip in the forward way. 53 | /// 54 | Forward, 55 | 56 | /// 57 | /// Plays the animation clip in the backward way. 58 | /// 59 | Backward 60 | } ; 61 | 62 | /// 63 | /// Defines an interface for an animation controller. 64 | /// 65 | public interface IAnimationController 66 | { 67 | /// 68 | /// Gets the animation clip being played. 69 | /// 70 | AnimationClip AnimationClip { get; } 71 | 72 | /// 73 | /// Gets os sets the current animation playback time. 74 | /// 75 | TimeSpan Time { get; set; } 76 | 77 | /// 78 | /// Gets os sets the animation playback speed. 79 | /// 80 | float Speed { get; set; } 81 | 82 | /// 83 | /// Enables animation looping. 84 | /// 85 | bool LoopEnabled { get; set; } 86 | 87 | /// 88 | /// Gets os sets the animation playback mode. 89 | /// 90 | PlaybackMode PlaybackMode { get; set; } 91 | 92 | /// 93 | /// Gets os sets how translations are interpolated between animation keyframes. 94 | /// Supports linear and cubic interpolation. 95 | /// 96 | InterpolationMode TranslationInterpolation { get; set; } 97 | 98 | /// 99 | /// Gets os sets how orientations are interpolated between animation keyframes. 100 | /// Supports linear and spherical interpolation. 101 | /// 102 | InterpolationMode OrientationInterpolation { get; set; } 103 | 104 | /// 105 | /// Gets os sets how scales are interpolated between animation keyframes. 106 | /// Supports linear and cubic interpolation. 107 | /// 108 | InterpolationMode ScaleInterpolation { get; set; } 109 | 110 | /// 111 | /// Returns whether the animation has finished. 112 | /// 113 | bool HasFinished { get; } 114 | 115 | /// 116 | /// Returns whether the animation is playing. 117 | /// 118 | bool IsPlaying { get; } 119 | 120 | /// 121 | /// Gets the local pose of all skeleton's bones in depth-first order. 122 | /// 123 | Pose[] LocalBonePoses { get; } 124 | 125 | /// 126 | /// Gets the final transformation of all skeleton's bonse in depth-first order. 127 | /// This transformation is used to transfom the model's mesh vertices. 128 | /// 129 | Matrix[] SkinnedBoneTransforms { get; } 130 | 131 | /// 132 | /// Starts the playback of an animation clip from the beginning. 133 | /// 134 | /// The animation clip to be played. 135 | void StartClip(AnimationClip animationClip); 136 | 137 | /// 138 | /// Plays an animation clip. 139 | /// 140 | /// The animation clip to be played. 141 | void PlayClip(AnimationClip animationClip); 142 | 143 | /// 144 | /// Interpolates linearly between two animation clips, fading out the current 145 | /// animation clip and fading in a new one. 146 | /// 147 | /// The animation clip to be faded in. 148 | /// Time used to fade in and out the animation clips. 149 | void CrossFade(AnimationClip animationClip, TimeSpan fadeTime); 150 | 151 | /// 152 | /// Interpolates between two animation clips, fading out the current animation clip 153 | /// and fading in a new one. 154 | /// 155 | /// The animation clip to be faded in. 156 | /// Time used to fade in and out the animation clips. 157 | /// How translations are interpolated between animation clips. 158 | /// How orientations are interpolated between animation clips. 159 | /// How scales are interpolated between animation clips. 160 | void CrossFade(AnimationClip animationClip, TimeSpan fadeTime, 161 | InterpolationMode translationInterpolation, InterpolationMode orientationInterpolation, 162 | InterpolationMode scaleInterpolation); 163 | 164 | /// 165 | /// Updates the animation clip time and calculates the new skeleton's bone pose. 166 | /// 167 | /// Time elapsed since the last update. 168 | /// The parent bone for the current skeleton's root bone. 169 | void Update(TimeSpan elapsedTime, Matrix parent); 170 | } 171 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Controllers/IBlendController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IBlendController.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | 17 | namespace XNAnimation.Controllers 18 | { 19 | /// 20 | /// Specify how animation clips are blended. 21 | /// 22 | public enum BlendMode 23 | { 24 | /// 25 | /// Blends animation clips interpolation between them. 26 | /// 27 | Interpolate, 28 | 29 | /// 30 | /// Blends animation clips additively. 31 | /// 32 | Additive 33 | } 34 | 35 | /// 36 | /// Enumerates the available blend layers. 37 | /// 38 | public enum BlendLayer 39 | { 40 | /// 41 | /// First blend layer. 42 | /// 43 | One, 44 | 45 | /// 46 | /// Second blend layer. 47 | /// 48 | Two, 49 | 50 | /// 51 | /// Third blend layer. 52 | /// 53 | Three, 54 | 55 | /// 56 | /// Fourth blend layer. 57 | /// 58 | Four 59 | } 60 | 61 | /// 62 | /// Defines an interface for an animation blend controller. 63 | /// 64 | public interface IBlendController : IBlendable 65 | { 66 | /// 67 | /// Gets or sets the animation blend mode. 68 | /// 69 | BlendMode BlendMode { get; set; } 70 | 71 | InterpolationMode TranslationInterpolation { get; set; } 72 | InterpolationMode OrientationInterpolation { get; set; } 73 | InterpolationMode ScaleInterpolation { get; set; } 74 | 75 | void SetBlendLayer(IBlendable blendable, BlendLayer blendLayer); 76 | 77 | // FadeLayer 78 | void SetWeightInterpolation(float value, float desiredValue, TimeSpan time, BlendLayer blendLayer); 79 | 80 | void UpdateBlend(); 81 | } 82 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Controllers/IBlendable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IBlendable.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | namespace XNAnimation.Controllers 16 | { 17 | /// 18 | /// Defines an interface for blendable animations. 19 | /// 20 | public interface IBlendable 21 | { 22 | /// 23 | /// Gets the local pose of all skeleton's bones in depth-first order. 24 | /// 25 | Pose[] LocalBonePoses { get; } 26 | 27 | /// 28 | /// Gets or sets the blend weight. 29 | /// The blend weight must be a positive value between 0 and 1. 30 | /// 31 | float BlendWeight { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Controllers/ISkeletonController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * ISkeletonController.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | namespace XNAnimation.Controllers 16 | { 17 | /// 18 | /// Defines an interface for an skeleton controller. 19 | /// 20 | public interface ISkeletonController 21 | { 22 | /// 23 | /// Gets the local pose of all skeleton's bones in depth-first order. 24 | /// 25 | Pose[] LocalBonePoses { get; } 26 | 27 | /// 28 | /// Sets a custom pose for an skeleton's bone. 29 | /// 30 | /// The name of the bone. 31 | /// The custom pose to be set. 32 | void SetBonePose(string channelName, ref Pose pose); 33 | 34 | /// 35 | /// Sets a custom pose for an skeleton's bone. 36 | /// 37 | /// The name of the bone. 38 | /// The custom pose to be set. 39 | void SetBonePose(string channelName, Pose pose); 40 | } 41 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Controllers/SkeletonController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkeletonController.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | namespace XNAnimation.Controllers 16 | { 17 | /// 18 | /// Controls the pose of each bone in a skeleton. Allows custom skeleton poses to be blended 19 | /// with other objects. 20 | /// 21 | public class SkeletonController : ISkeletonController, IBlendable 22 | { 23 | private SkinnedModelBoneDictionary skeletonDictionary; 24 | private Pose[] localBonePoses; 25 | private float blendWeight; 26 | 27 | #region Properties 28 | 29 | /// 30 | public Pose[] LocalBonePoses 31 | { 32 | get { return localBonePoses; } 33 | } 34 | 35 | /// 36 | public float BlendWeight 37 | { 38 | get { return blendWeight; } 39 | set { blendWeight = value; } 40 | } 41 | 42 | #endregion 43 | 44 | /// Initializes a new instance of the 45 | /// 46 | /// class. 47 | /// 48 | /// 49 | public SkeletonController(SkinnedModelBoneDictionary skeletonDictionary) 50 | { 51 | this.skeletonDictionary = skeletonDictionary; 52 | localBonePoses = new Pose[skeletonDictionary.Count]; 53 | 54 | blendWeight = 1.0f; 55 | } 56 | 57 | /// 58 | public void SetBonePose(string channelName, ref Pose pose) 59 | { 60 | localBonePoses[skeletonDictionary[channelName].Index] = pose; 61 | } 62 | 63 | /// 64 | public void SetBonePose(string channelName, Pose pose) 65 | { 66 | localBonePoses[skeletonDictionary[channelName].Index] = pose; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/ILight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * ILight.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | 17 | namespace XNAnimation.Effects 18 | { 19 | public interface ILight 20 | { 21 | Vector3 Color { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/IMaterial.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IMaterial.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | 17 | namespace XNAnimation.Effects 18 | { 19 | public interface IMaterial 20 | { 21 | Vector3 EmissiveColor { get; set; } 22 | Vector3 DiffuseColor { get; set; } 23 | Vector3 SpecularColor { get; set; } 24 | float SpecularPower { get; set; } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/IPointLight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IPointLight.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | 17 | namespace XNAnimation.Effects 18 | { 19 | public interface IPointLight : ILight 20 | { 21 | Vector3 Position { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/Material.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * IMaterial.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | using Microsoft.Xna.Framework.Graphics; 17 | 18 | namespace XNAnimation.Effects 19 | { 20 | public class Material : IMaterial 21 | { 22 | private EffectParameter emissiveColorParam; 23 | private EffectParameter diffuseColorParam; 24 | private EffectParameter specularColorParam; 25 | private EffectParameter specularPowerParam; 26 | 27 | #region Properties 28 | 29 | public Vector3 EmissiveColor 30 | { 31 | get { return emissiveColorParam.GetValueVector3(); } 32 | set { emissiveColorParam.SetValue(value); } 33 | } 34 | 35 | public Vector3 DiffuseColor 36 | { 37 | get { return diffuseColorParam.GetValueVector3(); } 38 | set { diffuseColorParam.SetValue(value); } 39 | } 40 | 41 | public Vector3 SpecularColor 42 | { 43 | get { return specularColorParam.GetValueVector3(); } 44 | set { specularColorParam.SetValue(value); } 45 | } 46 | 47 | public float SpecularPower 48 | { 49 | get { return specularPowerParam.GetValueSingle(); } 50 | set { specularPowerParam.SetValue(value); } 51 | } 52 | 53 | #endregion 54 | 55 | internal Material(EffectParameter materialStructParameter) 56 | { 57 | CacheEffectParams(materialStructParameter); 58 | } 59 | 60 | private void CacheEffectParams(EffectParameter materialStructParameter) 61 | { 62 | emissiveColorParam = materialStructParameter.StructureMembers["emissiveColor"]; 63 | diffuseColorParam = materialStructParameter.StructureMembers["diffuseColor"]; 64 | specularColorParam = materialStructParameter.StructureMembers["specularColor"]; 65 | specularPowerParam = materialStructParameter.StructureMembers["specularPower"]; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/PointLight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * PointLight.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | using Microsoft.Xna.Framework.Graphics; 17 | 18 | namespace XNAnimation.Effects 19 | { 20 | public class PointLight : IPointLight 21 | { 22 | private EffectParameter positionParam; 23 | private EffectParameter colorParam; 24 | 25 | #region Properties 26 | 27 | public Vector3 Position 28 | { 29 | get { return positionParam.GetValueVector3(); } 30 | set { positionParam.SetValue(value); } 31 | } 32 | 33 | public Vector3 Color 34 | { 35 | get { return colorParam.GetValueVector3(); } 36 | set { colorParam.SetValue(value); } 37 | } 38 | 39 | #endregion 40 | 41 | internal PointLight(EffectParameter lightStuctParameter) 42 | { 43 | CacheEffectParams(lightStuctParameter); 44 | } 45 | 46 | private void CacheEffectParams(EffectParameter lightStuctParameter) 47 | { 48 | positionParam = lightStuctParameter.StructureMembers["position"]; 49 | colorParam = lightStuctParameter.StructureMembers["color"]; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/PointLightCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * PointLightCollection.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimation.Effects 19 | { 20 | public class PointLightCollection : ReadOnlyCollection 21 | { 22 | public PointLightCollection(IList list) 23 | : base(list) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Effects/SkinnedModelBasicEffect.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/Effects/SkinnedModelBasicEffect.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pipeline/AnimationClipReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationClipReader.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework.Content; 16 | 17 | namespace XNAnimation.Pipeline 18 | { 19 | internal class AnimationClipReader : ContentTypeReader 20 | { 21 | protected override AnimationClip Read(ContentReader input, AnimationClip existingInstance) 22 | { 23 | return AnimationClip.Read(input); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pipeline/SkinnedModelBasicEffectReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBasicEffectReader.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework.Content; 16 | using XNAnimation.Effects; 17 | 18 | namespace XNAnimation.Pipeline 19 | { 20 | internal class SkinnedModelBasicEffectReader : ContentTypeReader 21 | { 22 | protected override SkinnedModelBasicEffect Read(ContentReader input, 23 | SkinnedModelBasicEffect existingInstance) 24 | { 25 | return SkinnedModelBasicEffect.Read(input); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pipeline/SkinnedModelBoneReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneReader.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework.Content; 16 | 17 | namespace XNAnimation.Pipeline 18 | { 19 | internal class SkinnedModelBoneReader : ContentTypeReader 20 | { 21 | protected override SkinnedModelBone Read(ContentReader input, SkinnedModelBone existingInstance) 22 | { 23 | return SkinnedModelBone.Read(input); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pipeline/SkinnedModelMeshReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMeshReader.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework.Content; 16 | 17 | namespace XNAnimation.Pipeline 18 | { 19 | internal class SkinnedModelMeshReader : ContentTypeReader 20 | { 21 | protected override SkinnedModelMesh Read(ContentReader input, SkinnedModelMesh existingInstance) 22 | { 23 | return SkinnedModelMesh.Read(input); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pipeline/SkinnedModelReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelReader.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework.Content; 16 | 17 | namespace XNAnimation.Pipeline 18 | { 19 | internal class SkinnedModelReader : ContentTypeReader 20 | { 21 | protected override SkinnedModel Read(ContentReader input, SkinnedModel existingInstance) 22 | { 23 | return SkinnedModel.Read(input); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Pose.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Pose.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using Microsoft.Xna.Framework; 17 | using XNAnimation.Controllers; 18 | using System.Globalization; 19 | 20 | namespace XNAnimation 21 | { 22 | public struct Pose : IEquatable 23 | { 24 | public Vector3 Translation; 25 | public Quaternion Orientation; 26 | public Vector3 Scale; 27 | 28 | private static readonly Pose _identity; 29 | 30 | #region Properties 31 | 32 | public static Pose Identity 33 | { 34 | get { return _identity; } 35 | } 36 | 37 | #endregion 38 | 39 | static Pose() 40 | { 41 | _identity.Orientation = Quaternion.Identity; 42 | _identity.Translation = Vector3.Zero; 43 | _identity.Scale = Vector3.Zero; 44 | } 45 | 46 | /* 47 | public Pose(Vector3 translation, Quaternion orientation, Vector3 scale) 48 | { 49 | this.Translation = translation; 50 | this.Orientation = orientation; 51 | this.Scale = scale; 52 | } 53 | */ 54 | 55 | public static Pose Interpolate(Pose pose1, Pose pose2, float amount, 56 | InterpolationMode translationInterpolation, InterpolationMode orientationInterpolation, 57 | InterpolationMode scaleInterpolation) 58 | { 59 | Pose resultPose; 60 | 61 | if (amount < 0 || amount > 1) 62 | throw new ArgumentException("Amount must be between 0.0 and 1.0 inclusive."); 63 | 64 | switch (translationInterpolation) 65 | { 66 | case InterpolationMode.None: 67 | resultPose.Translation = pose1.Translation; 68 | break; 69 | 70 | case InterpolationMode.Linear: 71 | Vector3.Lerp(ref pose1.Translation, ref pose2.Translation, amount, 72 | out resultPose.Translation); 73 | break; 74 | 75 | case InterpolationMode.Cubic: 76 | Vector3.SmoothStep(ref pose1.Translation, ref pose2.Translation, amount, 77 | out resultPose.Translation); 78 | break; 79 | 80 | default: 81 | throw new ArgumentException("Translation interpolation method not supported"); 82 | } 83 | 84 | switch (orientationInterpolation) 85 | { 86 | case InterpolationMode.None: 87 | resultPose.Orientation = pose1.Orientation; 88 | break; 89 | 90 | case InterpolationMode.Linear: 91 | Quaternion.Lerp(ref pose1.Orientation, ref pose2.Orientation, amount, 92 | out resultPose.Orientation); 93 | break; 94 | 95 | case InterpolationMode.Spherical: 96 | Quaternion.Slerp(ref pose1.Orientation, ref pose2.Orientation, amount, 97 | out resultPose.Orientation); 98 | break; 99 | 100 | default: 101 | throw new ArgumentException("Orientation interpolation method not supported"); 102 | } 103 | 104 | switch (scaleInterpolation) 105 | { 106 | case InterpolationMode.None: 107 | resultPose.Scale = pose1.Scale; 108 | break; 109 | 110 | case InterpolationMode.Linear: 111 | Vector3.Lerp(ref pose1.Scale, ref pose2.Scale, amount, 112 | out resultPose.Scale); 113 | break; 114 | 115 | case InterpolationMode.Cubic: 116 | Vector3.SmoothStep(ref pose1.Scale, ref pose2.Scale, amount, 117 | out resultPose.Scale); 118 | break; 119 | 120 | default: 121 | throw new ArgumentException("Scale interpolation method not supported"); 122 | } 123 | 124 | return resultPose; 125 | } 126 | 127 | #region IEquatable Members 128 | 129 | public override int GetHashCode() 130 | { 131 | return (Translation.GetHashCode() + Orientation.GetHashCode() + Scale.GetHashCode()); 132 | } 133 | 134 | public override string ToString() 135 | { 136 | CultureInfo currentCulture = CultureInfo.CurrentCulture; 137 | return string.Format(currentCulture, 138 | "{{Translation:{0}\n Orientation:{1}\n Scale:{2}\n}}", new object[] 139 | { Translation.ToString(), Orientation.ToString(), Scale.ToString() }); 140 | } 141 | 142 | public bool Equals(Pose other) 143 | { 144 | return (Translation == other.Translation && 145 | Orientation == other.Orientation && 146 | Scale == other.Scale); 147 | } 148 | 149 | public override bool Equals(object obj) 150 | { 151 | bool result = false; 152 | if (obj is Pose) 153 | { 154 | result = this.Equals((Pose)obj); 155 | } 156 | 157 | return result; 158 | } 159 | 160 | public static bool operator == (Pose pose1, Pose pose2) 161 | { 162 | return (pose1.Translation == pose2.Translation && 163 | pose1.Orientation == pose2.Orientation && 164 | pose1.Scale == pose2.Scale); 165 | } 166 | 167 | public static bool operator !=(Pose pose1, Pose pose2) 168 | { 169 | return (pose1.Translation != pose2.Translation || 170 | pose1.Orientation != pose2.Orientation || 171 | pose1.Scale != pose2.Scale); 172 | } 173 | 174 | #endregion 175 | } 176 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Properties/AppManifest.xml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | 10 | [assembly : AssemblyTitle("XNAnimation")] 11 | [assembly : AssemblyProduct("XNAnimation")] 12 | [assembly : AssemblyDescription("")] 13 | [assembly : AssemblyCompany("")] 14 | [assembly : AssemblyCopyright("Copyright © Bruno Evangelista 2008")] 15 | [assembly : AssemblyTrademark("")] 16 | [assembly : AssemblyCulture("")] 17 | [assembly : 18 | InternalsVisibleTo( 19 | "XNAnimationPipeline, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a3fb1b382a63894f63d29769d0f1d42ab77e36e5ff84fcd3d0711fe0a485adf65e4f37647945d840e3496d8d6d38963bf7a3c15d4f10aedef76f87b5feb27df6c9824acd42de25fed3db8a33e9b95382fd7fdc5fd00ba607acb7f4cdee233e2aed767a9afe4a50b10b747cb1456e4132df78276b988dd4c3e868286133712bd7" 20 | //"XNAnimationPipeline, PublicKey=0024000004800000940000000602000000240000525341310004000001000100156c8dbd94e1ac0d9daefc56d485525108d581717aa4ae7ee4542c450b1a4162a7c2d90bbcd01b8945f0a934667c54dfe1536e1b9814ba3c2ce1c1f208e58c875b263a28641e6b0d773c6b5d4109215b3ce1c035fe32dc6ee106e23229ee7fd8a07604d1c87a4a641b23b4b00aec788ee1f878bf145595d62aaddc91d8eaebcd" 21 | )] 22 | 23 | // [assembly : CLSCompliant(true)] 24 | 25 | // Setting ComVisible to false makes the types in this assembly not visible 26 | // to COM components. If you need to access a type in this assembly from 27 | // COM, set the ComVisible attribute to true on that type. 28 | 29 | [assembly : ComVisible(false)] 30 | 31 | // The following GUID is for the ID of the typelib if this project is exposed to COM 32 | 33 | [assembly: Guid("01717c1c-406c-4fa6-850c-dcd45c9aebf1")] 34 | 35 | // Version information for an assembly consists of the following four values: 36 | // 37 | // Major Version 38 | // Minor Version 39 | // Build Number 40 | // Revision 41 | // 42 | 43 | [assembly : AssemblyVersion("0.8.0.0")] -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/Properties/WMAppManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/ReadOnlyDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * ReadOnlyDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using System.Collections; 17 | using System.Collections.Generic; 18 | using System.Collections.ObjectModel; 19 | 20 | namespace XNAnimation 21 | { 22 | public class ReadOnlyDictionary : IDictionary 23 | { 24 | private static readonly string ReadOnlyException = "Collection is read-only."; 25 | private readonly IDictionary items; 26 | 27 | #region Properties 28 | 29 | V IDictionary.this[T key] 30 | { 31 | get { return items[key]; } 32 | set { throw new NotSupportedException(ReadOnlyException); } 33 | } 34 | 35 | ICollection IDictionary.Keys 36 | { 37 | get { throw new NotSupportedException(ReadOnlyException); } 38 | } 39 | 40 | ICollection IDictionary.Values 41 | { 42 | get { throw new NotSupportedException(ReadOnlyException); } 43 | } 44 | 45 | public V this[T key] 46 | { 47 | get { return items[key]; } 48 | } 49 | 50 | public ReadOnlyCollection Keys 51 | { 52 | get { return new ReadOnlyCollection(new List(items.Keys)); } 53 | } 54 | 55 | public ReadOnlyCollection Values 56 | { 57 | get { return new ReadOnlyCollection(new List(items.Values)); } 58 | } 59 | 60 | public int Count 61 | { 62 | get { return items.Count; } 63 | } 64 | 65 | public bool IsReadOnly 66 | { 67 | get { return true; } 68 | } 69 | 70 | #endregion 71 | 72 | public ReadOnlyDictionary(IDictionary dictionary) 73 | { 74 | if (dictionary == null) 75 | throw new ArgumentNullException("dictionary"); 76 | 77 | items = dictionary; 78 | } 79 | 80 | #region Not supported methods 81 | 82 | void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) 83 | { 84 | } 85 | 86 | void ICollection>.Clear() 87 | { 88 | throw new NotSupportedException(); 89 | } 90 | 91 | public bool Contains(KeyValuePair item) 92 | { 93 | throw new NotSupportedException(); 94 | } 95 | 96 | void ICollection>.Add(KeyValuePair item) 97 | { 98 | throw new NotSupportedException(ReadOnlyException); 99 | } 100 | 101 | void IDictionary.Add(T key, V value) 102 | { 103 | throw new NotSupportedException(ReadOnlyException); 104 | } 105 | 106 | bool ICollection>.Remove(KeyValuePair item) 107 | { 108 | throw new NotSupportedException(ReadOnlyException); 109 | } 110 | 111 | bool IDictionary.Remove(T key) 112 | { 113 | throw new NotSupportedException(ReadOnlyException); 114 | } 115 | 116 | #endregion 117 | 118 | public bool ContainsKey(T key) 119 | { 120 | return items.ContainsKey(key); 121 | } 122 | 123 | /* 124 | public bool ContainsValue(V value) 125 | { 126 | return items.ContainsValue(value); 127 | } 128 | */ 129 | 130 | public bool TryGetValue(T key, out V value) 131 | { 132 | return items.TryGetValue(key, out value); 133 | } 134 | 135 | public IEnumerator GetEnumerator() 136 | { 137 | return items.GetEnumerator(); 138 | } 139 | 140 | IEnumerator> IEnumerable>.GetEnumerator() 141 | { 142 | return (IEnumerator>) items.GetEnumerator(); 143 | } 144 | } 145 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModel.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/SkinnedModel.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModelBone.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/SkinnedModelBone.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModelBoneCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneCollection.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimation 19 | { 20 | public class SkinnedModelBoneCollection : ReadOnlyCollection 21 | { 22 | public SkinnedModelBone this[string boneName] 23 | { 24 | get 25 | { 26 | for (int i = 0; i < Count; i++) 27 | { 28 | if (this[i].Name == boneName) 29 | { 30 | return this[i]; 31 | } 32 | } 33 | return null; 34 | } 35 | } 36 | 37 | public SkinnedModelBoneCollection(IList list) 38 | : base(list) 39 | { 40 | } 41 | 42 | public int GetBoneId(string boneName) 43 | { 44 | for (int i = 0; i < Count; i++) 45 | { 46 | if (this[i].Name == boneName) 47 | { 48 | return i; 49 | } 50 | } 51 | return -1; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModelBoneDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | 17 | namespace XNAnimation 18 | { 19 | public class SkinnedModelBoneDictionary : ReadOnlyDictionary 20 | { 21 | public SkinnedModelBoneDictionary(IDictionary dictionary) 22 | : base(dictionary) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModelMesh.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMesh.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using System.Collections.Generic; 17 | using Microsoft.Xna.Framework; 18 | using Microsoft.Xna.Framework.Content; 19 | using Microsoft.Xna.Framework.Graphics; 20 | using XNAnimation.Effects; 21 | 22 | namespace XNAnimation 23 | { 24 | public class SkinnedModelMesh 25 | { 26 | internal int numVertices; 27 | internal int numTriangles; 28 | internal VertexBuffer vertices; 29 | internal IndexBuffer indices; 30 | internal SkinnedModelBasicEffect effect; 31 | 32 | public VertexBuffer Vertices { get { return vertices; } } 33 | 34 | public IndexBuffer Indices { get { return indices; } } 35 | 36 | public SkinnedModelBasicEffect Effect 37 | { 38 | get 39 | { 40 | return effect; 41 | } 42 | } 43 | 44 | internal SkinnedModelMesh() 45 | { 46 | } 47 | 48 | internal static SkinnedModelMesh Read(ContentReader input) 49 | { 50 | SkinnedModelMesh skinnedModelPart = new SkinnedModelMesh(); 51 | 52 | skinnedModelPart.numVertices = input.ReadInt32(); 53 | skinnedModelPart.numTriangles = input.ReadInt32(); 54 | skinnedModelPart.vertices = input.ReadObject(); 55 | skinnedModelPart.indices = input.ReadObject(); 56 | skinnedModelPart.effect = input.ReadObject(); 57 | 58 | return skinnedModelPart; 59 | } 60 | 61 | public void Draw() 62 | { 63 | GraphicsDevice graphicsDevice = vertices.GraphicsDevice; 64 | graphicsDevice.SetVertexBuffer(vertices); 65 | graphicsDevice.Indices = indices; 66 | 67 | for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++) 68 | { 69 | effect.CurrentTechnique.Passes[i].Apply(); 70 | graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numTriangles); 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/SkinnedModelMeshCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMeshCollection.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimation 19 | { 20 | public class SkinnedModelMeshCollection : ReadOnlyCollection 21 | { 22 | public SkinnedModelMeshCollection(IList list) 23 | : base(list) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimation (Windows Phone).csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {8A92E2A6-0CA7-40A1-B595-8B916687E9DB} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | Windows Phone 8 | Library 9 | Properties 10 | XNAnimation 11 | XNAnimation 12 | v4.0 13 | Client 14 | v4.0 15 | Windows Phone 16 | Reach 17 | 3fb55147-4fba-42af-bafc-8a797a5418b1 18 | Library 19 | $(AssemblyName).xap 20 | Properties\AppManifest.xml 21 | Properties\WMAppManifest.xml 22 | Background.png 23 | $(AssemblyName) 24 | 25 | SAK 26 | SAK 27 | SAK 28 | SAK 29 | 30 | 31 | true 32 | 33 | 34 | XNAnimationPhone.snk 35 | 36 | 37 | bin\Windows Phone\Debug 38 | prompt 39 | 4 40 | true 41 | false 42 | true 43 | full 44 | false 45 | DEBUG;TRACE;WINDOWS_PHONE 46 | false 47 | 48 | 49 | bin\Windows Phone\Release 50 | prompt 51 | 4 52 | true 53 | false 54 | pdbonly 55 | true 56 | TRACE;WINDOWS_PHONE 57 | false 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | true 97 | 98 | 99 | true 100 | 101 | 102 | true 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | False 112 | 113 | 114 | False 115 | 116 | 117 | False 118 | 119 | 120 | False 121 | 122 | 123 | False 124 | 125 | 126 | False 127 | 128 | 129 | False 130 | 131 | 132 | 133 | False 134 | 135 | 136 | False 137 | 138 | 139 | 140 | 141 | 142 | copy "$(TargetPath)" "$(SolutionDir)..\XNAnimation Samples\XNAnimation\Windows Phone\$(TargetFileName)" 143 | 144 | 152 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimation (Xbox 360).csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {53A043A1-DF61-487B-87B8-DAB1D3B88F78} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | Xbox 360 8 | Library 9 | Properties 10 | XNAnimation 11 | XNAnimation 12 | v4.0 13 | Client 14 | v4.0 15 | Xbox 360 16 | HiDef 17 | 3fb55147-4fba-42af-bafc-8a797a5418b1 18 | Library 19 | SAK 20 | SAK 21 | SAK 22 | SAK 23 | 24 | 25 | true 26 | 27 | 28 | XNAnimationXbox.snk 29 | 30 | 31 | bin\Xbox 360\Debug 32 | prompt 33 | 4 34 | true 35 | false 36 | true 37 | full 38 | false 39 | DEBUG;TRACE;XBOX;XBOX360 40 | true 41 | 42 | 43 | bin\Xbox 360\Release 44 | prompt 45 | 4 46 | true 47 | false 48 | pdbonly 49 | true 50 | TRACE;XBOX;XBOX360 51 | true 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | False 97 | 98 | 99 | False 100 | 101 | 102 | False 103 | 104 | 105 | False 106 | 107 | 108 | False 109 | 110 | 111 | False 112 | 113 | 114 | False 115 | 116 | 117 | False 118 | 119 | 120 | False 121 | 122 | 123 | False 124 | 125 | 126 | False 127 | 128 | 129 | False 130 | 131 | 132 | 133 | False 134 | 135 | 136 | False 137 | 138 | 139 | 140 | 141 | 142 | copy "$(TargetPath)" "$(SolutionDir)..\XNAnimation Samples\XNAnimation\Xbox 360\$(TargetFileName)" 143 | 144 | 152 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimation.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {95228D3D-48C7-41B3-AE1D-01E018354C34} 5 | {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | XNAnimation 11 | XNAnimation 12 | v4.0 13 | Client 14 | v4.0 15 | Windows 16 | HiDef 17 | 3fb55147-4fba-42af-bafc-8a797a5418b1 18 | Library 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\x86\Debug 33 | DEBUG;TRACE;WINDOWS 34 | prompt 35 | 4 36 | true 37 | false 38 | x86 39 | false 40 | 41 | 42 | pdbonly 43 | true 44 | bin\x86\Release 45 | TRACE;WINDOWS 46 | prompt 47 | 4 48 | true 49 | false 50 | x86 51 | true 52 | 53 | 54 | true 55 | 56 | 57 | XNAnimation.snk 58 | 59 | 60 | 61 | False 62 | 63 | 64 | False 65 | 66 | 67 | False 68 | 69 | 70 | False 71 | 72 | 73 | False 74 | 75 | 76 | False 77 | 78 | 79 | False 80 | 81 | 82 | False 83 | 84 | 85 | False 86 | 87 | 88 | False 89 | 90 | 91 | False 92 | 93 | 94 | False 95 | 96 | 97 | 4.0 98 | False 99 | 100 | 101 | 4.0 102 | False 103 | 104 | 105 | False 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 162 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimation.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/XNAnimation.snk -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimationDiagram.cd: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimationPhone.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/XNAnimationPhone.snk -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimation/XNAnimationXbox.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimation/XNAnimationXbox.snk -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/AnimationChannelContent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationChannelContent.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class AnimationChannelContent : ReadOnlyCollection 21 | { 22 | internal AnimationChannelContent(IList list) 23 | : base(list) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/AnimationChannelContentDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationChannelContentDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using XNAnimation; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class AnimationChannelContentDictionary : ReadOnlyDictionary 21 | { 22 | internal AnimationChannelContentDictionary( 23 | IDictionary dictionary) 24 | : base(dictionary) 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/AnimationClipContent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationClipContent.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using System.Collections.Generic; 17 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; 18 | 19 | namespace XNAnimationPipeline 20 | { 21 | public class AnimationClipContent 22 | { 23 | private readonly string name; 24 | private readonly TimeSpan duration; 25 | private readonly AnimationChannelContentDictionary channels; 26 | 27 | #region Properties 28 | 29 | public string Name 30 | { 31 | get { return name; } 32 | } 33 | 34 | public TimeSpan Duration 35 | { 36 | get { return duration; } 37 | } 38 | 39 | public AnimationChannelContentDictionary Channels 40 | { 41 | get { return channels; } 42 | } 43 | 44 | #endregion 45 | 46 | internal AnimationClipContent(string name, AnimationChannelContentDictionary channels, 47 | TimeSpan duration) 48 | { 49 | this.name = name; 50 | this.channels = channels; 51 | this.duration = duration; 52 | } 53 | 54 | internal void Write(ContentWriter output) 55 | { 56 | output.Write(name); 57 | output.WriteObject(duration); 58 | 59 | // Write animation clip channels 60 | output.Write(channels.Count); 61 | foreach (KeyValuePair pair in channels) 62 | { 63 | output.Write(pair.Key); 64 | AnimationChannelContent animationChannel = pair.Value; 65 | 66 | // Write the animation channel keyframes 67 | output.Write(animationChannel.Count); 68 | foreach (AnimationKeyframeContent keyframe in animationChannel) 69 | { 70 | output.WriteObject(keyframe.Time); 71 | 72 | // Write pose 73 | output.Write(keyframe.Pose.Translation); 74 | output.Write(keyframe.Pose.Orientation); 75 | output.Write(keyframe.Pose.Scale); 76 | } 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/AnimationClipContentDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationClipContentDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using XNAnimation; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class AnimationClipContentDictionary : ReadOnlyDictionary 21 | { 22 | internal AnimationClipContentDictionary(IDictionary dictionary) 23 | : base(dictionary) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/AnimationKeyframeContent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AnimationKeyframeContent.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System; 16 | using XNAnimation; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class AnimationKeyframeContent : IComparable 21 | { 22 | private TimeSpan time; 23 | private Pose pose; 24 | 25 | #region Properties 26 | 27 | public TimeSpan Time 28 | { 29 | get { return time; } 30 | } 31 | 32 | public Pose Pose 33 | { 34 | get { return pose; } 35 | } 36 | 37 | #endregion 38 | 39 | internal AnimationKeyframeContent(TimeSpan time, Pose pose) 40 | { 41 | this.time = time; 42 | this.pose = pose; 43 | } 44 | 45 | public int CompareTo(AnimationKeyframeContent other) 46 | { 47 | return time.CompareTo(other.Time); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Effects/SkinnedModelMaterialContent.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Effects/SkinnedModelMaterialContent.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/AnimationClipWriter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/AnimationClipWriter.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/AssemblyHelper.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/AssemblyHelper.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/PathType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace XNAnimationPipeline.Pipeline 6 | { 7 | public enum PathType 8 | { 9 | Absolute, 10 | Relative 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelBoneWriter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelBoneWriter.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelMaterialProcessor.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelMaterialProcessor.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelMaterialWriter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelMaterialWriter.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelMeshWriter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMeshWriter.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | using Microsoft.Xna.Framework.Content.Pipeline; 17 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; 18 | using XNAnimation.Pipeline; 19 | 20 | namespace XNAnimationPipeline.Pipeline 21 | { 22 | [ContentTypeWriter] 23 | internal class SkinnedModelMeshWriter : ContentTypeWriter 24 | { 25 | protected override void Write(ContentWriter output, SkinnedModelMeshContent value) 26 | { 27 | value.Write(output); 28 | } 29 | 30 | public override string GetRuntimeReader(TargetPlatform targetPlatform) 31 | { 32 | return AssemblyHelper.GetRuntimeReader(typeof(SkinnedModelMeshReader), targetPlatform); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelProcessor.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelProcessor.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelWriter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Pipeline/SkinnedModelWriter.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/Properties/AssemblyInfo.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.1 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace XNAnimationPipeline { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XNAnimationPipeline.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to // Any change made over these constants require that the SkinnedModelEffect also being updated. 65 | ///#define SHADER20_MAX_BONES 80 66 | ///#define MAX_LIGHTS 8 67 | /// 68 | ///struct PointLight 69 | ///{ 70 | /// float3 position; 71 | /// float3 color; 72 | ///}; 73 | /// 74 | ///struct Material 75 | ///{ 76 | /// float3 emissiveColor; 77 | /// float3 diffuseColor; 78 | /// float3 specularColor; 79 | /// float specularPower; 80 | ///}; 81 | /// 82 | ///// Configurations 83 | ///// ------------------------------------------------- 84 | ///bool diffuseMapEnabled; 85 | ///bool specularMapEnabled; 86 | /// 87 | ///// Matrix 88 | ///// ------------------- [rest of string was truncated]";. 89 | /// 90 | internal static string SkinnedModelEffect { 91 | get { 92 | return ResourceManager.GetString("SkinnedModelEffect", resourceCulture); 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | Resources\SkinnedModelEffect.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 123 | 124 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelBoneContent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneContent.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; 17 | using XNAnimation; 18 | 19 | namespace XNAnimationPipeline 20 | { 21 | public class SkinnedModelBoneContent 22 | { 23 | private readonly ushort index; 24 | private readonly string name; 25 | private SkinnedModelBoneContent parent; 26 | private SkinnedModelBoneContentCollection children; 27 | 28 | private readonly Pose bindPose; 29 | private readonly Matrix inverseBindPoseTransform; 30 | 31 | #region Properties 32 | 33 | public string Name 34 | { 35 | get { return name; } 36 | } 37 | 38 | public ushort Index 39 | { 40 | get { return index; } 41 | } 42 | 43 | public SkinnedModelBoneContent Parent 44 | { 45 | get { return parent; } 46 | internal set { parent = value; } 47 | } 48 | 49 | public SkinnedModelBoneContentCollection Children 50 | { 51 | get { return children; } 52 | internal set { children = value; } 53 | } 54 | 55 | public Pose BindPose 56 | { 57 | get { return bindPose; } 58 | } 59 | 60 | public Matrix InverseBindPoseTransform 61 | { 62 | get { return inverseBindPoseTransform; } 63 | } 64 | 65 | #endregion 66 | 67 | internal SkinnedModelBoneContent(ushort index, string name, Pose bindPose, 68 | Matrix inverseBindPoseTransform) 69 | { 70 | this.index = index; 71 | this.name = name; 72 | this.bindPose = bindPose; 73 | this.inverseBindPoseTransform = inverseBindPoseTransform; 74 | } 75 | 76 | internal void Write(ContentWriter output) 77 | { 78 | output.Write(index); 79 | output.Write(name); 80 | 81 | // Write bind pose 82 | output.Write(bindPose.Translation); 83 | output.Write(bindPose.Orientation); 84 | output.Write(bindPose.Scale); 85 | 86 | output.Write(inverseBindPoseTransform); 87 | 88 | // Write parent and children 89 | output.WriteSharedResource(parent); 90 | output.Write(children.Count); 91 | foreach (SkinnedModelBoneContent childBone in children) 92 | output.WriteSharedResource(childBone); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelBoneContentCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneContentCollection.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class SkinnedModelBoneContentCollection : ReadOnlyCollection 21 | { 22 | internal SkinnedModelBoneContentCollection(IList list) 23 | : base(list) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelBoneContentDictionary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelBoneContentDictionary.cs 3 | * Author: Bruno Evangelista 4 | * Copyright (c) 2008 Bruno Evangelista. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using XNAnimation; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class SkinnedModelBoneContentDictionary : ReadOnlyDictionary 21 | { 22 | internal SkinnedModelBoneContentDictionary( 23 | IDictionary dictionary) 24 | : base(dictionary) 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelContent.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/SkinnedModelContent.cs -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelMeshContent.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMeshContent.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using Microsoft.Xna.Framework; 16 | using Microsoft.Xna.Framework.Content.Pipeline.Graphics; 17 | using Microsoft.Xna.Framework.Content.Pipeline.Processors; 18 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler; 19 | 20 | namespace XNAnimationPipeline 21 | { 22 | public class SkinnedModelMeshContent 23 | { 24 | private int numVertices; 25 | private int numTriangles; 26 | private VertexBufferContent vertices; 27 | private IndexCollection indices; 28 | private MaterialContent material; 29 | 30 | internal SkinnedModelMeshContent(int numVertices, int numTriangles, VertexBufferContent vertices, 31 | IndexCollection indices, MaterialContent material) 32 | { 33 | this.numVertices = numVertices; 34 | this.numTriangles = numTriangles; 35 | this.vertices = vertices; 36 | this.indices = indices; 37 | this.material = material; 38 | } 39 | 40 | internal void Write(ContentWriter output) 41 | { 42 | output.Write(numVertices); 43 | output.Write(numTriangles); 44 | output.WriteObject(vertices); 45 | output.WriteObject(indices); 46 | output.WriteObject(material); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/SkinnedModelMeshContentCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * SkinnedModelMeshContentCollection.cs 3 | * Author: Rodrigo 'r2d2rigo' Díaz 4 | * Copyright (c) 2010 Rodrigo 'r2d2rigo' Díaz. All rights reserved. 5 | * 6 | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 7 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 9 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 10 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 11 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 12 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | * 14 | */ 15 | using System.Collections.Generic; 16 | using System.Collections.ObjectModel; 17 | 18 | namespace XNAnimationPipeline 19 | { 20 | public class SkinnedModelMeshContentCollection : ReadOnlyCollection 21 | { 22 | internal SkinnedModelMeshContentCollection(IList list) 23 | : base(list) 24 | { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/XNAnimation.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/XNAnimation/XNAnimationPipeline/XNAnimation.snk -------------------------------------------------------------------------------- /prototype/XNAnimation/XNAnimationPipeline/XNAnimationPipeline.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {06062F97-D86E-4FA6-BC0E-1F60666439CB} 5 | Debug 6 | x86 7 | Library 8 | Properties 9 | XNAnimationPipeline 10 | XNAnimationPipeline 11 | v4.0 12 | true 13 | XNAnimation.snk 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 3.5 25 | 26 | 27 | v4.0 28 | false 29 | publish\ 30 | true 31 | Disk 32 | false 33 | Foreground 34 | 7 35 | Days 36 | false 37 | false 38 | true 39 | 0 40 | 1.0.0.%2a 41 | false 42 | true 43 | 44 | 45 | true 46 | full 47 | false 48 | bin\x86\Debug 49 | DEBUG;TRACE 50 | prompt 51 | 4 52 | x86 53 | Windows 54 | AllRules.ruleset 55 | 56 | 57 | pdbonly 58 | true 59 | bin\x86\Release 60 | TRACE 61 | prompt 62 | 4 63 | x86 64 | Windows 65 | bin\x86\Release\XNAnimationPipeline.XML 66 | AllRules.ruleset 67 | 68 | 69 | true 70 | full 71 | false 72 | bin\Xbox 360\Debug 73 | TRACE;DEBUG 74 | prompt 75 | 4 76 | false 77 | x86 78 | Xbox 360 79 | 80 | 81 | AllRules.ruleset 82 | 83 | 84 | pdbonly 85 | true 86 | bin\Xbox 360\Release 87 | TRACE 88 | prompt 89 | 4 90 | false 91 | x86 92 | Xbox 360 93 | AllRules.ruleset 94 | 95 | 96 | 97 | 98 | 99 | 100 | False 101 | 102 | 103 | 3.5 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | True 123 | True 124 | Resources.resx 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | False 144 | .NET Framework 3.5 SP1 Client Profile 145 | false 146 | 147 | 148 | False 149 | .NET Framework 2.0 %28x86%29 150 | true 151 | 152 | 153 | False 154 | .NET Framework 3.0 %28x86%29 155 | false 156 | 157 | 158 | False 159 | .NET Framework 3.5 160 | false 161 | 162 | 163 | False 164 | .NET Framework 3.5 SP1 165 | false 166 | 167 | 168 | 169 | 170 | ResXFileCodeGenerator 171 | Resources.Designer.cs 172 | 173 | 174 | 175 | 176 | {95228D3D-48C7-41B3-AE1D-01E018354C34} 177 | XNAnimation 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 192 | -------------------------------------------------------------------------------- /prototype/asvo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asvo", "asvo\asvo.csproj", "{774C0106-D108-489B-ADAB-A0113A33730A}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asvoContent", "asvo\Content\asvoContent.contentproj", "{E8BA59AD-F486-4922-B704-F057F24AC405}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XNAnimation", "XNAnimation\XNAnimation\XNAnimation.csproj", "{95228D3D-48C7-41B3-AE1D-01E018354C34}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XNAnimation", "XNAnimation", "{3A62BABE-CB1F-471A-AE49-0B88A0F606A9}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XNAnimationPipeline", "XNAnimation\XNAnimationPipeline\XNAnimationPipeline.csproj", "{06062F97-D86E-4FA6-BC0E-1F60666439CB}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|x86 = Debug|x86 17 | Debug|Xbox 360 = Debug|Xbox 360 18 | Release|x86 = Release|x86 19 | Release|Xbox 360 = Release|Xbox 360 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {774C0106-D108-489B-ADAB-A0113A33730A}.Debug|x86.ActiveCfg = Debug|x86 23 | {774C0106-D108-489B-ADAB-A0113A33730A}.Debug|x86.Build.0 = Debug|x86 24 | {774C0106-D108-489B-ADAB-A0113A33730A}.Debug|Xbox 360.ActiveCfg = Debug|x86 25 | {774C0106-D108-489B-ADAB-A0113A33730A}.Release|x86.ActiveCfg = Release|x86 26 | {774C0106-D108-489B-ADAB-A0113A33730A}.Release|x86.Build.0 = Release|x86 27 | {774C0106-D108-489B-ADAB-A0113A33730A}.Release|Xbox 360.ActiveCfg = Release|x86 28 | {E8BA59AD-F486-4922-B704-F057F24AC405}.Debug|x86.ActiveCfg = Debug|x86 29 | {E8BA59AD-F486-4922-B704-F057F24AC405}.Debug|Xbox 360.ActiveCfg = Debug|x86 30 | {E8BA59AD-F486-4922-B704-F057F24AC405}.Release|x86.ActiveCfg = Release|x86 31 | {E8BA59AD-F486-4922-B704-F057F24AC405}.Release|Xbox 360.ActiveCfg = Release|x86 32 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Debug|x86.ActiveCfg = Debug|x86 33 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Debug|x86.Build.0 = Debug|x86 34 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Debug|Xbox 360.ActiveCfg = Debug|x86 35 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Release|x86.ActiveCfg = Release|x86 36 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Release|x86.Build.0 = Release|x86 37 | {95228D3D-48C7-41B3-AE1D-01E018354C34}.Release|Xbox 360.ActiveCfg = Release|x86 38 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Debug|x86.ActiveCfg = Debug|x86 39 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Debug|x86.Build.0 = Debug|x86 40 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Debug|Xbox 360.ActiveCfg = Debug|Xbox 360 41 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Debug|Xbox 360.Build.0 = Debug|Xbox 360 42 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Release|x86.ActiveCfg = Release|x86 43 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Release|x86.Build.0 = Release|x86 44 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Release|Xbox 360.ActiveCfg = Release|Xbox 360 45 | {06062F97-D86E-4FA6-BC0E-1F60666439CB}.Release|Xbox 360.Build.0 = Release|Xbox 360 46 | EndGlobalSection 47 | GlobalSection(SolutionProperties) = preSolution 48 | HideSolutionNode = FALSE 49 | EndGlobalSection 50 | GlobalSection(NestedProjects) = preSolution 51 | {95228D3D-48C7-41B3-AE1D-01E018354C34} = {3A62BABE-CB1F-471A-AE49-0B88A0F606A9} 52 | {06062F97-D86E-4FA6-BC0E-1F60666439CB} = {3A62BABE-CB1F-471A-AE49-0B88A0F606A9} 53 | EndGlobalSection 54 | EndGlobal 55 | -------------------------------------------------------------------------------- /prototype/asvo/Content/asvoContent.contentproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | {E8BA59AD-F486-4922-B704-F057F24AC405} 5 | {96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 6 | Debug 7 | x86 8 | Library 9 | Properties 10 | v4.0 11 | v4.0 12 | x86 13 | bin\$(Platform)\$(Configuration) 14 | Content 15 | publish\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | 0 26 | 1.0.0.%2a 27 | false 28 | false 29 | true 30 | 31 | 32 | Windows 33 | AllRules.ruleset 34 | 35 | 36 | Windows 37 | AllRules.ruleset 38 | 39 | 40 | 41 | simple 42 | EffectImporter 43 | EffectProcessor 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | imrod_walk_high 57 | FbxImporter 58 | SkinnedModelProcessor 59 | 60 | 61 | 62 | 63 | False 64 | Microsoft .NET Framework 4 %28x86 and x64%29 65 | true 66 | 67 | 68 | False 69 | .NET Framework 3.5 SP1 Client Profile 70 | false 71 | 72 | 73 | False 74 | .NET Framework 3.5 SP1 75 | false 76 | 77 | 78 | False 79 | Windows Installer 3.1 80 | true 81 | 82 | 83 | 84 | 85 | {06062F97-D86E-4FA6-BC0E-1F60666439CB} 86 | XNAnimationPipeline 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /prototype/asvo/Content/imrod_walk_high.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/asvo/Content/imrod_walk_high.fbx -------------------------------------------------------------------------------- /prototype/asvo/Content/simple.fx: -------------------------------------------------------------------------------- 1 | /* 2 | Original code by Riemer Grootjans 3 | */ 4 | 5 | Texture colorTexture; 6 | sampler colorTextureSampler = sampler_state { 7 | texture = ; magfilter = POINT; minfilter = POINT; mipfilter=POINT; 8 | AddressU = CLAMP; AddressV = CLAMP; 9 | }; 10 | 11 | Texture depthTexture; 12 | sampler depthTextureSampler = sampler_state { 13 | texture = ; magfilter = POINT; minfilter = POINT; mipfilter=POINT; 14 | AddressU = CLAMP; AddressV = CLAMP; 15 | }; 16 | 17 | float pixelWidth; 18 | float pixelHeight; 19 | float4 fillColor; 20 | float maxDim; 21 | int horRes, vertRes; 22 | 23 | struct VertexToPixel 24 | { 25 | float4 Position : POSITION0; 26 | float2 TexCoords : TEXCOORD0; 27 | }; 28 | 29 | struct PixelToFrame 30 | { 31 | float4 Color : COLOR0; 32 | }; 33 | 34 | 35 | VertexToPixel SimplestVertexShader(float4 inPos : POSITION0, float2 inTexCoords : TEXCOORD0) 36 | { 37 | VertexToPixel Output = (VertexToPixel)0; 38 | 39 | Output.Position = inPos; 40 | Output.TexCoords = inTexCoords; 41 | 42 | return Output; 43 | } 44 | 45 | PixelToFrame OurFirstPixelShader(VertexToPixel PSIn) 46 | { 47 | PixelToFrame Output = (PixelToFrame)0; 48 | 49 | int radius = 1; 50 | const int radiusTimes2 = radius * 2; 51 | 52 | float min = 1.0f; 53 | Output.Color = fillColor; 54 | const float uStart = PSIn.TexCoords.x - radius * pixelWidth; 55 | float u = uStart; 56 | float v = PSIn.TexCoords.y - radius * pixelHeight; 57 | float uMin, vMin; 58 | 59 | for (int i = 0; i <= radiusTimes2; ++i) 60 | { 61 | for (int j = 0; j <= radiusTimes2; ++j) 62 | { 63 | float depth = tex2D(depthTextureSampler, float2(u, v)).r; 64 | if (depth < min) 65 | { 66 | min = depth; 67 | uMin = u; 68 | vMin = v; 69 | } 70 | u += pixelWidth; 71 | } 72 | u = uStart; 73 | v += pixelHeight; 74 | } 75 | 76 | if (min != 1.0f) 77 | Output.Color = tex2D(colorTextureSampler, float2(uMin, vMin)); 78 | 79 | return Output; 80 | } 81 | 82 | technique Simplest 83 | { 84 | pass Pass0 85 | { 86 | VertexShader = compile vs_3_0 SimplestVertexShader(); 87 | PixelShader = compile ps_3_0 OurFirstPixelShader(); 88 | } 89 | } -------------------------------------------------------------------------------- /prototype/asvo/DynamicOctree.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using asvo.world3D; 3 | using System.Collections.Generic; 4 | 5 | namespace asvo { 6 | namespace datastructures 7 | { 8 | /// 9 | /// Represents a tree data structure in which every node has up to 10 | /// 8 child nodes. 11 | /// Convention: 12 | /// 13 | /// 6---7 14 | /// / /| 15 | /// 2---3 5 16 | /// | |/ 17 | /// 0---1 18 | /// 19 | /// with: 20 | /// 21 | /// y z 22 | /// |/ 23 | /// 0-x (left handed coordinate system) 24 | /// 25 | /// This is a dynamic octree that can be altered at runtime and 26 | /// is intended for construction of 3D models. 27 | /// 28 | /// Every node has a pointer to its first child and a pointer to the 29 | /// next child of his parent node after it: 30 | /// 31 | /// parent->nil 32 | /// | 33 | /// node->parent's second child->parent's third child->nil 34 | /// | | 35 | /// node's first child-> ... parent's third child's 36 | /// ... first child 37 | /// 38 | /// Since the octree is sparse, nodes store the 39 | /// relative position to their parents. 40 | /// Every DynamicOctree is a cube. 41 | /// 42 | internal class DynamicOctree : DynamicOctreeNode 43 | { 44 | public readonly float dimension; 45 | 46 | /// 47 | /// Creates a new DynamicOctree with the specified dimension. 48 | /// 49 | /// Dimension of the bounding cube spanned by this octree. 50 | public DynamicOctree(float dimension) : base(0) 51 | { 52 | this.dimension = dimension; 53 | } 54 | } 55 | 56 | /// 57 | /// Represents an node of a DynamicOctree. 58 | /// 59 | internal class DynamicOctreeNode 60 | { 61 | private byte childCount; 62 | public readonly byte position; 63 | private DynamicOctreeNode firstChild; 64 | private DynamicOctreeNode nextNode; 65 | public VisualData vd; 66 | public float dist; 67 | 68 | /// 69 | /// Creates a new empty node with no child nodes. 70 | /// 71 | /// The position of this node relative to 72 | /// its parent. 73 | public DynamicOctreeNode(byte position) 74 | { 75 | childCount = 0; 76 | this.position = position; 77 | firstChild = null; 78 | nextNode = null; 79 | dist = float.MaxValue; 80 | } 81 | 82 | /// 83 | /// Returns whether this node has child nodes or not. 84 | /// 85 | /// true if this node has child nodes, false otherwise. 86 | public bool hasChildren() 87 | { 88 | return childCount > 0; 89 | } 90 | 91 | /// 92 | /// Returns the child count of this node. 93 | /// 94 | /// Child count of this node. 95 | public byte getChildCount() 96 | { 97 | return childCount; 98 | } 99 | 100 | /// 101 | /// Adds a child with the specified node to this 102 | /// node, iff there is no child node with position yet. 103 | /// In there is already such a node, it is returned. 104 | /// 105 | /// The position of the child node relative to this node. 106 | /// The child of this node with relative position . 107 | public DynamicOctreeNode addChild(byte withPos) 108 | { 109 | if (childCount == 0) 110 | { 111 | firstChild = new DynamicOctreeNode(withPos); 112 | ++childCount; 113 | return firstChild; 114 | } 115 | else 116 | { 117 | if (withPos < firstChild.position) 118 | { 119 | DynamicOctreeNode insert = new DynamicOctreeNode(withPos); 120 | insert.nextNode = firstChild; 121 | firstChild = insert; 122 | ++childCount; 123 | return insert; 124 | } 125 | else if (withPos == firstChild.position) 126 | return firstChild; 127 | 128 | DynamicOctreeNode currentNode = firstChild.nextNode; 129 | DynamicOctreeNode previousNode = firstChild; 130 | for (int i = 1; i < childCount; ++i) 131 | { 132 | if (withPos < currentNode.position) 133 | { 134 | DynamicOctreeNode insert = new DynamicOctreeNode(withPos); 135 | previousNode.nextNode = insert; 136 | insert.nextNode = currentNode; 137 | ++childCount; 138 | return insert; 139 | } 140 | else if (withPos == currentNode.position) 141 | { 142 | return currentNode; 143 | } 144 | else 145 | { 146 | currentNode = currentNode.nextNode; 147 | previousNode = previousNode.nextNode; 148 | } 149 | } 150 | 151 | previousNode.nextNode = new DynamicOctreeNode(withPos); 152 | ++childCount; 153 | return previousNode.nextNode; 154 | } 155 | } 156 | 157 | /// 158 | /// Returns the first child of this node. 159 | /// 160 | /// The first child of this node. Can be null. 161 | public DynamicOctreeNode getFirstChild() 162 | { 163 | return firstChild; 164 | } 165 | 166 | /// 167 | /// Returns the next child of this node's parent after this node. 168 | /// 169 | /// The next child of this node's parent after this node. Can be null. 170 | public DynamicOctreeNode getNextNode() 171 | { 172 | return nextNode; 173 | } 174 | 175 | /// 176 | /// Returns the total number of this node's children + 1. 177 | /// 178 | /// #children + 1 179 | public int getNodeCount() 180 | { 181 | int result = 1; 182 | 183 | DynamicOctreeNode child = firstChild; 184 | for (int i = 0; i < childCount; ++i) 185 | { 186 | result += child.getNodeCount(); 187 | child = child.nextNode; 188 | } 189 | 190 | return result; 191 | } 192 | 193 | /// 194 | /// Returns the total number of leaf nodes beneath this node. 195 | /// 196 | /// The total number of leaf nodes beneath this node. 197 | public uint getLeafCount() 198 | { 199 | uint result = childCount == 0 ? 1u : 0u; 200 | 201 | DynamicOctreeNode child = firstChild; 202 | for (int i = 0; i < childCount; ++i) 203 | { 204 | result += child.getLeafCount(); 205 | child = child.nextNode; 206 | } 207 | 208 | return result; 209 | } 210 | 211 | /// 212 | /// Returns the total number of pre-leaf nodes beneath this node. 213 | /// A pre-leaf is a node, whose children are leaves. 214 | /// 215 | /// The total number of pre-leaf nodes beneath this node. 216 | public uint getPreLeafCount() 217 | { 218 | uint result = (childCount > 0 && firstChild.childCount == 0) ? 1u : 0u; 219 | 220 | DynamicOctreeNode child = firstChild; 221 | for (int i = 0; i < childCount; ++i) 222 | { 223 | result += child.getPreLeafCount(); 224 | child = child.nextNode; 225 | } 226 | 227 | return result; 228 | } 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /prototype/asvo/Game.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denniskb/asvo/cdef2db10984dccff5a9f3295841563a78a2d3cd/prototype/asvo/Game.ico -------------------------------------------------------------------------------- /prototype/asvo/Game1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.GamerServices; 8 | using Microsoft.Xna.Framework.Graphics; 9 | using Microsoft.Xna.Framework.Input; 10 | using Microsoft.Xna.Framework.Media; 11 | using Microsoft.Xna.Framework.Net; 12 | using Microsoft.Xna.Framework.Storage; 13 | 14 | using asvo.datastructures; 15 | using asvo.renderers; 16 | using asvo.world3D; 17 | using asvo.multithreading; 18 | 19 | namespace asvo 20 | { 21 | /// 22 | /// This is the main type for your game 23 | /// 24 | public class Game1 : Microsoft.Xna.Framework.Game 25 | { 26 | GraphicsDeviceManager graphics; 27 | 28 | Rasterizer testRasterizer; 29 | Object3D testObj; 30 | TriangleMesh testMesh; 31 | 32 | Camera cam; 33 | 34 | private KeyboardState ks; 35 | 36 | /// 37 | /// Application for testing purposes. 38 | /// 39 | public Game1() 40 | { 41 | // Set necessary values. 42 | graphics = new GraphicsDeviceManager(this); 43 | Content.RootDirectory = "Content"; 44 | 45 | graphics.PreferredBackBufferWidth = 512; 46 | graphics.PreferredBackBufferHeight = 512; 47 | 48 | this.IsFixedTimeStep = false; 49 | graphics.SynchronizeWithVerticalRetrace = false; 50 | 51 | // Create as many threads as you have cores. 52 | // Used for rendering - greatly enhances performance. 53 | JobCenter.initializeWorkers(6); 54 | 55 | // Initialize the software-rasterizer. 56 | testRasterizer = new Rasterizer( 57 | graphics.PreferredBackBufferWidth, 58 | graphics.PreferredBackBufferHeight 59 | ); 60 | 61 | // Initialize the virtual camera. 62 | cam = new Camera(10, 200, new Vector3(0, 25, 80), new Vector3(0, 0, 0), 63 | ((float)graphics.PreferredBackBufferWidth) / 64 | graphics.PreferredBackBufferHeight); 65 | } 66 | 67 | /// 68 | /// Allows the game to perform any initialization it needs to before starting to run. 69 | /// This is where it can query for any required services and load any non-graphic 70 | /// related content. Calling base.Initialize will enumerate through any components 71 | /// and initialize them as well. 72 | /// 73 | protected override void Initialize() 74 | { 75 | base.Initialize(); 76 | } 77 | 78 | /// 79 | /// LoadContent will be called once per game and is the place to load 80 | /// all of your content. 81 | /// 82 | protected override void LoadContent() 83 | { 84 | // call LoadContent on all used components that implement it. 85 | testRasterizer.loadContent(GraphicsDevice, Content); 86 | 87 | // Load a triangle mesh. 88 | testMesh = new TriangleMesh("imrod_walk_high", Content); 89 | 90 | // Create a BFSOctree out of that mesh. 91 | testObj = new Object3D(testMesh.toBFSOctree(7), false); 92 | // Store the octree into a binary file. 93 | //testObj.getData().export("imrod.asvo"); 94 | testObj.rotate(Vector3.UnitX, MathHelper.PiOver2); 95 | 96 | System.GC.Collect(); 97 | ks = Keyboard.GetState(); 98 | } 99 | 100 | /// 101 | /// UnloadContent will be called once per game and is the place to unload 102 | /// all content. 103 | /// 104 | protected override void UnloadContent() 105 | { 106 | // TODO: Unload any non ContentManager content here 107 | } 108 | 109 | /// 110 | /// Allows the game to run logic such as updating the world, 111 | /// checking for collisions, gathering input, and playing audio. 112 | /// 113 | /// Provides a snapshot of timing values. 114 | protected override void Update(GameTime gameTime) 115 | { 116 | // Allows the game to exit 117 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 118 | this.Exit(); 119 | 120 | // Update camera movement. 121 | cam.update(gameTime, 122 | graphics.PreferredBackBufferWidth, 123 | graphics.PreferredBackBufferHeight); 124 | 125 | base.Update(gameTime); 126 | } 127 | 128 | /// 129 | /// This is called when the game should draw itself. 130 | /// 131 | /// Provides a snapshot of timing values. 132 | protected override void Draw(GameTime gameTime) 133 | { 134 | GraphicsDevice.Clear(Color.Black); 135 | 136 | // Control skinning animations with the keyboard: Pressing "down" advances the 137 | // animation by 1 frame. 138 | //if (ks.IsKeyUp(Keys.Down) && (ks = Keyboard.GetState()).IsKeyDown(Keys.Down)) 139 | testObj.frame = (int)((testObj.frame + 1) % testObj.getData().frameCount); 140 | //else 141 | //ks = Keyboard.GetState(); 142 | 143 | // Render the octree using the JobCenter 144 | JobCenter.assignJob(new RenderObjectJob(testObj, cam, testRasterizer)); 145 | JobCenter.wait(); 146 | JobCenter.assignJob(new MergeDepthBufferJob(testRasterizer)); 147 | JobCenter.wait(); 148 | 149 | // Draw the final image on the screen. 150 | testRasterizer.draw(GraphicsDevice); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /prototype/asvo/Object3d.cs: -------------------------------------------------------------------------------- 1 | using asvo.datastructures; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace asvo 5 | { 6 | namespace world3D 7 | { 8 | /// 9 | /// Represents a visible three dimensional object, such as 10 | /// a box, sphere, vehicle, NPC, ... 11 | /// Abstracts from the representation (like voxels) and encapsulates 12 | /// common operations on 3D objects like transformations. 13 | /// 14 | internal class Object3D 15 | { 16 | protected BFSOctree _representation; 17 | private Matrix _rotation, _translation, _transformation; 18 | public int frame; 19 | 20 | /// 21 | /// Creates a new 3D object consiting of the provided octree. 22 | /// After creation, its transformation matrices reflect its position and 23 | /// orientation in the world space coordinate system. 24 | /// 25 | /// The raw 3d data which represents the object in form of a BFSOctree. 26 | /// Indicates whether the calling 27 | /// framework uses a right-handed coordinate system and if therefore the 28 | /// object needs to be translated into this system, if false nothing happens as 29 | /// octree data is always provided in a left-handed manner. 30 | public Object3D(BFSOctree representation, bool rightHandedCoordinateSystem) 31 | { 32 | this._representation = representation; 33 | 34 | _rotation = _translation = Matrix.Identity; 35 | 36 | if (rightHandedCoordinateSystem) 37 | _rotation.M33 = -1.0f; 38 | 39 | updateTransformation(); 40 | } 41 | 42 | /// 43 | /// Returns the transformations of this object. Rotation is always applied before 44 | /// translation. 45 | /// 46 | /// Transformation (rotation * translation) of this object. 47 | public Matrix getTransformation() 48 | { 49 | return _transformation; 50 | } 51 | 52 | /// 53 | /// Returns the rotation matrix of this model only. 54 | /// Suitable for transforming normals. 55 | /// 56 | /// The rotation matrix of this object. 57 | public Matrix getRotation() 58 | { 59 | return _rotation; 60 | } 61 | 62 | /// 63 | /// Returns the raw 3d data that represents this object. 64 | /// 65 | /// 3D data representing this object in form of a BFSOctree. 66 | public BFSOctree getData() 67 | { 68 | return _representation; 69 | } 70 | 71 | /// 72 | /// Rotates the object around by . 73 | /// 74 | /// The axis to rotate this object around. 75 | /// The angle to rotate this object by. 76 | public void rotate(Vector3 axis, float angle) 77 | { 78 | Matrix rotationMatrix = Matrix.CreateFromAxisAngle(axis, angle); 79 | Matrix.Multiply(ref _rotation, ref rotationMatrix, out _rotation); 80 | 81 | updateTransformation(); 82 | } 83 | 84 | /// 85 | /// Translates this object by . 86 | /// 87 | /// The offset to translate this object by. 88 | public void translate(Vector3 offset) 89 | { 90 | Matrix translationMatrix = Matrix.CreateTranslation(offset); 91 | Matrix.Multiply(ref _translation, ref translationMatrix, out _translation); 92 | 93 | updateTransformation(); 94 | } 95 | 96 | /// 97 | /// Caches the transformations of this model after each modification of 98 | /// its position / orientation. 99 | /// 100 | private void updateTransformation() 101 | { 102 | _transformation = _rotation * _translation; 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /prototype/asvo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace asvo 4 | { 5 | static class Program 6 | { 7 | /// 8 | /// The main entry point for the application. 9 | /// 10 | static void Main(string[] args) 11 | { 12 | using (Game1 game = new Game1()) 13 | { 14 | game.Run(); 15 | } 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /prototype/asvo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("asvo")] 9 | [assembly: AssemblyProduct("asvo")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyCompany("anonymous")] 12 | 13 | [assembly: AssemblyCopyright("Copyright © anonymous 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9f84eca8-6c2d-441a-a8a3-56f339c6a549")] 24 | 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | [assembly: AssemblyVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /prototype/asvo/SharedDepthBuffer.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | using asvo.multithreading; 6 | 7 | namespace asvo 8 | { 9 | namespace datastructures 10 | { 11 | /// 12 | /// Represents a depth buffer that is accessable by multiple threads. 13 | /// Internally multiple depth buffers are stored so that each can 14 | /// be accessed by its own thread and no conflicts occur. 15 | /// These depth buffers are merged back into one (by computing 16 | /// max(depthBuffer0, ..., depthBufferN) for every element). 17 | /// 18 | internal class SharedDepthBuffer 19 | { 20 | public readonly float[][] _elements; 21 | public readonly float[] _maxDims; 22 | 23 | /// 24 | /// Constructs a new shared depth buffer with the size of elementCount 25 | /// 26 | /// The size of the buffer. 27 | public SharedDepthBuffer(int elementCount) 28 | { 29 | _elements = new float[JobCenter.getWorkerCount()][]; 30 | for (int i = 0; i < JobCenter.getWorkerCount(); ++i) 31 | _elements[i] = new float[elementCount]; 32 | 33 | _maxDims = new float[JobCenter.getWorkerCount()]; 34 | } 35 | 36 | /// 37 | /// Zeroes the depth buffer. 38 | /// 39 | /// Index of the calling thread, starts at 0 40 | public void zeroOut(int threadIndex) 41 | { 42 | for (int i = 0; i < _elements[threadIndex].Length; ++i) 43 | _elements[threadIndex][i] = 1.0f; 44 | 45 | _maxDims[threadIndex] = 0.0f; 46 | } 47 | 48 | /// 49 | /// Merges the results from the different threads into one array. Additionally, 50 | /// an array of 2D surfaces () is provided. Every 51 | /// element of this array was accessed by a different thread. The winning color at 52 | /// every pixel is derived from the winning (the smallest) depth at every pixel. 53 | /// 54 | /// Index of the calling thread, starts at 0. 55 | /// An array of 2D surfaces. 56 | public void merge(int threadIndex, Color[][] colorBuffer) 57 | { 58 | int start = (_elements[threadIndex].Length * threadIndex) / JobCenter.getWorkerCount(); 59 | int end = (_elements[threadIndex].Length * (threadIndex + 1)) / JobCenter.getWorkerCount(); 60 | 61 | float minDepth; 62 | int minColor = 0; 63 | for (int i = start; i < end; ++i) 64 | { 65 | minDepth = 1.0f; 66 | for (int j = 0; j < JobCenter.getWorkerCount(); ++j) 67 | { 68 | if (_elements[j][i] < minDepth) 69 | { 70 | minDepth = _elements[j][i]; 71 | minColor = j; 72 | } 73 | } 74 | _elements[0][i] = minDepth; 75 | colorBuffer[0][i] = colorBuffer[minColor][i]; 76 | } 77 | 78 | if (threadIndex == 0) 79 | { 80 | float maxDim = 0.0f; 81 | for (int i = 0; i < JobCenter.getWorkerCount(); ++i) 82 | { 83 | if (_maxDims[i] > maxDim) 84 | maxDim = _maxDims[i]; 85 | } 86 | _maxDims[0] = maxDim; 87 | } 88 | } 89 | } 90 | } 91 | } 92 | --------------------------------------------------------------------------------