コード例 #1
0
ファイル: CSGModelBase.cs プロジェクト: vrum/SabreCSG
 public GameObject CreateCompoundBrush <T>(Vector3 localPosition, Vector3 localSize = default(Vector3), Quaternion localRotation = default(Quaternion), Material material = null, CSGMode csgMode = CSGMode.Add, string brushName = null) where T : CompoundBrush
 {
     return(CreateCompoundBrush(typeof(T), localPosition, localSize, localRotation, material, csgMode, brushName));
 }
コード例 #2
0
ファイル: CSGModelBase.cs プロジェクト: vrum/SabreCSG
        public GameObject CreateCompoundBrush(Type compoundBrushType, Vector3 localPosition, Vector3 localSize = default(Vector3), Quaternion localRotation = default(Quaternion), Material material = null, CSGMode csgMode = CSGMode.Add, string brushName = null)
        {
            // Make sure we're actually being asked to create a compound brush
            if (!typeof(CompoundBrush).IsAssignableFrom(compoundBrushType))
            {
                throw new ArgumentException("Specified type must be derived from CompoundBrush");
            }

            GameObject brushObject;

            if (!string.IsNullOrEmpty(brushName))
            {
                brushObject = new GameObject(brushName);
            }
            else
            {
                brushObject = new GameObject("");
            }

            brushObject.transform.localScale    = this.transform.lossyScale;
            brushObject.transform.parent        = this.transform;
            brushObject.transform.localPosition = localPosition;
            if (localRotation != default(Quaternion))
            {
                brushObject.transform.localRotation = localRotation;
            }
            CompoundBrush compoundBrush = (CompoundBrush)brushObject.AddComponent(compoundBrushType);

            compoundBrush.Mode = csgMode;
            compoundBrush.Invalidate(true);
            //			if(localSize != default(Vector3)
            //				&& localSize != new Vector3(2,2,2))
            //			{
            //				BrushUtility.Resize(compoundBrush, localSize);
            //			}

            if (material != null)
            {
                //				SurfaceUtility.SetAllPolygonsMaterials(compoundBrush, material);
            }

            return(brushObject);
        }
コード例 #3
0
ファイル: CSGModelBase.cs プロジェクト: vrum/SabreCSG
        /// <summary>
        /// Creates a brush under the CSG Model with the specified attributes.
        /// </summary>
        /// <returns>The created game object.</returns>
        /// <param name="brushType">Brush type.</param>
        /// <param name="localPosition">Local position of the brush's transform</param>
        /// <param name="localSize">Local bounds size of the brush (Optional, defaults to 2,2,2).</param>
        /// <param name="localRotation">Local rotation of the brush (Optional, defaults to identity quaternion).</param>
        /// <param name="material">Material to apply to all faces, (Optional, defaults to null for default material).</param>
        /// <param name="csgMode">Whether the brush is additive or subtractive (Optional, defaults to additive).</param>
        /// <param name="brushName">Name for the game object (Optional, defaults to "AppliedBrush").</param>
        public GameObject CreateBrush(PrimitiveBrushType brushType, Vector3 localPosition, Vector3 localSize = default(Vector3), Quaternion localRotation = default(Quaternion), Material material = null, CSGMode csgMode = CSGMode.Add, string brushName = null)
        {
            GameObject brushObject;

            if (!string.IsNullOrEmpty(brushName))
            {
                brushObject = new GameObject(brushName);
            }
            else
            {
                brushObject = new GameObject("");
            }

            brushObject.transform.localScale    = this.transform.lossyScale;
            brushObject.transform.parent        = this.transform;
            brushObject.transform.localPosition = localPosition;
            if (localRotation != default(Quaternion))
            {
                brushObject.transform.localRotation = localRotation;
            }
            PrimitiveBrush primitiveBrush = brushObject.AddComponent <PrimitiveBrush>();

            primitiveBrush.BrushType = brushType;
            primitiveBrush.Mode      = csgMode;
            primitiveBrush.ResetPolygons();

            if (localSize != default(Vector3) &&
                localSize != new Vector3(2, 2, 2))
            {
                BrushUtility.Resize(primitiveBrush, localSize);
            }
            else
            {
                // Resize automatically invalidates a brush with changed polygons set, if no resize took place we still need to make sure it happens
                primitiveBrush.Invalidate(true);
            }

            if (material != null)
            {
                SurfaceUtility.SetAllPolygonsMaterials(primitiveBrush, material);
            }

            return(brushObject);
        }