-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPopCinema4d.js
More file actions
116 lines (97 loc) · 2.87 KB
/
PopCinema4d.js
File metadata and controls
116 lines (97 loc) · 2.87 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Pop.Cinema4d = {};
// v8 cannot parse json where there's newlines and tabs in a value
// which http://www.utilities-online.info/xmltojson spits out
// the webpage should be using \t and \n
Pop.CleanJson = function(Json)
{
// match value with a string
let regex = new RegExp('"[^\\"]+"[\\s]*:[\\s]*"[\\s0-9a-f]+"','g');
let Replace = function(Match)
{
//Pop.Debug("Match is ",Match);
//Pop.Debug(...arguments);
Match = Match.replace( new RegExp('\n','g'), '\\n' );
Match = Match.replace( new RegExp('\t','g'), '\\t' );
return Match;
}
Json = Json.replace(regex, Replace);
//Pop.Debug(Contents);
return Json;
}
Pop.Cinema4d.Parse = function(Contents,OnActor,OnSpline)
{
if ( Contents.startsWith('<?xml') )
throw "Convert cinema4d file from xml to json first http://www.utilities-online.info/xmltojson";
Contents = Pop.CleanJson(Contents);
const DocumentTree = JSON.parse( Contents );
const NodeTree = DocumentTree.c4d_file.v6_basedocument.v6_root_object.v6_rootlist2d;
let Nodes = NodeTree.obj_pluginobject;
let NodeSplines = [NodeTree.obj_spline];
let ParseFloatPosition = function(Float)
{
Float = parseFloat( Float );
Float /= 10;
return Float;
}
let VectorToArray = function(Vector)
{
let x = ParseFloatPosition( Vector['-x'] );
let y = ParseFloatPosition( Vector['-y'] );
let z = ParseFloatPosition( Vector['-z'] );
return [x,y,z];
}
let StringToNodeName = function(String)
{
String = String['-v'];
String = String.replace(' ','_');
return String;
}
let ParseNode = function(Node)
{
let Actor = {};
Actor.Name = StringToNodeName( Node.v6_baselist2d.string );
Actor.Position = VectorToArray( Node.v6_baseobject.vector[0] );
//Pop.Debug(Node,Actor);
return Actor;
}
let ParseSpline = function(Node)
{
let Actor = {};
Actor.Name = StringToNodeName(Node.v6_baselist2d.string);
//Actor.Position = VectorToArray( Node.v6_baseobject.vector[0] );
let PositionVectors = Node.v6_root_tag.v6_rootlist2d.tag_hermite2d.tag_hermite2d.vector;
Actor.PathPositions = PositionVectors.map( VectorToArray );
Pop.Debug('Actor.PathPositions',Actor.PathPositions);
// maybe this
// https://www.shadertoy.com/view/4sS3Wc
/*
let HermiteD = function(x,a,b,e,f)
{
return b+0.5 * x * (e+b-a+x*(a-b+e+x*3.0*(e*3.0+f+x*5.0/3.0*(-e*3.0-f+x*0.4*(e*3.0+f))))));
}
let Hermite = function(x,a,b,c,d)
{
return HermiteD( x, a, b, (c-b), (a-d) );
}
*/
// debug spline points
let PositionAsActor = function(Position,Index)
{
if ( Index % 4 != 0 )
{
//return;
}
let Actor = {};
Actor.Name = 'actor'+Index;
Actor.Position = Position;
OnActor( Actor );
}
//Actor.PathPositions.forEach( PositionAsActor );
Pop.Debug(Node,Actor);
return Actor;
}
let Actors = Nodes.map( ParseNode );
let Splines = NodeSplines.map( ParseSpline );
Actors.forEach( OnActor );
Splines.forEach( OnSpline );
}