private void ChangeNormal(int index, float nx, float ny, float nz) { var original = HeightMap[index]; HeightMap[index] = new XYZTextureNormalType() { x = original.x, y = original.y, z = original.z, tu = original.tu, tv = original.tv, nx = nx, ny = ny, nz = nz }; }
private void ChangeHeight(int index, float height) { var original = HeightMap[index]; HeightMap[index] = new XYZTextureNormalType() { x = original.x, y = original.y + height, z = original.z, tu = original.tu, tv = original.tv, nx = original.nx, ny = original.ny, nz = original.nz }; }
private bool LoadObject(string objectFormatFileName) { objectFormatFileName = SystemConfiguration.ModelFilePath + objectFormatFileName; try { var lines = File.ReadLines(objectFormatFileName).ToList(); var vertextCountString = lines[0].Split(new char[] { ':' })[1].Trim(); _vertexCount = int.Parse(vertextCountString); IndexCount = _vertexCount; ModelObject = new XYZTextureNormalType[_vertexCount]; for (var i = 4; i < lines.Count && i < 4 + _vertexCount; ++i) { var objectArray = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); ModelObject[i - 4] = new XYZTextureNormalType() { x = float.Parse(objectArray[0]), y = float.Parse(objectArray[1]), z = float.Parse(objectArray[2]), tu = float.Parse(objectArray[3]), tv = float.Parse(objectArray[4]), nx = float.Parse(objectArray[5]), ny = float.Parse(objectArray[6]), nz = float.Parse(objectArray[7]), }; } return(true); } catch (Exception ex) { //Log.WriteToFile(ErrorLevel.Error, "Object.LoadObject", ex, true); return(false); } }
private bool LoadSkyDomeModel(string skyDomeModelFileName) { skyDomeModelFileName = SystemConfiguration.ModelFilePath + skyDomeModelFileName; try { // Open the model file. string[] lines = File.ReadAllLines(skyDomeModelFileName); // Read up to the value of vertex count. int lineIndex = 0; bool found = false; while (!found) { if (lines[lineIndex].StartsWith("Vertex Count:")) { found = true; } else { lineIndex++; } } // Read in the vertex count, the second column after the ':' of the first row in the file. string stringVertexCount = lines[lineIndex].Split(':')[1]; VertexCount = int.Parse(stringVertexCount); // Set the number of indices to be the same as the vertex count. IndexCount = VertexCount; // Create the model using the vertex count that was read in. Model = new XYZTextureNormalType[VertexCount]; // Before continueing with the line parsing ensure we are starting one line after the "Data" portion of the file. int lineDataIndex = ++lineIndex; found = false; while (!found) { if (lines[lineDataIndex].Equals("Data:")) { found = true; } else { lineDataIndex++; } } // Procced to the next line for Vertex data. lineDataIndex++; // Read up to the beginning of the data. int vertexWriteIndex = 0; for (int i = lineDataIndex; i < lines.Length; i++) { // Ignor blank lines. if (string.IsNullOrEmpty(lines[i])) { continue; } // break out segments of this line. string[] segments = lines[i].Split(' '); //Model[vertexWriteIndex] = new DModelType() //{ // Read in the vertex data, First X, Y & Z positions. Model[vertexWriteIndex].x = float.Parse(segments[0]); Model[vertexWriteIndex].y = float.Parse(segments[1], NumberStyles.Float); Model[vertexWriteIndex].z = float.Parse(segments[2], NumberStyles.Float); // Read in the Tu and Yv tecture coordinate values. Model[vertexWriteIndex].tu = float.Parse(segments[3], NumberStyles.Float); Model[vertexWriteIndex].tv = float.Parse(segments[4], NumberStyles.Float); // Read in the Normals X, Y & Z values. Model[vertexWriteIndex].nx = float.Parse(segments[5], NumberStyles.Float); Model[vertexWriteIndex].ny = float.Parse(segments[6], NumberStyles.Float); Model[vertexWriteIndex].nz = float.Parse(segments[7], NumberStyles.Float, CultureInfo.InvariantCulture); vertexWriteIndex++; } } catch (Exception) { return(false); } return(true); }