beginning of light reading

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 45ab442396
commit 9e0d64f63f
3 changed files with 88 additions and 29 deletions
+20 -5
View File
@@ -7,9 +7,9 @@ def exportData(ob):
par = par.parent
file.write('{\n' + ob.type + ": " + ob.name + '\n')
file.write('pos: ' + str(ob.location.x) + ' ' + str(ob.location.y) + ' ' + str(ob.location.z) + '\n')
file.write('rot: ' + str(ob.rotation_quaternion.w) + ' ' + str(ob.rotation_quaternion.x) + ' ' + str(ob.rotation_quaternion.y) + ' ' + str(-ob.rotation_quaternion.z) + '\n')
file.write('scale: ' + str(ob.scale.x) + ' ' + str(ob.scale.y) + ' ' + str(ob.scale.z) + '\n')
file.write('pos: ' + str(ob.location.x) + ' ' + str(ob.location.y) + ' ' + str(ob.location.z) + ' \n')
file.write('rot: ' + str(ob.rotation_quaternion.w) + ' ' + str(ob.rotation_quaternion.x) + ' ' + str(ob.rotation_quaternion.y) + ' ' + str(-ob.rotation_quaternion.z) + ' \n')
file.write('scale: ' + str(ob.scale.x) + ' ' + str(ob.scale.y) + ' ' + str(ob.scale.z) + ' \n')
file.write('parent: ' + ('-' if par is None else par.name) + '\n')
numAnims = 0
@@ -105,11 +105,26 @@ def exportData(ob):
pos = vert.co
file.write(str(pos.x) + ' ' + str(pos.y) + ' ' + str(pos.z) + ' \n')
channels.extend(mesh.shape_keys.animation_data.drivers)
elif ob.type == 'LIGHT':
color = ob.data.color
outerAngle = 0
innerAngle = 0
type = ob.data.type
if type == 'SPOT':
outerAngle = ob.data.spot_size
innerAngle = outerAngle * ob.data.spot_blend
file.write('type: ' + type + '\n')
file.write('color: ' + str(color[0]) + ' ' + str(color[1]) + ' ' + str(color[2]) + ' \n')
file.write('outerAngle: ' + str(outerAngle) + ' \n')
file.write('innerAngle: ' + str(innerAngle) + ' \n')
file.write('animations: ' + str(numAnims) + '\n')
if numAnims > 0:
if ob.type != 'LIGHT' and numAnims > 0:
readAnimations(ob, numAnims)
elif ob.type == 'LIGHT':
readAnimations(ob, len(ob.animation_data.nla_tracks[0].strips))
readAnimations(ob.data, len(ob.data.animation_data.nla_tracks[0].strips))
if ob.animation_data is not None:
channels.extend(ob.animation_data.drivers)
@@ -233,7 +248,7 @@ for s in selectedObjects:
if inObjects == False:
objects.append(sPar)
file=open(fl, 'w')
file = open(fl, 'w')
for ob in selectedObjects:
exportData(ob)
file.write('}\n')
+67 -24
View File
@@ -1,16 +1,17 @@
#include"vbModelReader.h"
#include"util.h"
#include"vector.h"
#include"mesh.h"
#include"skeleton.h"
#include"bone.h"
#include"model.h"
#include"animation.h"
#include"animationController.h"
#include "vbModelReader.h"
#include "util.h"
#include "vector.h"
#include "light.h"
#include "mesh.h"
#include "skeleton.h"
#include "bone.h"
#include "model.h"
#include "animation.h"
#include "animationController.h"
#include<vector>
#include<algorithm>
#include<fstream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
@@ -323,12 +324,7 @@ namespace vb01{
int boneStartLine = 6;
int numBones = atoi(data[1].c_str());
int animationStartLine = boneStartLine + numBones;
int driverStartLine = animationStartLine;
for(int i = animationStartLine; i < skeletonData.size(); i++)
if(skeletonData[i].find_first_of(':') != -1 && skeletonData[i].substr(0, skeletonData[i].length() - 1) == "drivers: "){
driverStartLine = i;
break;
}
int driverStartLine = findDriverStartLine(skeletonData, animationStartLine);
AnimationController *controller = new AnimationController();
Skeleton *skeleton = new Skeleton(controller, name);
@@ -498,12 +494,7 @@ namespace vb01{
int faceStartLine = vertexStartLine + numVertices + 1;
int shapeKeyStartLine = faceStartLine + numFaces * numVertsPerFace + 1;
int animationStartLine = shapeKeyStartLine + numShapes * (1 + numVertices);
int driverStartLine = animationStartLine;
for(int i = animationStartLine; i < meshData.size(); i++)
if(meshData[i].find_first_of(':') != -1 && meshData[i].substr(0, meshData[i].length() - 1) == "drivers: "){
driverStartLine = i;
break;
}
int driverStartLine = findDriverStartLine(meshData, animationStartLine);
vector<Vector3> vertPos, vertNorm;
vector<float> vertWeights;
@@ -568,6 +559,58 @@ namespace vb01{
}
void VbModelReader::readLights(vector<string> &lightData){
string name = lightData[0].substr(lightData[0].find_first_of(':') + 2);
string data[4];
getLineData(lightData[1].substr(lightData[1].find_first_of(':') + 2), data, 3);
Vector3 pos = Vector3(atof(data[0].c_str()), atof(data[1].c_str()), atof(data[2].c_str()));
getLineData(lightData[2].substr(lightData[2].find_first_of(':') + 2), data, 4);
Quaternion rot = Quaternion(atof(data[0].c_str()), atof(data[1].c_str()), atof(data[2].c_str()), atof(data[3].c_str()));
getLineData(lightData[3].substr(lightData[3].find_first_of(':') + 2), data, 3);
Vector3 scale = Vector3(atof(data[0].c_str()), atof(data[1].c_str()) + 2, atof(data[2].c_str()));
string parent = lightData[4].substr(lightData[4].find_first_of(':') + 2);
string typeStr = lightData[5].substr(lightData[5].find_first_of(':') + 2);
Light::Type type;
if(typeStr == "POINT")
type = Light::POINT;
else if(typeStr == "SUN")
type = Light::DIRECTIONAL;
else if(typeStr == "SPOT")
type = Light::SPOT;
else if(typeStr == "AREA")
type = Light::AMBIENT;
getLineData(lightData[6].substr(lightData[6].find_first_of(':') + 2), data, 3);
Vector3 color = Vector3(atof(data[0].c_str()), atof(data[1].c_str()), atof(data[2].c_str()));
float outerAngle = atof(lightData[7].substr(lightData[7].find_first_of(':') + 2).c_str());
float innerAngle = atof(lightData[8].substr(lightData[8].find_first_of(':') + 2).c_str());
Light *light = new Light(type);
light->setColor(color);
light->setOuterAngle(outerAngle);
light->setInnerAngle(innerAngle);
AnimationController *controller = new AnimationController();
Node *node = new Node(pos, rot, scale, name, controller);
nodes.push_back(node);
int animationStartLine = 9;
int driverStartLine = findDriverStartLine(lightData, animationStartLine);
vector<string> lightSubData = vector<string>(lightData.begin() + animationStartLine, lightData.begin() + driverStartLine);
readAnimations(node, controller, lightSubData);
lightSubData.clear();
lightSubData = vector<string>(lightData.begin() + driverStartLine, lightData.end());
readDrivers(lightSubData, name);
lightSubData.clear();
}
int VbModelReader::findDriverStartLine(vector<string> &data, int animationStartLine){
int driverStartLine = animationStartLine;
for(int i = animationStartLine; i < data.size(); i++)
if(data[i].find_first_of(':') != -1 && data[i].substr(0, data[i].length() - 1) == "drivers: "){
driverStartLine = i;
break;
}
return driverStartLine;
}
}
+1
View File
@@ -24,6 +24,7 @@ namespace vb01{
void getObjectBounds(std::map<int, int>&, std::map<int, int>&, std::map<int, int>&);
void connectNodes();
void setupDrivers();
int findDriverStartLine(std::vector<std::string>&, int);
void createBones(Skeleton*, std::vector<std::string>&);
KeyframeChannel readKeyframeChannel(Animatable*, std::vector<std::string>&, int&);
void readAnimations(Animatable*, AnimationController*, std::vector<std::string>&);