Skip to content

Commit f5751d0

Browse files
committed
- collada parser
1 parent d47344a commit f5751d0

File tree

4 files changed

+1963
-734
lines changed

4 files changed

+1963
-734
lines changed

src/main/kotlin/collada/ColladaHelper.kt

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,23 @@ enum class InputType {
4646
Bitangent
4747
}
4848

49+
/** Supported controller types */
50+
enum class ControllerType {
51+
Skin,
52+
Morph
53+
}
54+
55+
/** Supported morph methods */
56+
enum class MorphMethod {
57+
Normalized,
58+
Relative
59+
}
60+
4961
/** Contains all data for one of the different transformation types */
5062
class Transform(
51-
var mID: String, ///< SID of the transform step, by which anim channels address their target node
52-
var mType: TransformType,
53-
var f: FloatArray) ///< Interpretation of data depends on the type of the transformation
63+
var mID: String = "", ///< SID of the transform step, by which anim channels address their target node
64+
var mType: TransformType = TransformType.LOOKAT,
65+
var f: FloatArray = floatArrayOf()) ///< Interpretation of data depends on the type of the transformation
5466

5567
/** A collada camera. */
5668
class Camera(
@@ -109,58 +121,58 @@ class InputSemanticMapEntry(
109121
/** Table to map from effect to vertex input semantics */
110122
class SemanticMappingTable(
111123
//! Name of material
112-
var mMatName: String,
124+
var mMatName: String = "",
113125
//! List of semantic map commands, grouped by effect semantic name
114-
var mMap: Map<String, InputSemanticMapEntry>)
126+
var mMap: MutableMap<String, InputSemanticMapEntry> = mutableMapOf())
115127

116128
/** A reference to a mesh inside a node, including materials assigned to the various subgroups.
117129
* The ID refers to either a mesh or a controller which specifies the mesh */
118130
class MeshInstance(
119131
///< ID of the mesh or controller to be instanced
120-
var mMeshOrController: String,
132+
var mMeshOrController: String = "",
121133
///< Map of materials by the subgroup ID they're applied to
122-
var mMaterials: Map<String, SemanticMappingTable>)
134+
var mMaterials: MutableMap<String, SemanticMappingTable> = mutableMapOf())
123135

124136
/** A reference to a camera inside a node*/
125137
class CameraInstance(
126138
///< ID of the camera
127-
var mCamera: String)
139+
var mCamera: String = "")
128140

129141
/** A reference to a light inside a node*/
130142
class LightInstance(
131143
///< ID of the camera
132-
var mLight: String)
144+
var mLight: String = "")
133145

134146
/** A reference to a node inside a node*/
135147
class NodeInstance(
136148
///< ID of the node
137-
var mNode: String)
149+
var mNode: String = "")
138150

139151
/** A node in a scene hierarchy */
140152
class Node(
141-
var mName: String,
142-
var mID: String,
143-
var mSID: String,
153+
var mName: String = "",
154+
var mID: String = "",
155+
var mSID: String = "",
144156
var mParent: Node? = null,
145-
var mChildren: ArrayList<Node>,
157+
var mChildren: ArrayList<Node> = arrayListOf(),
146158

147159
/** Operations in order to calculate the resulting transformation to parent. */
148-
var mTransforms: ArrayList<Transform>,
160+
var mTransforms: ArrayList<Transform> = arrayListOf(),
149161

150162
/** Meshes at this node */
151-
var mMeshes: ArrayList<MeshInstance>,
163+
var mMeshes: ArrayList<MeshInstance> = arrayListOf(),
152164

153165
/** Lights at this node */
154-
var mLights: ArrayList<LightInstance>,
166+
var mLights: ArrayList<LightInstance> = arrayListOf(),
155167

156168
/** Cameras at this node */
157-
var mCameras: ArrayList<CameraInstance>,
169+
var mCameras: ArrayList<CameraInstance> = arrayListOf(),
158170

159171
/** Node instances at this node */
160-
var mNodeInstances: ArrayList<NodeInstance>,
172+
var mNodeInstances: ArrayList<NodeInstance> = arrayListOf(),
161173

162174
/** Rootnodes: Name of primary camera, if any */
163-
var mPrimaryCamera: String)
175+
var mPrimaryCamera: String = "")
164176

165177
/** Data source array: either floats or strings */
166178
class Data(
@@ -243,6 +255,12 @@ enum class PrimitiveType {
243255

244256
/** A skeleton controller to deform a mesh with the use of joints */
245257
class Controller(
258+
// controller type
259+
var mType: ControllerType = ControllerType.Morph,
260+
261+
// Morphing method if type is Morph
262+
var mMethod: MorphMethod = MorphMethod.Normalized,
263+
246264
// the URL of the mesh deformed by the controller.
247265
var mMeshId: String = "",
248266

@@ -264,12 +282,15 @@ class Controller(
264282
var mWeightCounts: MutableList<Int> = mutableListOf(),
265283

266284
// JointIndex-WeightIndex pairs for all vertices
267-
var mWeights: MutableList<Pair<Int, Int>> = mutableListOf())
285+
var mWeights: MutableList<Pair<Int, Int>> = mutableListOf(),
286+
287+
var mMorphTarget: String = "",
288+
var mMorphWeight: String = "")
268289

269290
/** A collada material. Pretty much the only member is a reference to an effect. */
270291
class Material(
271-
var mName: String,
272-
var mEffect: String)
292+
var mName: String = "",
293+
var mEffect: String = "")
273294

274295
/** Type of the effect param */
275296
enum class ParamType {
@@ -279,8 +300,8 @@ enum class ParamType {
279300

280301
/** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */
281302
class EffectParam(
282-
var mType: ParamType,
283-
var mReference: String) // to which other thing the param is referring to.
303+
var mType: ParamType = ParamType.Sampler,
304+
var mReference: String = "") // to which other thing the param is referring to.
284305

285306
/** Shading type supported by the standard effect spec of Collada */
286307
enum class ShadeType {
@@ -294,7 +315,7 @@ enum class ShadeType {
294315
/** Represents a texture sampler in collada */
295316
class Sampler(
296317
/** Name of image reference */
297-
var mName: String,
318+
var mName: String = "",
298319

299320
/** Wrap U? */
300321
var mWrapU: Boolean = true,
@@ -303,19 +324,19 @@ class Sampler(
303324
var mWrapV: Boolean = true,
304325

305326
/** Mirror U? */
306-
var mMirrorU: Boolean,
327+
var mMirrorU: Boolean = false,
307328

308329
/** Mirror V? */
309-
var mMirrorV: Boolean,
330+
var mMirrorV: Boolean = false,
310331

311332
/** Blend mode */
312333
var mOp: AiTexture.Op = AiTexture.Op.multiply,
313334

314335
/** UV transformation */
315-
var mTransform: AiUVTransform,
336+
var mTransform: AiUVTransform = AiUVTransform(),
316337

317338
/** Name of source UV channel */
318-
var mUVChannel: String,
339+
var mUVChannel: String = "",
319340

320341
/** Resolved UV channel index or UINT_MAX if not known */
321342
var mUVId: Int = 0xFFFFFFFF.i,
@@ -324,12 +345,12 @@ class Sampler(
324345
// -------------------------------------------------------
325346

326347
/** Weighting factor */
327-
var mWeighting: Float,
348+
var mWeighting: Float = 1f,
328349

329350
/** Mixing factor from OKINO */
330-
var mMixWithPrevious: Float)
351+
var mMixWithPrevious: Float = 1f)
331352

332-
typealias ParamLibrary = Map<String, EffectParam>
353+
typealias ParamLibrary = MutableMap<String, EffectParam>
333354

334355
/** A collada effect. Can contain about anything according to the Collada spec, but we limit our version to a reasonable subset. */
335356
class Effect(
@@ -342,16 +363,16 @@ class Effect(
342363
var mDiffuse: AiColor4D = AiColor4D(.6f, .6f, .6f, 1f),
343364
var mSpecular: AiColor4D = AiColor4D(.4, .4f, .4f, 1f),
344365
var mTransparent: AiColor4D = AiColor4D(0, 0, 0, 1),
345-
var mReflective: AiColor4D,
366+
var mReflective: AiColor4D = AiColor4D(),
346367

347368
// Textures
348-
var mTexEmissive: Sampler,
349-
var mTexAmbient: Sampler,
350-
var mTexDiffuse: Sampler,
351-
var mTexSpecular: Sampler,
352-
var mTexTransparent: Sampler,
353-
var mTexBump: Sampler,
354-
var mTexReflective: Sampler,
369+
var mTexEmissive: Sampler = Sampler(),
370+
var mTexAmbient: Sampler = Sampler(),
371+
var mTexDiffuse: Sampler = Sampler(),
372+
var mTexSpecular: Sampler = Sampler(),
373+
var mTexTransparent: Sampler = Sampler(),
374+
var mTexBump: Sampler = Sampler(),
375+
var mTexReflective: Sampler = Sampler(),
355376

356377
// Scalar factory
357378
var mShininess: Float = 10f,
@@ -363,7 +384,7 @@ class Effect(
363384
var mInvertTransparency: Boolean = false,
364385

365386
// local params referring to each other by their SID
366-
var mParams: ParamLibrary,
387+
var mParams: ParamLibrary = mutableMapOf(),
367388

368389
// MAX3D extensions
369390
// ---------------------------------------------------------
@@ -375,13 +396,13 @@ class Effect(
375396
/** An image, meaning texture */
376397
class Image(
377398

378-
var mFileName: String,
399+
var mFileName: String = "",
379400

380401
/** If image file name is zero, embedded image data */
381-
var mImageData: ArrayList<Byte>,
402+
var mImageData: ByteArray = byteArrayOf(),
382403

383404
/** If image file name is zero, file format of embedded image data. */
384-
var mEmbeddedFormat: String)
405+
var mEmbeddedFormat: String = "")
385406

386407
/** An animation channel. */
387408
class AnimationChannel(
@@ -392,7 +413,13 @@ class AnimationChannel(
392413
/** Source URL of the time values. Collada calls them "input". Meh. */
393414
var mSourceTimes: String = "",
394415
/** Source URL of the value values. Collada calls them "output". */
395-
var mSourceValues: String = "")
416+
var mSourceValues: String = "",
417+
/** Source URL of the IN_TANGENT semantic values. */
418+
var mInTanValues: String = "",
419+
/** Source URL of the OUT_TANGENT semantic values. */
420+
var mOutTanValues: String = "",
421+
/** Source URL of the INTERPOLATION semantic values. */
422+
var mInterpolationValues: String = "")
396423

397424
/** An animation. Container for 0-x animation channels or 0-x animations */
398425
class Animation(
@@ -440,6 +467,7 @@ class Animation(
440467
/** Description of a collada animation channel which has been determined to affect the current node */
441468
class ChannelEntry(
442469
val mChannel: AnimationChannel, ///> the source channel
470+
var mTargetId: String,
443471
var mTransformId: String, // the ID of the transformation step of the node which is influenced
444472
var mTransformIndex: Int, // Index into the node's transform chain to apply the channel to
445473
val mSubElement: Int, // starting index inside the transform data

0 commit comments

Comments
 (0)