collada: normalize cpp/hpp/fx to dos line endings
This commit is contained in:
parent
03b0299415
commit
0d1a363790
@ -1,580 +0,0 @@
|
||||
collada.types.Collada(
|
||||
library_animations=[],
|
||||
library_controllers=[],
|
||||
library_effects=[
|
||||
collada.types.LibraryEffects(
|
||||
id=None,
|
||||
name=None,
|
||||
effects=[
|
||||
collada.types.Effect(
|
||||
id='CubeMaterialTextured',
|
||||
name=None,
|
||||
profile_common=[
|
||||
collada.types.ProfileCommon(
|
||||
id=None,
|
||||
newparam=[
|
||||
collada.types.Newparam(
|
||||
sid='troll_cleric29_max2010_jpg-surface',
|
||||
parameter_type=collada.types.Surface(
|
||||
type=collada.types.FxSurfaceType._2D,
|
||||
init_from=collada.types.InitFrom(uri='troll_cleric29_max2010_jpg')
|
||||
)
|
||||
),
|
||||
collada.types.Newparam(
|
||||
sid='troll_cleric29_max2010_jpg-sampler',
|
||||
parameter_type=collada.types.Sampler2D(
|
||||
source=collada.types.SourceFX(sid='troll_cleric29_max2010_jpg-surface')
|
||||
)
|
||||
)
|
||||
],
|
||||
technique=collada.types.TechniqueFX(
|
||||
id=None,
|
||||
sid='common',
|
||||
shader=collada.types.Blinn(
|
||||
emission=collada.types.Color(value=(0.0, 0.0, 0.0, 1.0)),
|
||||
ambient=collada.types.Color(
|
||||
value=(0.8588236, 0.254902, 0.9137256, 1.0)
|
||||
),
|
||||
diffuse=collada.types.Texture(
|
||||
texture='troll_cleric29_max2010_jpg-sampler',
|
||||
texcoord='CHANNEL1'
|
||||
),
|
||||
specular=collada.types.Color(value=(0.0, 0.0, 0.0, 1.0)),
|
||||
shininess=collada.types.Float(value=10.0),
|
||||
reflective=collada.types.Color(value=(0.0, 0.0, 0.0, 1.0)),
|
||||
reflectivity=None,
|
||||
transparent=collada.types.Color(value=(1.0, 1.0, 1.0, 1.0)),
|
||||
transparency=collada.types.Float(value=1.0),
|
||||
index_of_refraction=None
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
library_materials=[
|
||||
collada.types.LibraryMaterials(
|
||||
id=None,
|
||||
name=None,
|
||||
materials=[
|
||||
collada.types.Material(
|
||||
id='CubeMaterialTextured-material',
|
||||
name='CubeMaterialTextured',
|
||||
instance_effect=collada.types.InstanceEffect(
|
||||
sid=None,
|
||||
name=None,
|
||||
url='#CubeMaterialTextured'
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
library_geometries=[
|
||||
collada.types.LibraryGeometries(
|
||||
id=None,
|
||||
name=None,
|
||||
geometries=[
|
||||
collada.types.Geometry(
|
||||
id='geom-Cube',
|
||||
name='Cube',
|
||||
geometric_element=collada.types.Mesh(
|
||||
sources=[
|
||||
collada.types.SourceCore(
|
||||
id='geom-Cube-positions',
|
||||
name=None,
|
||||
array_element=collada.types.FloatArray(
|
||||
count=24,
|
||||
id='geom-Cube-positions-array',
|
||||
name=None,
|
||||
digits=6,
|
||||
magnitude=38,
|
||||
floats=[
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.0,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.0,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.0,
|
||||
0.5,
|
||||
0.5,
|
||||
0.0,
|
||||
-0.5,
|
||||
-0.5,
|
||||
1.0,
|
||||
0.5,
|
||||
-0.5,
|
||||
1.0,
|
||||
-0.5,
|
||||
0.5,
|
||||
1.0,
|
||||
0.5,
|
||||
0.5,
|
||||
1.0
|
||||
]
|
||||
),
|
||||
technique_common=collada.types.TechniqueCommon_SourceCore(
|
||||
accessor=collada.types.Accessor(
|
||||
count=8,
|
||||
offset=0,
|
||||
source='#geom-Cube-positions-array',
|
||||
stride=3,
|
||||
params=[
|
||||
collada.types.Param(name='X', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='Y', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='Z', sid=None, type='float', semantic=None)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
collada.types.SourceCore(
|
||||
id='geom-Cube-normals',
|
||||
name=None,
|
||||
array_element=collada.types.FloatArray(
|
||||
count=72,
|
||||
id='geom-Cube-normals-array',
|
||||
name=None,
|
||||
digits=6,
|
||||
magnitude=38,
|
||||
floats=[
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
0.0
|
||||
]
|
||||
),
|
||||
technique_common=collada.types.TechniqueCommon_SourceCore(
|
||||
accessor=collada.types.Accessor(
|
||||
count=24,
|
||||
offset=0,
|
||||
source='#geom-Cube-normals-array',
|
||||
stride=3,
|
||||
params=[
|
||||
collada.types.Param(name='X', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='Y', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='Z', sid=None, type='float', semantic=None)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
collada.types.SourceCore(
|
||||
id='geom-Cube-map1',
|
||||
name=None,
|
||||
array_element=collada.types.FloatArray(
|
||||
count=36,
|
||||
id='geom-Cube-map1-array',
|
||||
name=None,
|
||||
digits=6,
|
||||
magnitude=38,
|
||||
floats=[
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0
|
||||
]
|
||||
),
|
||||
technique_common=collada.types.TechniqueCommon_SourceCore(
|
||||
accessor=collada.types.Accessor(
|
||||
count=12,
|
||||
offset=0,
|
||||
source='#geom-Cube-map1-array',
|
||||
stride=3,
|
||||
params=[
|
||||
collada.types.Param(name='S', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='T', sid=None, type='float', semantic=None),
|
||||
collada.types.Param(name='P', sid=None, type='float', semantic=None)
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
vertices=collada.types.Vertices(
|
||||
id='geom-Cube-vertices',
|
||||
name=None,
|
||||
inputs=[
|
||||
collada.types.InputUnshared(
|
||||
semantic='POSITION',
|
||||
source='#geom-Cube-positions'
|
||||
)
|
||||
]
|
||||
),
|
||||
primitive_elements=[
|
||||
collada.types.Triangles(
|
||||
name=None,
|
||||
count=12,
|
||||
material='CubeMaterialTextured',
|
||||
inputs=[
|
||||
collada.types.InputShared(
|
||||
offset=0,
|
||||
semantic='VERTEX',
|
||||
source='#geom-Cube-vertices',
|
||||
set=None
|
||||
),
|
||||
collada.types.InputShared(
|
||||
offset=1,
|
||||
semantic='NORMAL',
|
||||
source='#geom-Cube-normals',
|
||||
set=None
|
||||
),
|
||||
collada.types.InputShared(
|
||||
offset=2,
|
||||
semantic='TEXCOORD',
|
||||
source='#geom-Cube-map1',
|
||||
set=0
|
||||
)
|
||||
],
|
||||
p=[
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
2,
|
||||
1,
|
||||
11,
|
||||
3,
|
||||
2,
|
||||
10,
|
||||
3,
|
||||
2,
|
||||
10,
|
||||
1,
|
||||
3,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
9,
|
||||
4,
|
||||
4,
|
||||
8,
|
||||
5,
|
||||
5,
|
||||
9,
|
||||
7,
|
||||
6,
|
||||
11,
|
||||
7,
|
||||
6,
|
||||
11,
|
||||
6,
|
||||
7,
|
||||
10,
|
||||
4,
|
||||
4,
|
||||
8,
|
||||
0,
|
||||
8,
|
||||
4,
|
||||
1,
|
||||
9,
|
||||
5,
|
||||
5,
|
||||
10,
|
||||
7,
|
||||
5,
|
||||
10,
|
||||
7,
|
||||
4,
|
||||
11,
|
||||
6,
|
||||
0,
|
||||
8,
|
||||
4,
|
||||
1,
|
||||
12,
|
||||
0,
|
||||
3,
|
||||
13,
|
||||
1,
|
||||
7,
|
||||
14,
|
||||
3,
|
||||
7,
|
||||
14,
|
||||
3,
|
||||
5,
|
||||
15,
|
||||
2,
|
||||
1,
|
||||
12,
|
||||
0,
|
||||
3,
|
||||
16,
|
||||
4,
|
||||
2,
|
||||
17,
|
||||
5,
|
||||
6,
|
||||
18,
|
||||
7,
|
||||
6,
|
||||
18,
|
||||
7,
|
||||
7,
|
||||
19,
|
||||
6,
|
||||
3,
|
||||
16,
|
||||
4,
|
||||
2,
|
||||
20,
|
||||
0,
|
||||
0,
|
||||
21,
|
||||
1,
|
||||
4,
|
||||
22,
|
||||
3,
|
||||
4,
|
||||
22,
|
||||
3,
|
||||
6,
|
||||
23,
|
||||
2,
|
||||
2,
|
||||
20,
|
||||
0
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
library_lights=[
|
||||
collada.types.LibraryLights(
|
||||
id=None,
|
||||
name=None,
|
||||
lights=[
|
||||
collada.types.Light(
|
||||
id='EnvironmentAmbientLight',
|
||||
name='EnvironmentAmbientLight',
|
||||
technique_common=collada.types.TechniqueCommon_Light(
|
||||
light=collada.types.Ambient(color=(0.0, 0.0, 0.0))
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
library_images=[
|
||||
collada.types.LibraryImages(
|
||||
id=None,
|
||||
name=None,
|
||||
images=[
|
||||
collada.types.Image(
|
||||
id='troll_cleric29_max2010_jpg',
|
||||
name=None,
|
||||
format=None,
|
||||
height=None,
|
||||
width=None,
|
||||
depth=None,
|
||||
image_source=collada.types.InitFrom(
|
||||
uri='file:///C:/cygwin/home/bilbo/collada/images/0_troll_cleric29_max2010.'
|
||||
'jpg'
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
library_visual_scenes=[
|
||||
collada.types.LibraryVisualScenes(
|
||||
id=None,
|
||||
name=None,
|
||||
visual_scenes=[
|
||||
collada.types.VisualScene(
|
||||
id='MaxScene',
|
||||
name=None,
|
||||
nodes=[
|
||||
collada.types.Node(
|
||||
id=None,
|
||||
name='EnvironmentAmbientLight',
|
||||
sid=None,
|
||||
type=collada.types.NodeType.NODE,
|
||||
layer=[],
|
||||
transformation_elements=[],
|
||||
instance_geometries=[],
|
||||
instance_lights=[
|
||||
collada.types.InstanceLight(
|
||||
sid=None,
|
||||
name=None,
|
||||
url='#EnvironmentAmbientLight'
|
||||
)
|
||||
],
|
||||
nodes=[]
|
||||
),
|
||||
collada.types.Node(
|
||||
id='node-Cube',
|
||||
name='Cube',
|
||||
sid=None,
|
||||
type=collada.types.NodeType.NODE,
|
||||
layer=[],
|
||||
transformation_elements=[],
|
||||
instance_geometries=[],
|
||||
instance_lights=[],
|
||||
nodes=[
|
||||
collada.types.Node(
|
||||
id=None,
|
||||
name=None,
|
||||
sid=None,
|
||||
type=collada.types.NodeType.NODE,
|
||||
layer=[],
|
||||
transformation_elements=[
|
||||
collada.types.Matrix(
|
||||
sid=None,
|
||||
values=(
|
||||
(1.0, 0.0, 0.0, 0.0),
|
||||
(0.0, 1.0, -4.37114e-08, 2.18557e-08),
|
||||
(0.0, 4.37114e-08, 1.0, -0.5),
|
||||
(0.0, 0.0, 0.0, 1.0)
|
||||
)
|
||||
)
|
||||
],
|
||||
instance_geometries=[
|
||||
collada.types.InstanceGeometry(
|
||||
sid=None,
|
||||
name=None,
|
||||
url='#geom-Cube',
|
||||
bind_material=collada.types.BindMaterial(
|
||||
technique_common=collada.types.TechniqueCommon_BindMaterial(
|
||||
materials=[
|
||||
collada.types.InstanceMaterial(
|
||||
sid=None,
|
||||
name=None,
|
||||
target='#CubeMaterialTextured-material',
|
||||
symbol='CubeMaterialTextured',
|
||||
bind_vertex_inputs=[
|
||||
collada.types.BindVertexInput(
|
||||
semantic='CHANNEL1',
|
||||
input_semantic='TEXCOORD',
|
||||
input_set='0'
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
],
|
||||
instance_lights=[],
|
||||
nodes=[]
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
scenes=[
|
||||
collada.types.Scene(
|
||||
instance_visual_scene=collada.types.InstanceVisualScene(
|
||||
sid=None,
|
||||
name=None,
|
||||
url='#MaxScene'
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef COLLADA_HPP_
|
||||
#define COLLADA_HPP_
|
||||
|
||||
namespace collada {
|
||||
HRESULT LoadEffect();
|
||||
HRESULT LoadMesh();
|
||||
void Render(float t);
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef COLLADA_HPP_
|
||||
#define COLLADA_HPP_
|
||||
|
||||
namespace collada {
|
||||
HRESULT LoadEffect();
|
||||
HRESULT LoadMesh();
|
||||
void Render(float t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,239 +1,239 @@
|
||||
#pragma once
|
||||
|
||||
namespace collada {
|
||||
|
||||
struct float3 {
|
||||
float const x;
|
||||
float const y;
|
||||
float const z;
|
||||
};
|
||||
|
||||
struct float4 {
|
||||
float const x;
|
||||
float const y;
|
||||
float const z;
|
||||
float const w;
|
||||
};
|
||||
|
||||
struct float7 {
|
||||
float const a;
|
||||
float const b;
|
||||
float const c;
|
||||
float const d;
|
||||
float const e;
|
||||
float const f;
|
||||
float const g;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// animation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class interpolation {
|
||||
LINEAR,
|
||||
BEZIER,
|
||||
};
|
||||
|
||||
struct source {
|
||||
union {
|
||||
float const * const float_array;
|
||||
enum interpolation const name_array;
|
||||
};
|
||||
int const count;
|
||||
int const stride;
|
||||
};
|
||||
|
||||
struct sampler {
|
||||
source const input;
|
||||
source const output;
|
||||
source const intangent;
|
||||
source const outangent;
|
||||
source const interpolation;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// geometry
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class input_format {
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
INT4,
|
||||
};
|
||||
|
||||
struct input_element {
|
||||
char const * const semantic;
|
||||
int const semantic_index;
|
||||
enum input_format const format;
|
||||
};
|
||||
|
||||
// inputs uniqueness is by evaluted pointer
|
||||
struct inputs {
|
||||
input_element const * const elements;
|
||||
int const elements_count;
|
||||
};
|
||||
|
||||
struct triangles {
|
||||
int const count;
|
||||
int const index_offset;
|
||||
inputs const inputs;
|
||||
};
|
||||
|
||||
struct mesh {
|
||||
// `triangles` must become a union if non-triangles are implemented.
|
||||
// instance_geometry is an index into this array.
|
||||
triangles const * triangles;
|
||||
int const triangles_count;
|
||||
|
||||
int const vertex_buffer_offset;
|
||||
int const vertex_buffer_size;
|
||||
|
||||
int const index_buffer_offset;
|
||||
int const index_buffer_size;
|
||||
};
|
||||
|
||||
struct geometry {
|
||||
mesh mesh;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// node
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct lookat {
|
||||
float3 const eye;
|
||||
float3 const at;
|
||||
float3 const up;
|
||||
};
|
||||
|
||||
struct matrix {
|
||||
float const _11, _12, _13, _14;
|
||||
float const _21, _22, _23, _24;
|
||||
float const _31, _32, _33, _34;
|
||||
float const _41, _42, _43, _44;
|
||||
};
|
||||
|
||||
enum class transform_type {
|
||||
LOOKAT,
|
||||
MATRIX,
|
||||
ROTATE,
|
||||
SCALE,
|
||||
TRANSLATE,
|
||||
};
|
||||
|
||||
struct transform {
|
||||
transform_type const type;
|
||||
union {
|
||||
lookat const lookat;
|
||||
matrix const matrix;
|
||||
float4 const rotate;
|
||||
float3 const scale;
|
||||
float7 const skew;
|
||||
float3 const translate;
|
||||
};
|
||||
};
|
||||
|
||||
enum class node_type {
|
||||
JOINT,
|
||||
NODE,
|
||||
};
|
||||
|
||||
|
||||
struct color_or_texture {
|
||||
union {
|
||||
float4 color;
|
||||
};
|
||||
};
|
||||
|
||||
struct blinn {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const specular;
|
||||
float const shininess;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct lambert {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct phong {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const specular;
|
||||
float const shininess;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct constant {
|
||||
float4 const color;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
enum class effect_type {
|
||||
BLINN,
|
||||
LAMBERT,
|
||||
PHONG,
|
||||
CONSTANT,
|
||||
};
|
||||
|
||||
struct effect {
|
||||
effect_type const type;
|
||||
union {
|
||||
blinn const blinn;
|
||||
lambert const lambert;
|
||||
phong const phong;
|
||||
constant const constant;
|
||||
};
|
||||
};
|
||||
|
||||
struct material {
|
||||
effect const * const effect;
|
||||
};
|
||||
|
||||
struct instance_material {
|
||||
int element_index;
|
||||
material const * const material;
|
||||
};
|
||||
|
||||
struct instance_geometry {
|
||||
geometry const * const geometry;
|
||||
|
||||
instance_material const * const instance_materials;
|
||||
int const instance_materials_count;
|
||||
};
|
||||
|
||||
struct node {
|
||||
node_type const type;
|
||||
|
||||
transform const * const transforms;
|
||||
int const transforms_count;
|
||||
|
||||
instance_geometry const * const instance_geometries;
|
||||
int const instance_geometries_count;
|
||||
|
||||
node const * const nodes;
|
||||
int const nodes_count;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
namespace collada {
|
||||
|
||||
struct float3 {
|
||||
float const x;
|
||||
float const y;
|
||||
float const z;
|
||||
};
|
||||
|
||||
struct float4 {
|
||||
float const x;
|
||||
float const y;
|
||||
float const z;
|
||||
float const w;
|
||||
};
|
||||
|
||||
struct float7 {
|
||||
float const a;
|
||||
float const b;
|
||||
float const c;
|
||||
float const d;
|
||||
float const e;
|
||||
float const f;
|
||||
float const g;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// animation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class interpolation {
|
||||
LINEAR,
|
||||
BEZIER,
|
||||
};
|
||||
|
||||
struct source {
|
||||
union {
|
||||
float const * const float_array;
|
||||
enum interpolation const name_array;
|
||||
};
|
||||
int const count;
|
||||
int const stride;
|
||||
};
|
||||
|
||||
struct sampler {
|
||||
source const input;
|
||||
source const output;
|
||||
source const intangent;
|
||||
source const outangent;
|
||||
source const interpolation;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// geometry
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class input_format {
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
INT4,
|
||||
};
|
||||
|
||||
struct input_element {
|
||||
char const * const semantic;
|
||||
int const semantic_index;
|
||||
enum input_format const format;
|
||||
};
|
||||
|
||||
// inputs uniqueness is by evaluted pointer
|
||||
struct inputs {
|
||||
input_element const * const elements;
|
||||
int const elements_count;
|
||||
};
|
||||
|
||||
struct triangles {
|
||||
int const count;
|
||||
int const index_offset;
|
||||
inputs const inputs;
|
||||
};
|
||||
|
||||
struct mesh {
|
||||
// `triangles` must become a union if non-triangles are implemented.
|
||||
// instance_geometry is an index into this array.
|
||||
triangles const * triangles;
|
||||
int const triangles_count;
|
||||
|
||||
int const vertex_buffer_offset;
|
||||
int const vertex_buffer_size;
|
||||
|
||||
int const index_buffer_offset;
|
||||
int const index_buffer_size;
|
||||
};
|
||||
|
||||
struct geometry {
|
||||
mesh mesh;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// node
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct lookat {
|
||||
float3 const eye;
|
||||
float3 const at;
|
||||
float3 const up;
|
||||
};
|
||||
|
||||
struct matrix {
|
||||
float const _11, _12, _13, _14;
|
||||
float const _21, _22, _23, _24;
|
||||
float const _31, _32, _33, _34;
|
||||
float const _41, _42, _43, _44;
|
||||
};
|
||||
|
||||
enum class transform_type {
|
||||
LOOKAT,
|
||||
MATRIX,
|
||||
ROTATE,
|
||||
SCALE,
|
||||
TRANSLATE,
|
||||
};
|
||||
|
||||
struct transform {
|
||||
transform_type const type;
|
||||
union {
|
||||
lookat const lookat;
|
||||
matrix const matrix;
|
||||
float4 const rotate;
|
||||
float3 const scale;
|
||||
float7 const skew;
|
||||
float3 const translate;
|
||||
};
|
||||
};
|
||||
|
||||
enum class node_type {
|
||||
JOINT,
|
||||
NODE,
|
||||
};
|
||||
|
||||
|
||||
struct color_or_texture {
|
||||
union {
|
||||
float4 color;
|
||||
};
|
||||
};
|
||||
|
||||
struct blinn {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const specular;
|
||||
float const shininess;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct lambert {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct phong {
|
||||
color_or_texture const emission;
|
||||
color_or_texture const ambient;
|
||||
color_or_texture const diffuse;
|
||||
color_or_texture const specular;
|
||||
float const shininess;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
struct constant {
|
||||
float4 const color;
|
||||
color_or_texture const reflective;
|
||||
float const reflectivity;
|
||||
color_or_texture const transparent;
|
||||
float const transparency;
|
||||
float const index_of_refraction;
|
||||
};
|
||||
|
||||
enum class effect_type {
|
||||
BLINN,
|
||||
LAMBERT,
|
||||
PHONG,
|
||||
CONSTANT,
|
||||
};
|
||||
|
||||
struct effect {
|
||||
effect_type const type;
|
||||
union {
|
||||
blinn const blinn;
|
||||
lambert const lambert;
|
||||
phong const phong;
|
||||
constant const constant;
|
||||
};
|
||||
};
|
||||
|
||||
struct material {
|
||||
effect const * const effect;
|
||||
};
|
||||
|
||||
struct instance_material {
|
||||
int element_index;
|
||||
material const * const material;
|
||||
};
|
||||
|
||||
struct instance_geometry {
|
||||
geometry const * const geometry;
|
||||
|
||||
instance_material const * const instance_materials;
|
||||
int const instance_materials_count;
|
||||
};
|
||||
|
||||
struct node {
|
||||
node_type const type;
|
||||
|
||||
transform const * const transforms;
|
||||
int const transforms_count;
|
||||
|
||||
instance_geometry const * const instance_geometries;
|
||||
int const instance_geometries_count;
|
||||
|
||||
node const * const nodes;
|
||||
int const nodes_count;
|
||||
};
|
||||
}
|
||||
|
||||
724
src/collada.cpp
724
src/collada.cpp
@ -1,362 +1,362 @@
|
||||
#include <windows.h>
|
||||
#include <d3d10.h>
|
||||
|
||||
#include "directxmath/directxmath.h"
|
||||
|
||||
#include "print.hpp"
|
||||
#include "collada.hpp"
|
||||
|
||||
extern ID3D10Device * g_pd3dDevice;
|
||||
extern XMMATRIX g_View;
|
||||
extern XMMATRIX g_Projection;
|
||||
|
||||
namespace collada {
|
||||
static const float vertex_buffer[] = {
|
||||
-5.0, -5.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0,
|
||||
-5.0, 5.0, 0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 0.0,
|
||||
5.0, 5.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0,
|
||||
5.0, -5.0, 0.0, 0.0, 0.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5.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
-5.0, -5.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
||||
-5.0, -5.0, 4.0, -1.0, 0.0, 0.0, 1.0, 0.2, 0.0,
|
||||
-5.0, 5.0, 4.0, -1.0, 0.0, 0.0, 0.0, 0.2, 0.0,
|
||||
-5.0, -5.0, 8.0, -1.0, 0.0, 0.0, 1.0, 0.4, 0.0,
|
||||
-5.0, 5.0, 8.0, -1.0, 0.0, 0.0, 0.0, 0.4, 0.0,
|
||||
-5.0, -5.0, 12.0, -1.0, 0.0, 0.0, 1.0, 0.6, 0.0,
|
||||
-5.0, 5.0, 12.0, -1.0, 0.0, 0.0, 0.0, 0.6, 0.0,
|
||||
-5.0, -5.0, 16.0, -1.0, 0.0, 0.0, 1.0, 0.8, 0.0,
|
||||
-5.0, 5.0, 16.0, -1.0, 0.0, 0.0, 0.0, 0.8, 0.0,
|
||||
-5.0, -5.0, 20.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
|
||||
-5.0, 5.0, 20.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
|
||||
};
|
||||
|
||||
static const int index_buffer[] = {
|
||||
0, 1, 2,
|
||||
2, 3, 0,
|
||||
4, 5, 6,
|
||||
6, 7, 4,
|
||||
8, 9, 10,
|
||||
10, 11, 8,
|
||||
11, 10, 12,
|
||||
12, 13, 11,
|
||||
13, 12, 14,
|
||||
14, 15, 13,
|
||||
15, 14, 16,
|
||||
16, 17, 15,
|
||||
17, 16, 18,
|
||||
18, 19, 17,
|
||||
20, 21, 22,
|
||||
22, 23, 20,
|
||||
23, 22, 24,
|
||||
24, 25, 23,
|
||||
25, 24, 26,
|
||||
26, 27, 25,
|
||||
27, 26, 28,
|
||||
28, 29, 27,
|
||||
29, 28, 30,
|
||||
30, 31, 29,
|
||||
32, 33, 34,
|
||||
34, 35, 32,
|
||||
35, 34, 36,
|
||||
36, 37, 35,
|
||||
37, 36, 38,
|
||||
38, 39, 37,
|
||||
39, 38, 40,
|
||||
40, 41, 39,
|
||||
41, 40, 42,
|
||||
42, 43, 41,
|
||||
44, 45, 46,
|
||||
46, 47, 44,
|
||||
47, 46, 48,
|
||||
48, 49, 47,
|
||||
49, 48, 50,
|
||||
50, 51, 49,
|
||||
51, 50, 52,
|
||||
52, 53, 51,
|
||||
53, 52, 54,
|
||||
54, 55, 53,
|
||||
};
|
||||
|
||||
static const float inverse_bind_matrices[] = {
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
-10.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
static const float joints_weights[] = {
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0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, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
};
|
||||
|
||||
ID3D10Effect * g_pEffect = NULL;
|
||||
ID3D10EffectTechnique * g_pTechniqueRender = NULL;
|
||||
ID3D10InputLayout * g_pVertexLayout = NULL;
|
||||
|
||||
ID3D10Buffer * g_pVertexBufferPNT;
|
||||
ID3D10Buffer * g_pVertexBufferJW;
|
||||
ID3D10Buffer * g_pIndexBuffer;
|
||||
|
||||
ID3D10EffectMatrixVariable * g_pJointVariable = NULL;
|
||||
|
||||
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pViewVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pProjectionVariable = NULL;
|
||||
|
||||
HRESULT LoadEffect()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
HRSRC hRes = FindResource(NULL, L"RES_COLLADA_FXO", RT_RCDATA);
|
||||
if (hRes == NULL) {
|
||||
print("FindResource RES_COLLADA_FXO\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
DWORD dwResSize = SizeofResource(NULL, hRes);
|
||||
HGLOBAL hData = LoadResource(NULL, hRes);
|
||||
void * pData = LockResource(hData);
|
||||
hr = D3D10CreateEffectFromMemory(pData,
|
||||
dwResSize,
|
||||
0,
|
||||
g_pd3dDevice,
|
||||
NULL,
|
||||
&g_pEffect
|
||||
);
|
||||
if (FAILED(hr)) {
|
||||
print("D3D10CreateEffectFromMemory\n");
|
||||
return hr;
|
||||
}
|
||||
g_pTechniqueRender = g_pEffect->GetTechniqueByName("Render");
|
||||
|
||||
// variables
|
||||
g_pJointVariable = g_pEffect->GetVariableByName("mJoint")->AsMatrix();
|
||||
|
||||
g_pWorldVariable = g_pEffect->GetVariableByName("World")->AsMatrix();
|
||||
g_pViewVariable = g_pEffect->GetVariableByName("View")->AsMatrix();
|
||||
g_pProjectionVariable = g_pEffect->GetVariableByName("Projection")->AsMatrix();
|
||||
|
||||
// layout
|
||||
D3D10_INPUT_ELEMENT_DESC layout[] = {
|
||||
{"POSITION" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"NORMAL" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"TEXCOORD" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDWEIGHT" , 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
UINT numElements = (sizeof (layout)) / (sizeof (layout[0]));
|
||||
|
||||
D3D10_PASS_DESC passDesc;
|
||||
g_pTechniqueRender->GetPassByIndex(0)->GetDesc(&passDesc);
|
||||
|
||||
hr = g_pd3dDevice->CreateInputLayout(layout, numElements,
|
||||
passDesc.pIAInputSignature,
|
||||
passDesc.IAInputSignatureSize,
|
||||
&g_pVertexLayout);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateInputLayout\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT LoadMesh()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
D3D10_SUBRESOURCE_DATA initData;
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (vertex_buffer));
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = vertex_buffer;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pVertexBufferPNT);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_VERTEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (joints_weights));
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = joints_weights;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pVertexBufferJW);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_VERTEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (index_buffer));
|
||||
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = index_buffer;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pIndexBuffer);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_INDEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void Render(float t)
|
||||
{
|
||||
XMMATRIX World = XMMatrixScaling(1, 1, 1);
|
||||
|
||||
// XMMATRIX XM_CALLCONV XMMatrixRotationNormal(FXMVECTOR NormalAxis, float Angle) noexcept;
|
||||
//XMConvertToRadians
|
||||
XMVECTOR axis = XMVectorSet(0, 1, 0, 0);
|
||||
XMVECTOR axisZ = XMVectorSet(0, 0, 1, 0);
|
||||
XMMATRIX joint0
|
||||
= XMMatrixRotationNormal(axis, XMConvertToRadians(-90))
|
||||
;
|
||||
XMMATRIX joint1
|
||||
= XMMatrixRotationNormal(axisZ, sin(t))
|
||||
* XMMatrixTranslation(10, 0, 0)
|
||||
* joint0
|
||||
;
|
||||
|
||||
XMMATRIX joint0ibm = XMLoadFloat4x4((XMFLOAT4X4*)&inverse_bind_matrices[0 * 16]);
|
||||
XMMATRIX joint1ibm = XMLoadFloat4x4((XMFLOAT4X4*)&inverse_bind_matrices[1 * 16]);
|
||||
XMMATRIX mJoints[2] = {
|
||||
joint0ibm * joint0,
|
||||
joint1ibm * joint1,
|
||||
};
|
||||
|
||||
g_pJointVariable->SetMatrixArray((float *)mJoints, 0, 2);
|
||||
|
||||
g_pWorldVariable->SetMatrix((float *)&World);
|
||||
g_pViewVariable->SetMatrix((float *)&g_View);
|
||||
g_pProjectionVariable->SetMatrix((float *)&g_Projection);
|
||||
|
||||
UINT stride[] = {
|
||||
3 * 3 * 4, // position normal texture
|
||||
4 * 2 * 4, // joint weight
|
||||
};
|
||||
UINT offset[] = { 0, 0 };
|
||||
ID3D10Buffer * vertex_buffers[] = {
|
||||
g_pVertexBufferPNT,
|
||||
g_pVertexBufferJW,
|
||||
};
|
||||
|
||||
g_pd3dDevice->IASetInputLayout(g_pVertexLayout);
|
||||
g_pd3dDevice->IASetVertexBuffers(0, 2, vertex_buffers, stride, offset);
|
||||
g_pd3dDevice->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
D3D10_TECHNIQUE_DESC techDesc;
|
||||
g_pTechniqueRender->GetDesc(&techDesc);
|
||||
|
||||
int indices_length = (sizeof (index_buffer)) / (sizeof (int));
|
||||
for (UINT p = 0; p < techDesc.Passes; p++) {
|
||||
g_pTechniqueRender->GetPassByIndex(p)->Apply(0);
|
||||
g_pd3dDevice->DrawIndexed(indices_length, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include <windows.h>
|
||||
#include <d3d10.h>
|
||||
|
||||
#include "directxmath/directxmath.h"
|
||||
|
||||
#include "print.hpp"
|
||||
#include "collada.hpp"
|
||||
|
||||
extern ID3D10Device * g_pd3dDevice;
|
||||
extern XMMATRIX g_View;
|
||||
extern XMMATRIX g_Projection;
|
||||
|
||||
namespace collada {
|
||||
static const float vertex_buffer[] = {
|
||||
-5.0, -5.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0,
|
||||
-5.0, 5.0, 0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 0.0,
|
||||
5.0, 5.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0,
|
||||
5.0, -5.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0,
|
||||
-5.0, -5.0, 20.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
|
||||
5.0, -5.0, 20.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
|
||||
5.0, 5.0, 20.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
|
||||
-5.0, 5.0, 20.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0,
|
||||
-5.0, -5.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0,
|
||||
5.0, -5.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0,
|
||||
5.0, -5.0, 4.0, 0.0, -1.0, 0.0, 1.0, 0.2, 0.0,
|
||||
-5.0, -5.0, 4.0, 0.0, -1.0, 0.0, 0.0, 0.2, 0.0,
|
||||
5.0, -5.0, 8.0, 0.0, -1.0, 0.0, 1.0, 0.4, 0.0,
|
||||
-5.0, -5.0, 8.0, 0.0, -1.0, 0.0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.0, 20.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
|
||||
-5.0, 5.0, 20.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
|
||||
};
|
||||
|
||||
static const int index_buffer[] = {
|
||||
0, 1, 2,
|
||||
2, 3, 0,
|
||||
4, 5, 6,
|
||||
6, 7, 4,
|
||||
8, 9, 10,
|
||||
10, 11, 8,
|
||||
11, 10, 12,
|
||||
12, 13, 11,
|
||||
13, 12, 14,
|
||||
14, 15, 13,
|
||||
15, 14, 16,
|
||||
16, 17, 15,
|
||||
17, 16, 18,
|
||||
18, 19, 17,
|
||||
20, 21, 22,
|
||||
22, 23, 20,
|
||||
23, 22, 24,
|
||||
24, 25, 23,
|
||||
25, 24, 26,
|
||||
26, 27, 25,
|
||||
27, 26, 28,
|
||||
28, 29, 27,
|
||||
29, 28, 30,
|
||||
30, 31, 29,
|
||||
32, 33, 34,
|
||||
34, 35, 32,
|
||||
35, 34, 36,
|
||||
36, 37, 35,
|
||||
37, 36, 38,
|
||||
38, 39, 37,
|
||||
39, 38, 40,
|
||||
40, 41, 39,
|
||||
41, 40, 42,
|
||||
42, 43, 41,
|
||||
44, 45, 46,
|
||||
46, 47, 44,
|
||||
47, 46, 48,
|
||||
48, 49, 47,
|
||||
49, 48, 50,
|
||||
50, 51, 49,
|
||||
51, 50, 52,
|
||||
52, 53, 51,
|
||||
53, 52, 54,
|
||||
54, 55, 53,
|
||||
};
|
||||
|
||||
static const float inverse_bind_matrices[] = {
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
0.0f, 0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
-10.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
|
||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 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.2, 0.8, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.4, 0.6, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.6, 0.4, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 0.8, 0.2, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1.0, 0, 0, 0,
|
||||
};
|
||||
|
||||
ID3D10Effect * g_pEffect = NULL;
|
||||
ID3D10EffectTechnique * g_pTechniqueRender = NULL;
|
||||
ID3D10InputLayout * g_pVertexLayout = NULL;
|
||||
|
||||
ID3D10Buffer * g_pVertexBufferPNT;
|
||||
ID3D10Buffer * g_pVertexBufferJW;
|
||||
ID3D10Buffer * g_pIndexBuffer;
|
||||
|
||||
ID3D10EffectMatrixVariable * g_pJointVariable = NULL;
|
||||
|
||||
ID3D10EffectMatrixVariable * g_pWorldVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pViewVariable = NULL;
|
||||
ID3D10EffectMatrixVariable * g_pProjectionVariable = NULL;
|
||||
|
||||
HRESULT LoadEffect()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
HRSRC hRes = FindResource(NULL, L"RES_COLLADA_FXO", RT_RCDATA);
|
||||
if (hRes == NULL) {
|
||||
print("FindResource RES_COLLADA_FXO\n");
|
||||
return E_FAIL;
|
||||
}
|
||||
DWORD dwResSize = SizeofResource(NULL, hRes);
|
||||
HGLOBAL hData = LoadResource(NULL, hRes);
|
||||
void * pData = LockResource(hData);
|
||||
hr = D3D10CreateEffectFromMemory(pData,
|
||||
dwResSize,
|
||||
0,
|
||||
g_pd3dDevice,
|
||||
NULL,
|
||||
&g_pEffect
|
||||
);
|
||||
if (FAILED(hr)) {
|
||||
print("D3D10CreateEffectFromMemory\n");
|
||||
return hr;
|
||||
}
|
||||
g_pTechniqueRender = g_pEffect->GetTechniqueByName("Render");
|
||||
|
||||
// variables
|
||||
g_pJointVariable = g_pEffect->GetVariableByName("mJoint")->AsMatrix();
|
||||
|
||||
g_pWorldVariable = g_pEffect->GetVariableByName("World")->AsMatrix();
|
||||
g_pViewVariable = g_pEffect->GetVariableByName("View")->AsMatrix();
|
||||
g_pProjectionVariable = g_pEffect->GetVariableByName("Projection")->AsMatrix();
|
||||
|
||||
// layout
|
||||
D3D10_INPUT_ELEMENT_DESC layout[] = {
|
||||
{"POSITION" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"NORMAL" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"TEXCOORD" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
{"BLENDWEIGHT" , 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
UINT numElements = (sizeof (layout)) / (sizeof (layout[0]));
|
||||
|
||||
D3D10_PASS_DESC passDesc;
|
||||
g_pTechniqueRender->GetPassByIndex(0)->GetDesc(&passDesc);
|
||||
|
||||
hr = g_pd3dDevice->CreateInputLayout(layout, numElements,
|
||||
passDesc.pIAInputSignature,
|
||||
passDesc.IAInputSignatureSize,
|
||||
&g_pVertexLayout);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateInputLayout\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT LoadMesh()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
D3D10_BUFFER_DESC bd;
|
||||
D3D10_SUBRESOURCE_DATA initData;
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (vertex_buffer));
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = vertex_buffer;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pVertexBufferPNT);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_VERTEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (joints_weights));
|
||||
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = joints_weights;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pVertexBufferJW);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_VERTEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
bd.Usage = D3D10_USAGE_IMMUTABLE;
|
||||
bd.ByteWidth = (sizeof (index_buffer));
|
||||
bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = 0;
|
||||
bd.MiscFlags = 0;
|
||||
initData.pSysMem = index_buffer;
|
||||
hr = g_pd3dDevice->CreateBuffer(&bd, &initData, &g_pIndexBuffer);
|
||||
if (FAILED(hr)) {
|
||||
print("CreateBuffer: D3D10_BIND_INDEX_BUFFER\n");
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void Render(float t)
|
||||
{
|
||||
XMMATRIX World = XMMatrixScaling(1, 1, 1);
|
||||
|
||||
// XMMATRIX XM_CALLCONV XMMatrixRotationNormal(FXMVECTOR NormalAxis, float Angle) noexcept;
|
||||
//XMConvertToRadians
|
||||
XMVECTOR axis = XMVectorSet(0, 1, 0, 0);
|
||||
XMVECTOR axisZ = XMVectorSet(0, 0, 1, 0);
|
||||
XMMATRIX joint0
|
||||
= XMMatrixRotationNormal(axis, XMConvertToRadians(-90))
|
||||
;
|
||||
XMMATRIX joint1
|
||||
= XMMatrixRotationNormal(axisZ, sin(t))
|
||||
* XMMatrixTranslation(10, 0, 0)
|
||||
* joint0
|
||||
;
|
||||
|
||||
XMMATRIX joint0ibm = XMLoadFloat4x4((XMFLOAT4X4*)&inverse_bind_matrices[0 * 16]);
|
||||
XMMATRIX joint1ibm = XMLoadFloat4x4((XMFLOAT4X4*)&inverse_bind_matrices[1 * 16]);
|
||||
XMMATRIX mJoints[2] = {
|
||||
joint0ibm * joint0,
|
||||
joint1ibm * joint1,
|
||||
};
|
||||
|
||||
g_pJointVariable->SetMatrixArray((float *)mJoints, 0, 2);
|
||||
|
||||
g_pWorldVariable->SetMatrix((float *)&World);
|
||||
g_pViewVariable->SetMatrix((float *)&g_View);
|
||||
g_pProjectionVariable->SetMatrix((float *)&g_Projection);
|
||||
|
||||
UINT stride[] = {
|
||||
3 * 3 * 4, // position normal texture
|
||||
4 * 2 * 4, // joint weight
|
||||
};
|
||||
UINT offset[] = { 0, 0 };
|
||||
ID3D10Buffer * vertex_buffers[] = {
|
||||
g_pVertexBufferPNT,
|
||||
g_pVertexBufferJW,
|
||||
};
|
||||
|
||||
g_pd3dDevice->IASetInputLayout(g_pVertexLayout);
|
||||
g_pd3dDevice->IASetVertexBuffers(0, 2, vertex_buffers, stride, offset);
|
||||
g_pd3dDevice->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
D3D10_TECHNIQUE_DESC techDesc;
|
||||
g_pTechniqueRender->GetDesc(&techDesc);
|
||||
|
||||
int indices_length = (sizeof (index_buffer)) / (sizeof (int));
|
||||
for (UINT p = 0; p < techDesc.Passes; p++) {
|
||||
g_pTechniqueRender->GetPassByIndex(p)->Apply(0);
|
||||
g_pd3dDevice->DrawIndexed(indices_length, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,72 +1,72 @@
|
||||
matrix World;
|
||||
matrix View;
|
||||
matrix Projection;
|
||||
|
||||
matrix mJoint[2];
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 Pos : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Tex : TEXCOORD0;
|
||||
float4 Joint : BLENDINDICES0;
|
||||
float4 Weight : BLENDWEIGHT0;
|
||||
};
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
PS_INPUT VS(VS_INPUT input)
|
||||
{
|
||||
PS_INPUT output;
|
||||
|
||||
matrix mSkin
|
||||
= input.Weight.x * mJoint[int(input.Joint.x)]
|
||||
+ input.Weight.y * mJoint[int(input.Joint.y)]
|
||||
+ input.Weight.z * mJoint[int(input.Joint.z)]
|
||||
+ input.Weight.w * mJoint[int(input.Joint.w)]
|
||||
;
|
||||
|
||||
output.Pos = mul(input.Pos, mSkin);
|
||||
output.Pos = mul(output.Pos, World);
|
||||
output.Pos = mul(output.Pos, View);
|
||||
output.Pos = mul(output.Pos, Projection);
|
||||
|
||||
output.Normal = input.Normal;
|
||||
output.Tex = input.Tex;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
//return float4(input.Normal * 0.5 + 0.5, 1);
|
||||
return float4(input.Tex.xy, 0, 1);
|
||||
}
|
||||
|
||||
BlendState DisableBlending
|
||||
{
|
||||
BlendEnable[0] = FALSE;
|
||||
};
|
||||
|
||||
DepthStencilState EnableDepth
|
||||
{
|
||||
DepthEnable = TRUE;
|
||||
DepthWriteMask = ALL;
|
||||
};
|
||||
|
||||
technique10 Render
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
SetVertexShader(CompileShader(vs_4_0, VS()));
|
||||
SetGeometryShader(NULL);
|
||||
SetPixelShader(CompileShader(ps_4_0, PS()));
|
||||
SetBlendState(DisableBlending, float4(0.0, 0.0, 0.0, 0.0), 0xffffffff);
|
||||
SetDepthStencilState(EnableDepth, 0);
|
||||
}
|
||||
}
|
||||
matrix World;
|
||||
matrix View;
|
||||
matrix Projection;
|
||||
|
||||
matrix mJoint[2];
|
||||
|
||||
struct VS_INPUT
|
||||
{
|
||||
float4 Pos : POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Tex : TEXCOORD0;
|
||||
float4 Joint : BLENDINDICES0;
|
||||
float4 Weight : BLENDWEIGHT0;
|
||||
};
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float3 Normal : NORMAL;
|
||||
float2 Tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
PS_INPUT VS(VS_INPUT input)
|
||||
{
|
||||
PS_INPUT output;
|
||||
|
||||
matrix mSkin
|
||||
= input.Weight.x * mJoint[int(input.Joint.x)]
|
||||
+ input.Weight.y * mJoint[int(input.Joint.y)]
|
||||
+ input.Weight.z * mJoint[int(input.Joint.z)]
|
||||
+ input.Weight.w * mJoint[int(input.Joint.w)]
|
||||
;
|
||||
|
||||
output.Pos = mul(input.Pos, mSkin);
|
||||
output.Pos = mul(output.Pos, World);
|
||||
output.Pos = mul(output.Pos, View);
|
||||
output.Pos = mul(output.Pos, Projection);
|
||||
|
||||
output.Normal = input.Normal;
|
||||
output.Tex = input.Tex;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 PS(PS_INPUT input) : SV_Target
|
||||
{
|
||||
//return float4(input.Normal * 0.5 + 0.5, 1);
|
||||
return float4(input.Tex.xy, 0, 1);
|
||||
}
|
||||
|
||||
BlendState DisableBlending
|
||||
{
|
||||
BlendEnable[0] = FALSE;
|
||||
};
|
||||
|
||||
DepthStencilState EnableDepth
|
||||
{
|
||||
DepthEnable = TRUE;
|
||||
DepthWriteMask = ALL;
|
||||
};
|
||||
|
||||
technique10 Render
|
||||
{
|
||||
pass P0
|
||||
{
|
||||
SetVertexShader(CompileShader(vs_4_0, VS()));
|
||||
SetGeometryShader(NULL);
|
||||
SetPixelShader(CompileShader(ps_4_0, PS()));
|
||||
SetBlendState(DisableBlending, float4(0.0, 0.0, 0.0, 0.0), 0xffffffff);
|
||||
SetDepthStencilState(EnableDepth, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user