⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splyload.cpp

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 CPP
字号:
#include <stdio.h>
#include "subdiv.h"
#include <vector>
#include <brook/brook.hpp>
using std::vector;
void LoadPly (const char * file,vector<STri> &ret) {
  int i;
  float ver;char mchar;
  int numvertex,numface,propertycount=0;
  vector<tri_vertex_t> vertices;
  
  FILE * fp = fopen (file,"r");
  if (!fp) return;
  fscanf(fp,"ply\nformat ascii %f\n",&ver);
  int comment;
  while (1==(comment=fscanf(fp,"commen%c %*[^\n]\n",&mchar))) {
     int j=1;
  }
  fscanf(fp,"element vertex %d\n",&numvertex);
  while (1==fscanf(fp,"propert%c %*s %*s\n",&mchar)) {
    propertycount++;
  }
  fscanf(fp,"element face %d\n",&numface);
  while (1==fscanf(fp,"propert%c %*[^\n]\n",&mchar));
  fscanf(fp,"end_header\n");
  for (i=0;i<numvertex;++i) {
    tri_vertex_t in;
    fscanf(fp,"%f %f %f",&in.x,&in.y,&in.z);
    for (int i=3;i<propertycount;++i) {
      fscanf(fp,"%*f");
    }
    vertices.push_back(in);
  }
  for (i=0;i<numface;++i) {
    int num=0;
    int a,b,c,count=0;
    fscanf(fp,"%d",&num);
    if (num>=2) {
      count=2;
      fscanf(fp,"%d %d",&a,&b);
    }
    for (int i=count;i<num;++i) {
      fscanf(fp,"%d",&c);
      ret.push_back(STri());
      ret.back().A = vertices[a];
      ret.back().B = vertices[b];
      ret.back().C = vertices[c];
      a = b;
      b = c;
    }
    fscanf(fp,"\n");
  }
  fclose(fp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -