1 /*
2 	Copyright (C) 2005-2007 Feeling Software Inc.
3 	Portions of the code are:
4 	Copyright (C) 2005-2007 Sony Computer Entertainment America
5 
6 	MIT License: http://www.opensource.org/licenses/mit-license.php
7 */
8 
9 #include "StdAfx.h"
10 #include "FCDocument/FCDocument.h"
11 #include "FCDocument/FCDExtra.h"
12 #include "FCDocument/FCDGeometrySource.h"
13 #include "FUtils/FUDaeEnum.h"
14 
15 //
16 // FCDGeometrySource
17 //
18 
19 ImplementObjectType(FCDGeometrySource);
20 ImplementParameterObject(FCDGeometrySource, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent));
21 
FCDGeometrySource(FCDocument * document)22 FCDGeometrySource::FCDGeometrySource(FCDocument* document)
23 :	FCDObjectWithId(document, "GeometrySource")
24 ,	InitializeParameterNoArg(name)
25 ,	InitializeParameterAnimatableNoArg(sourceData)
26 ,	InitializeParameter(stride, 0)
27 ,	InitializeParameter(sourceType, (uint32) FUDaeGeometryInput::UNKNOWN)
28 ,	InitializeParameterNoArg(extra)
29 {
30 }
31 
~FCDGeometrySource()32 FCDGeometrySource::~FCDGeometrySource()
33 {
34 }
35 
SetDataCount(size_t count)36 void FCDGeometrySource::SetDataCount(size_t count)
37 {
38 	sourceData.resize(count);
39 	SetDirtyFlag();
40 }
41 
Clone(FCDGeometrySource * clone) const42 FCDGeometrySource* FCDGeometrySource::Clone(FCDGeometrySource* clone) const
43 {
44 	if (clone == NULL) clone = new FCDGeometrySource(const_cast<FCDocument*>(GetDocument()));
45 	FCDObjectWithId::Clone(clone);
46 	clone->name = name;
47 	clone->sourceType = sourceType;
48 
49 	// Clone the data of this source.
50 	clone->stride = stride;
51 	clone->sourceData.GetDataList() = sourceData.GetDataList(); // this should be replaced by an operator= where even the FCDAnimated* list is copied.
52 	clone->sourceType = sourceType;
53 
54 	// Clone the extra information.
55 	if (extra != NULL)
56 	{
57 		extra->Clone(clone->GetExtra());
58 	}
59 
60 	return clone;
61 }
62 
SetData(const FloatList & _sourceData,uint32 _sourceStride,size_t offset,size_t count)63 void FCDGeometrySource::SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t offset, size_t count)
64 {
65 	// Remove all the data currently held by the source.
66 	sourceData.clear();
67 	stride = _sourceStride;
68 
69 	// Check the given bounds
70 	size_t beg = min(offset, _sourceData.size()), end;
71 	if (count == 0) end = _sourceData.size();
72 	else end = min(count + offset, _sourceData.size());
73 	sourceData.insert(0, _sourceData.begin() + beg, end - beg);
74 
75 	SetDirtyFlag();
76 }
77 
GetExtra()78 FCDExtra* FCDGeometrySource::GetExtra()
79 {
80 	return (extra != NULL) ? extra : extra = new FCDExtra(GetDocument(), this);
81 }
82