initial upload
This commit is contained in:
44
archive/msh2obj/oldfiles/GMT_colorPattern.mtl
Normal file
44
archive/msh2obj/oldfiles/GMT_colorPattern.mtl
Normal file
@@ -0,0 +1,44 @@
|
||||
# newmtl [name] 材质名称
|
||||
# Ns [0~1000] 反射高光度 值越高则高光越密集
|
||||
# Ni [0.001~10] 折射值 若取值为1.0 光在通过物体的时候不发生弯曲 玻璃的折射率为1.5
|
||||
# Ka [0~1] [0~1] [0~1] 材质的环境光 阴影色(ambient color)
|
||||
# Kd [0~1] [0~1] [0~1] 散射光 固有色(diffuse color)
|
||||
# Ks [0~1] [0~1] [0~1] 镜面光 高光色(specular color)
|
||||
# d [0~1] 渐隐指数描述 参数factor表示物体融入背景的数量 取值范围为0.0~1.0 取值为1.0表示完全不透明 取值为0.0时表示完全透明
|
||||
# illum 1
|
||||
# map_Ka [pic-file]
|
||||
# map_Kd [pic-file]
|
||||
# map_Ks [pic-file]
|
||||
|
||||
newmtl seis
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_seis.png
|
||||
map_Kd GMT_seis.png
|
||||
|
||||
newmtl rainbow
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka GMT_rainbow.png
|
||||
map_Kd GMT_rainbow.png
|
||||
|
||||
newmtl arctic
|
||||
Ns 96.078431
|
||||
Ni 1.000000
|
||||
Ka 0.100000 0.100000 0.100000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
d 1.0
|
||||
illum 1
|
||||
map_Ka arctic.png
|
||||
map_Kd arctic.png
|
10263
archive/msh2obj/oldfiles/input.msh
Normal file
10263
archive/msh2obj/oldfiles/input.msh
Normal file
File diff suppressed because it is too large
Load Diff
3116
archive/msh2obj/oldfiles/input2.msh
Normal file
3116
archive/msh2obj/oldfiles/input2.msh
Normal file
File diff suppressed because it is too large
Load Diff
BIN
archive/msh2obj/oldfiles/msh2obj
Normal file
BIN
archive/msh2obj/oldfiles/msh2obj
Normal file
Binary file not shown.
168
archive/msh2obj/oldfiles/msh2obj.cpp
Normal file
168
archive/msh2obj/oldfiles/msh2obj.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "iomanip"
|
||||
#include "string.h"
|
||||
#include "cmath"
|
||||
#include "vector"
|
||||
|
||||
#define ZERO 1e-20
|
||||
#define Pi (4.0*atan(1.0))
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct point{
|
||||
double x,y,z;
|
||||
};
|
||||
typedef vector<point> pointArray;
|
||||
|
||||
struct spoint
|
||||
{
|
||||
double lon,lat,rad;
|
||||
};
|
||||
typedef vector<spoint> spointArray;
|
||||
|
||||
struct vertex : public point{
|
||||
int id;
|
||||
double attri;
|
||||
};
|
||||
typedef vector<vertex> vertexArray;
|
||||
|
||||
struct face{
|
||||
int id;
|
||||
int vec[3] = {-1,-1,-1};
|
||||
point outNor;
|
||||
};
|
||||
typedef vector<face> faceArray;
|
||||
|
||||
point normal(point a){
|
||||
point out = a;
|
||||
double module = sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
|
||||
out.x /= module; out.y /= module; out.z /= module;
|
||||
return out;
|
||||
}
|
||||
|
||||
point operator -(point a,point b){
|
||||
point out;
|
||||
out.x = a.x - b.x;
|
||||
out.y = a.y - b.y;
|
||||
out.z = a.z - b.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
point operator -(vertex a,vertex b){
|
||||
point out;
|
||||
out.x = a.x - b.x;
|
||||
out.y = a.y - b.y;
|
||||
out.z = a.z - b.z;
|
||||
return out;
|
||||
}
|
||||
|
||||
point cross(point a,point b){
|
||||
point out;
|
||||
out.x = a.y*b.z-a.z*b.y;
|
||||
out.y = a.z*b.x-a.x*b.z;
|
||||
out.z = a.x*b.y-a.y*b.x;
|
||||
return out;
|
||||
}
|
||||
|
||||
spoint c2s(vertex c)
|
||||
{
|
||||
spoint s;
|
||||
s.rad = sqrt(c.x*c.x+c.y*c.y+c.z*c.z);
|
||||
if (fabs(s.rad)<ZERO) //点距离原点极近 将点置于原点
|
||||
{
|
||||
s.lat = s.lon = s.rad = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.lat = 90.0 - acos(c.z/s.rad)*180.0/Pi;
|
||||
s.lon = atan2(c.y,c.x)*180.0/Pi;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]){
|
||||
vertex node;
|
||||
face triangle;
|
||||
vertexArray nodes;
|
||||
faceArray triangles;
|
||||
|
||||
int temp_int,temp_int2;
|
||||
string temp_str;
|
||||
stringstream temp_ss;
|
||||
|
||||
double attriMax = -1e+30;
|
||||
double attriMin = 1e+30;
|
||||
ifstream mshin("input2.msh");
|
||||
while(getline(mshin,temp_str)){
|
||||
if (!strcmp(temp_str.c_str(),"$Nodes")){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> node.id >> node.x >> node.y >> node.z;
|
||||
nodes.push_back(node);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(temp_str.c_str(),"$Elements")){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> triangle.id >> temp_int2 >> temp_int2 >> temp_int2
|
||||
>> triangle.vec[0] >> triangle.vec[1] >> triangle.vec[2];
|
||||
//triangle.vec[0] += 1; triangle.vec[1] += 1; triangle.vec[2] += 1;
|
||||
triangle.id += 1;
|
||||
triangles.push_back(triangle);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(temp_str.c_str(),"$NodeData")){
|
||||
for (int i = 0; i < 8; i++)
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int;
|
||||
for (int i = 0; i < temp_int; i++){
|
||||
getline(mshin,temp_str);
|
||||
temp_ss.str(""); temp_ss.clear(); temp_ss.str(temp_str);
|
||||
temp_ss >> temp_int2 >> nodes[i].attri;
|
||||
if(nodes[i].attri > attriMax) attriMax = nodes[i].attri;
|
||||
if(nodes[i].attri < attriMin) attriMin = nodes[i].attri;
|
||||
}
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
mshin.close();
|
||||
|
||||
for (int i = 0; i < nodes.size(); i++)
|
||||
nodes[i].attri = (nodes[i].attri - attriMin)/(attriMax - attriMin);
|
||||
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
triangles[i].outNor = normal(cross(nodes[triangles[i].vec[1]-1]-nodes[triangles[i].vec[0]-1],
|
||||
nodes[triangles[i].vec[2]-1]-nodes[triangles[i].vec[0]-1]));
|
||||
}
|
||||
|
||||
ofstream objout("sphere.obj");
|
||||
objout << "mtllib global_topography.mtl" << endl << "o sphere" << endl;
|
||||
for (int i = 0; i < nodes.size(); i++){
|
||||
objout << "v " << setprecision(16) << nodes[i].x << " " << nodes[i].y << " " << nodes[i].z << endl;
|
||||
}
|
||||
for (int i = 0; i < nodes.size(); i++){
|
||||
objout << "vt " << setprecision(16) << nodes[i].attri << " 0.5" << endl;
|
||||
}
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
objout << "vn " << setprecision(16) << triangles[i].outNor.x << " " << triangles[i].outNor.y << " " << triangles[i].outNor.z << endl;
|
||||
}
|
||||
objout << "usemtl earth-topo" << endl << "g model1" << endl << "s 1" << endl;
|
||||
for (int i = 0; i < triangles.size(); i++){
|
||||
objout << "f " << triangles[i].vec[0] << "/" << triangles[i].vec[0] << "/" << i+1 << " "
|
||||
<< triangles[i].vec[1] << "/" << triangles[i].vec[1] << "/" << i+1 << " "
|
||||
<< triangles[i].vec[2] << "/" << triangles[i].vec[2] << "/" << i+1 << endl;
|
||||
}
|
||||
objout.close();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user