标题: [其他] 命令行 三维模型渲染绘制器 [打印本页]
作者: slimay 时间: 2021-7-15 17:47 标题: 命令行 三维模型渲染绘制器
v v.exe
摘要:命令行下的 ASE、PLY 三维模型文件绘制工具。不足50KB, cpu使用率不到百分之一,黑窗口下高质量渲染三维模型
版本:1.8
用法:(控制台窗口输入命令)
vv [ASE文件路径]
下载链接:https://pan.baidu.com/s/1atnT6S0j0-_zKuUMI5vhFg
提取码:ypd9
请及时下载,失效后不在补更- 控制:
- A、D 按键控制图像 左右旋转
- W、S 按键控制图像 上下旋转
- Q、E 按键控制图像 Z轴倾斜
- Z、X 按键控制图像 缩放
-
- O、P 按键控制灯光强弱
-
- Y 按键 开启、关闭 二级旋转开关
- U 按键 渲染模式切换: 1.面渲染 2.点渲染 3.线渲染 4.白模渲染
- I 按键 开启、关闭 材质加强渲染开关
-
- R 按键重置图像,复位键
- 空格键 控制图像 暂停、旋转
- 回车键 控制程序 关闭
-
- 2、8 按键控制图像 上下平移
- 4、6 按键控制图像 左右平移
- 7、9 按键控制图像 里外平移
-
- 补充:
- 附带的FreeImage.dll图像插件如果删除,vv.exe将会启用内置gdiplus显示模型。
- 脱离FreeImage图像插件后,vv将无法加载dds、tga等纹理贴图,但此时可实现在
- PE下独立运行。
复制代码
ASE文件解析核心- int readAseData( char* aseFile )
- {
-
- FILE* fp = fopen(aseFile , "rb" );
- if( fp == NULL )
- {
- printf( "Needs ase file in!\n" );
- exit( 1 );
- }
-
- // 获取ASE文件路径
- char materPath[MAX_PATH];
- materPath[0] = 0; //初始化为空字符串
- char* p = strrchr(aseFile, '\\');
- if(p != NULL)
- {
- *(p + 1) = '\0';
- strcpy(materPath, aseFile);
- }
- // 计算ASE文件后缀路径添加位置
- char* addSuffixPathPos = (char*)materPath + strlen(materPath);
-
- char line[LINE_SIZE + 1];
- line[0] = 0; //初始化为空字符串
-
- int flag[5] = {0};
-
- int preADD = 0;
- int _tpreADD = 0;
- int materIndex = 0;
-
- while( !feof( fp ) )
- {
- fgets( line, 1024, fp );
-
- if( strstr( line, "*MATERIAL" ) != NULL )
- {
- int n;
- if(sscanf( line, " *MATERIAL %d", &n) != 0 )
- {
- materCount ++;
- materIndex = abs(n) % MAX_MESH;
- readMaterCount[materIndex] = materCount;
-
- // 先初默认纹理编号为白色纹理编号
- materials[materCount].texture = 0;
- continue;
- }
- }
- if( strstr( line, "*MATERIAL_AMBIENT" ) != NULL )
- {
- float f1 = 0.0f, f2 = 0.0f, f3 = 0.0f;
- if(sscanf( line, " *MATERIAL_AMBIENT %f %f %f", &f1, &f2, &f3) != 0 )
- {
- ((materials[materCount]).ambient)[0] = f1;
- ((materials[materCount]).ambient)[1] = f2;
- ((materials[materCount]).ambient)[2] = f3;
- continue;
- }
- }
- if( strstr( line, "*MATERIAL_DIFFUSE" ) != NULL )
- {
- float f1 = 0.0f, f2 = 0.0f, f3 = 0.0f;
- if(sscanf( line, " *MATERIAL_DIFFUSE %f %f %f", &f1, &f2, &f3) != 0 )
- {
- ((materials[materCount]).diffuse)[0] = f1;
- ((materials[materCount]).diffuse)[1] = f2;
- ((materials[materCount]).diffuse)[2] = f3;
- continue;
- }
- }
- if( strstr( line, "*MATERIAL_SPECULAR" ) != NULL )
- {
- float f1 = 0.0f, f2 = 0.0f, f3 = 0.0f;
- if(sscanf( line, " *MATERIAL_SPECULAR %f %f %f", &f1, &f2, &f3) != 0 )
- {
- ((materials[materCount]).specular)[0] = f1;
- ((materials[materCount]).specular)[1] = f2;
- ((materials[materCount]).specular)[2] = f3;
- continue;
- }
- }
- if( strstr( line, "*MATERIAL_EMISSION" ) != NULL )
- {
- float f1 = 0.0f, f2 = 0.0f, f3 = 0.0f;
- if(sscanf( line, " *MATERIAL_AMBIENT %f %f %f", &f1, &f2, &f3) != 0 )
- {
- ((materials[materCount]).emission)[0] = f1;
- ((materials[materCount]).emission)[1] = f2;
- ((materials[materCount]).emission)[2] = f3;
- continue;
- }
- }
- if( strstr( line, "*MATERIAL_SHINE" ) != NULL )
- {
- float f1;
- if(sscanf( line, " *MATERIAL_SHINE %f", &f1) != 0 )
- {
- (materials[materCount]).shine = f1;
- }
- }
- if( strstr( line, "*MATERIAL_TRANSPARENCY" ) != NULL )
- {
- float f1;
- if(sscanf( line, " *MATERIAL_TRANSPARENCY %f", &f1) != 0 )
- {
- (materials[materCount]).alpha = f1;
- }
- }
-
- if( strstr( line, "*MESH_NUMVERTEX" ) != NULL )
- {
- continue;
- }
-
- if( strstr( line, "*MESH_NUMFACES" ) != NULL )
- {
- continue;
- }
-
- if( strstr( line, "*MATERIAL_REF" ) != NULL )
- {
- int ni = -1;
- if( sscanf( line, " *MATERIAL_REF %d", &ni ) != 0 )
- {
- materIndex = abs(ni) % MAX_MESH;
- meshIndex[meshIncount ++ ] = readMaterCount[materIndex];
- continue;
- }
- }
-
- if( strstr( line, "*MAP_DIFFUSE" ) != NULL )
- {
- flag[4] = 1;
- continue;
- }
-
- if( flag[4] == 1 )
- {
- if( strstr( line, "*BITMAP" ) != NULL )
- {
- char pStr[MAX_PATH];
- if( sscanf( line, " *BITMAP \"%[^\"]\"", &pStr ) != 0 )
- {
- //检查材质路径是否为绝对路径
- p = strrchr(pStr, ':');
- //如果是相对路径,
- if(p == NULL)
- {
- // 则附在ASE文件的路径后边附加上材质相对路径
- strcpy(addSuffixPathPos , pStr);
- // 将拼接的材质总路径复制回 pStr容器中
- strcpy(pStr, materPath);
- }
-
- flag[4] = 0;
- continue;
- }
- }
- }
-
- if( strstr( line, "*MESH_VERTEX_LIST" ) != NULL )
- {
- flag[0] = 1;
- continue;
- }
-
- if( flag[0] == 1 )
- {
- char* keyPos = strstr( line, "*MESH_VERTEX" );
- if( keyPos != NULL )
- {
- int a;
- float f1, f2, f3;
-
- sscanf( line, " *MESH_VERTEX %d %f %f %f", &a, &f1, &f2, &f3 );
- pointData[pointCount][0] = f1;
- pointData[pointCount][1] = f2;
- pointData[pointCount][2] = f3;
- pointCount ++;
- }
- else
- {
- flag[0] = 0;
- }
- }
-
- if( strstr( line, "*MESH_FACE_LIST" ) != NULL )
- {
- flag[1] = 1;
- continue;
- }
-
- if( flag[1] == 1 )
- {
- char* keyPos = strstr( line, "*MESH_FACE" );
- if( keyPos != NULL )
- {
- int a;
- int f1, f2, f3;
- sscanf( line, " *MESH_FACE %d: A: %d B: %d C: %d", &a, &f1, &f2, &f3 );
- faceData[faceCount][0] = (abs(f1) + preADD) % pointCount;
- faceData[faceCount][1] = (abs(f2) + preADD) % pointCount;
- faceData[faceCount][2] = (abs(f3) + preADD) % pointCount;
- faceCount ++;
- }
- else
- {
- flag[1] = 0;
- preADD = pointCount;
-
- }
- }
-
- if( strstr( line, "*MESH_TVERTLIST" ) != NULL )
- {
- flag[2] = 1;
- continue;
- }
-
- if( flag[2] == 1 )
- {
- char* keyPos = strstr( line, "*MESH_TVERT" );
- if( keyPos != NULL )
- {
- int a;
- float f1, f2, f3;
- sscanf( line, " *MESH_TVERT %d %f %f %f", &a, &f1, &f2, &f3 );
- _tpointData[_tpointCount][0] = f1;
- _tpointData[_tpointCount][1] = f2;
- _tpointData[_tpointCount][2] = f3;
- _tpointCount ++;
- }
- else
- {
- flag[2] = 0;
- }
- }
-
- if( strstr( line, "*MESH_TFACELIST" ) != NULL )
- {
- flag[3] = 1;
- continue;
- }
-
- if( flag[3] == 1 )
- {
- char* keyPos = strstr( line, "*MESH_TFACE" );
- if( keyPos != NULL )
- {
- int a;
- int f1, f2, f3;
- sscanf( line, " *MESH_TFACE %d %d %d %d", &a, &f1, &f2, &f3 );
- _tfaceData[_tfaceCount][0] = (abs(f1) + _tpreADD) % _tpointCount;
- _tfaceData[_tfaceCount][1] = (abs(f2) + _tpreADD) % _tpointCount;
- _tfaceData[_tfaceCount][2] = (abs(f3) + _tpreADD) % _tpointCount;
- _tfaceCount ++;
- }
- else
- {
- flag[3] = 0;
- _tpreADD = _tpointCount;
- meshDelimsIndex[++ meshDelimsCount] = _tfaceCount;
-
- }
- }
-
- }
- fclose( fp );
- return 0;
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |