private void determineCombineOpMat(ref StringBuilder map, RMPrimitive prim, CSG csg, uint index) { CombineOpsTypes combineOpType; string obj = "obj"; string combineOps = "_combineOps" + "[" + index + "].y);"; if (prim) { combineOpType = prim.CombineOpType; } else { combineOpType = csg.CombineOpType; obj = "storedCSGs[" + index + "]"; combineOps = "_combineOpsCSGs" + "[" + index + "].w);"; } switch (combineOpType) { case CombineOpsTypes.Union: map.AppendLine("\tscene = opUMat(scene, " + obj + ");"); break; case CombineOpsTypes.Subtraction: map.AppendLine("\tscene = opSMat(" + obj + ", scene);"); break; case CombineOpsTypes.Intersection: map.AppendLine("\tscene = opIMat(scene, " + obj + ");"); break; case CombineOpsTypes.SmoothUnion: map.AppendLine("\tscene = opSmoothUnionMat(scene, " + obj + ", " + combineOps); break; case CombineOpsTypes.SmoothSubtraction: map.AppendLine("\tscene = opSmoothSubMat(" + obj + ", scene, " + combineOps); break; case CombineOpsTypes.SmoothIntersection: map.AppendLine("\tscene = opSmoothIntMat(scene, " + obj + ", " + combineOps); break; case CombineOpsTypes.AbsUnion: map.AppendLine("\tscene = opUAbsMat(scene, " + obj + ");"); break; default: map.AppendLine("\tscene = opUMat(scene, " + obj + ");"); Debug.LogError("Shader Parse: Unkown Combining Operation!"); break; } }
private void renderPrimitive(RMPrimitive rmPrim, ref int primIndex, ref int altIndex) { // Homogeneous transformation matrices _invModelMats[primIndex] = rmPrim.transform.localToWorldMatrix.inverse; // Colour information _colours[primIndex] = rmPrim.Colour; // Primitive to render //primitiveTypes[primIndex] = (float)rmPrim.PrimitiveType; // Combine Operation _combineOps[primIndex] = rmPrim.CombineOp; // Primitive Geometry Information _primitiveGeoInfo[primIndex] = rmPrim.GeoInfo; // Reflection Information _reflInfo[primIndex] = rmPrim.ReflectionInfo; // Refraction Information Vector4 info = rmPrim.RefractionInfo; if (info.x > 0.0f) { info.x = 1.0f; } _refractInfo[primIndex] = info; // Alterations' Information foreach (Alteration alt in rmPrim.Alterations) { _altInfo[altIndex] = alt.info; ++altIndex; } //foreach(Vector4 altInfo in rmPrim.AlterationInfo) //{ // _altInfo[altIndex] = altInfo; // ++altIndex; //} _boundGeoInfo[primIndex] = rmPrim.BoundGeoInfo; ++primIndex; }
private void parsePrimitive(ref StringBuilder map, RMPrimitive prim, ref uint primIndex, ref uint altIndex, bool csgNodeTwo = false) { if (!prim.Static) { // Determine position and geometric information map.AppendLine("\tpos = mul(_invModelMats[" + primIndex + "], float4(p, 1.0));"); map.AppendLine("\tgeoInfo = _primitiveGeoInfo[" + primIndex + "];"); parseAlterationTypes(ref map, prim.Alterations, ref altIndex); string obj = "obj"; if (csgNodeTwo) { obj = "obj2"; } map.Append("\t" + obj + " = "); // Determine primitive type parsePrimitiveType(ref map, prim.PrimitiveType); // Store distance into distance buffer parseAlterationTypes(ref map, prim.Alterations, ref altIndex, false); map.AppendLine("\tdistBuffer[" + primIndex + "] = " + obj + ";"); map.AppendLine(); // Determine combining operation if (!prim.CSGNode) { determineCombineOp(ref map, prim, null, primIndex); } else { map.AppendLine(); } //map.AppendLine(); ++primIndex; } else { Matrix4x4 mat; Vector4 info; // Determine position and geometric information //map.AppendLine("\tpos = mul(_invModelMats[" + primIndex + "], float4(p, 1.0));"); mat = prim.transform.localToWorldMatrix.inverse; map.AppendLine("\tpos = mul(float4x4(" + mat.m00 + ", " + mat.m01 + ", " + mat.m02 + ", " + mat.m03 + ", " + mat.m10 + ", " + mat.m11 + ", " + mat.m12 + ", " + mat.m13 + ", " + mat.m20 + ", " + mat.m21 + ", " + mat.m22 + ", " + mat.m23 + ", " + mat.m30 + ", " + mat.m31 + ", " + mat.m32 + ", " + mat.m33 + "), float4(p, 1.0));"); //map.AppendLine("\tgeoInfo = _primitiveGeoInfo[" + primIndex + "];"); info = prim.GeoInfo; map.AppendLine("\tgeoInfo = float4(" + info.x + ", " + info.y + ", " + info.z + ", " + info.w + ");"); string obj = "obj"; if (csgNodeTwo) { obj = "obj2"; } map.Append("\t" + obj + " = "); // Determine primitive type parsePrimitiveType(ref map, prim.PrimitiveType); // Store distance into distance buffer map.AppendLine("\tdistBuffer[" + primIndex + "] = " + obj + ";"); map.AppendLine(); // Determine combining operation if (!prim.CSGNode) { determineCombineOp(ref map, prim, null, primIndex); } else { map.AppendLine(); } //map.AppendLine(); ++primIndex; } }
void DisplayGeoInfo(RMPrimitive rmComp, PrimitiveTypes type, Vector4 geoInfo) { switch (type) { case PrimitiveTypes.Sphere: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Box: geoInfo.x = EditorGUILayout.FloatField("Length", _geoInfo.vector4Value.x); geoInfo.z = EditorGUILayout.FloatField("Breadth", _geoInfo.vector4Value.z); geoInfo.y = EditorGUILayout.FloatField("Height", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.RoundBox: geoInfo.x = EditorGUILayout.FloatField("Length", _geoInfo.vector4Value.x); geoInfo.z = EditorGUILayout.FloatField("Breadth", _geoInfo.vector4Value.z); geoInfo.y = EditorGUILayout.FloatField("Height", _geoInfo.vector4Value.y); geoInfo.w = EditorGUILayout.FloatField("Roundness", _geoInfo.vector4Value.w); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Torus: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Thickness", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.CappedTorus: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Thickness", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("RA", _geoInfo.vector4Value.z); geoInfo.w = EditorGUILayout.FloatField("RB", _geoInfo.vector4Value.w); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Link: geoInfo.x = EditorGUILayout.FloatField("Length", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("R1", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("R2", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Cylinder: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Height", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.CappedCylinder: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Hieght", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.CappedCylinderSlower: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Hieght", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.RoundedCylinder: geoInfo.x = EditorGUILayout.FloatField("RA", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("RB", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("Hieght", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Cone: geoInfo.x = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Hieght", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.CappedCone: geoInfo.x = EditorGUILayout.FloatField("H", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("R1", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("R2", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.RoundCone: geoInfo.x = EditorGUILayout.FloatField("R1", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("R2", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("H", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Plane: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("Z", _geoInfo.vector4Value.z); geoInfo.w = EditorGUILayout.FloatField("W", _geoInfo.vector4Value.w); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.HexagonalPrism: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.TriangularPrism: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Capsule: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("Z", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.VerticalCapsule: geoInfo.x = EditorGUILayout.FloatField("Hieght", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Radius", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.SolidAngle: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("Z", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Ellipsoid: geoInfo.x = EditorGUILayout.FloatField("X", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Y", _geoInfo.vector4Value.y); geoInfo.z = EditorGUILayout.FloatField("Z", _geoInfo.vector4Value.z); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Octahedron: geoInfo.x = EditorGUILayout.FloatField("S", _geoInfo.vector4Value.x); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.OctahedronBound: geoInfo.x = EditorGUILayout.FloatField("S", _geoInfo.vector4Value.x); _geoInfo.vector4Value = geoInfo; break; case PrimitiveTypes.Triangle: break; case PrimitiveTypes.Quad: break; case PrimitiveTypes.Tetrahedron: break; case PrimitiveTypes.Mandelbulb: geoInfo.x = EditorGUILayout.FloatField("Iterations", _geoInfo.vector4Value.x); geoInfo.y = EditorGUILayout.FloatField("Power", _geoInfo.vector4Value.y); _geoInfo.vector4Value = geoInfo; break; default: break; } }